0.3.0 • Published 10 years ago

stik-view-bag v0.3.0

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

#$viewBag Enables a controller to push and pull data in and out of its template. While pushing, $viewBag will only care about the values within the object passed.

##Using it For the given HTML:

<div data-controller="MessageCtrl" data-action="Revelation">
  <span data-key="senderName"></span>
  <span data-key="receiverName"></span>
  <span data-key="message"></span>
  <input data-key="customNOOO"/>
</div>

And this JS:

stik.controller("MessageCtrl", "Revelation", function($viewBag){
  // the push method receives an object
  // with the values that it will use
  $viewBag.push({
    senderName: "Darth Vader",
    receiverName: "Luke Skywalker",
    message: "I'm your father!",
    customNOOO: "NOOOOOO!!!"
  });

  // use pull to get bound data out of the template
  var dataset = $viewBag.pull();
  // this will return an object with the following structure
  // {
  //   senderName: "Darth Vader",
  //   receiverName: "Luke Skywalker",
  //   message: "I'm your father!",
  //   customNOOO: "NOOOOOO!!!"
  // }
});