ampersand-store
Use the flux application architecture in your Backbone or Amperand apps. This store will encapsulate your models and collections and register actions on the dispatcher.
Installing
npm install ampersand-store
Example
var Store = ;var Dispatcher = Dispatcher;var Model = ; var MyStore = Store; var globalDispatcher = ;var model = ;var storeInstance = dispatcher: globalDispatcher model: model; globalDispatcher; // prints "first action invoked on dispatcher: foo" to the console.
API Reference
Store.extend(properties...)
extend To create a Store class of your own, you extend ampersand-store and provide instance properties.
var ToDoStore = Store;
new Store(options)
constructor / initialize Requires a flux dispatcher passed in as options.dispatcher. Callbacks from the actions
hash will be registered in the constructor. dispatcher
, model
, and collection
will be attached directly to the store, along with the dispatchToken
from registering the callbacks. If the store defines an initialize function, it will be called when the store is first created.
actions
Provides declarative callbacks for actions dispatched on the dispatcher. Actions are written in the format {"actionType": "callback"}
. The callback may be either the name of a method on the store, or a direct function body. Actions are registerd on the dispatcher within the Store's constructor.
The actions property may also be defined as a function that returns an actions hash, to make it easier to programmatically define your actions, as well as inherit them from parent stores.
var MyStore = Store;
Tests
Run npm test
to run tests in mocha with chai.