Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
ampersand-store
Advanced tools
A store for use with ampersand or backbone projects and flux dispatchers
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.
npm install ampersand-store
var Store = require('ampersand-store');
var Dispatcher = require('flux').Dispatcher;
var Model = require('ampersand-model');
var MyStore = Store.extend({
// actions object works similar to backbone events and routes
// value can be a function or a string reference to a function
// on the store
actions: {
'action:one': 'doFirstAction',
'action:two': function (payload) {
this.model.set('value', payload.value);
console.log('second action invoked on dispatcher', payload.value);
}
},
doFirstAction: function (payload) {
this.model.set('anotherValue', payload.value);
console.log('first action invoked on dispatcher:', payload.value);
}
});
var globalDispatcher = new flux.Dispatcher();
var model = new Model();
var storeInstance = new MyStore({
dispatcher: globalDispatcher,
model: model
});
globalDispatcher.dispatch({
actionType: 'event1',
value: 'foo'
});
// prints "first action invoked on dispatcher: foo" to the console.
Store.extend(properties...)
To create a Store class of your own, you extend ampersand-store and provide instance properties.
var ToDoStore = Store.extend({
initialize: function () { ... },
actions: { ... }
});
new Store(options)
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.
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.extend({
actions: {
'action:one': 'doFirstAction',
'action:two': function (payload) {
console.log('second action invoked on dispatcher', payload.value);
}
},
doFirstAction: function (payload) { ... }
});
Run npm test
to run tests in mocha with chai.
FAQs
A store for use with ampersand or backbone projects and flux dispatchers
The npm package ampersand-store receives a total of 2 weekly downloads. As such, ampersand-store popularity was classified as not popular.
We found that ampersand-store demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.