stik-view-bag

0.3.0 • Public • Published

$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!!!"
  // }
});

Readme

Keywords

Package Sidebar

Install

npm i stik-view-bag

Weekly Downloads

0

Version

0.3.0

License

MIT

Last publish

Collaborators

  • lukelex