Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
A Flux dispatcher for applications that run on the server and the client.
A Flux dispatcher for applications that run on the server and the client.
For a more detailed example, see our example applications.
var ExampleStore = require('./stores/ExampleStore.js');
var dispatcher = require('dispatchr').createDispatcher({
stores: [ExampleStore]
});
var contextOptions = {};
var dispatcherContext = dispatcher.createContext(contextOptions);
dispatcherContext.dispatch('NAVIGATE', {});
// Action has been handled fully
Dispatchr's main goal is to facilitate server-side rendering of Flux applications while also working on the client-side to encourage code reuse. In order to isolate stores between requests on the server-side, we have opted to instantiate the dispatcher and stores classes per request.
In addition, action registration is done by stores as a unit rather than individual callbacks. This allows us to lazily instantiate stores as the events that they handle are dispatched. Since instantiation of stores is handled by the dispatcher, we can keep track of the stores that were used during a request and dehydrate their state to the client when the server has completed its execution.
Lastly, we are able to enforce the Flux flow by restricting access to the
dispatcher from stores. Instead of stores directly requiring a singleton
dispatcher, we pass a dispatcher interface to the constructor of the stores to
provide access to only the functions that should be available to it: waitFor
and getStore
. This prevents the stores from dispatching an entirely new
action, which should only be done by action creators to enforce the
unidirectional flow that is Flux.
These utilities make creating stores less verbose and provide some change
related functions that are common amongst all store implementations. These
store helpers also implement a basic shouldDehydrate
function that returns
true if emitChange
has been called by the store and false otherwise.
require('dispatchr/addons/BaseStore')
provides a base store class for
extending. Provides getContext
, emitChange
, addChangeListener
, and
removeChangeListener
functions. Example:
var inherits = require('inherits');
var BaseStore = require('dispatchr/addons/BaseStore');
var MyStore = function (dispatcherInterface) {
BaseStore.apply(this, arguments);
};
inherits(MyStore, BaseStore);
MyStore.storeName = 'MyStore';
MyStore.handlers = {
'NAVIGATE': function (payload) { ... this.emitChange() ... }
};
MyStore.prototype.getFoo = function () { var context = this.getContext(), ... }
module.exports = MyStore;
require('dispatchr/addons/createStore')
provides a helper function for
creating stores similar to React's createClass
function. The created store
class will extend BaseStore and have the same built-in functions. Example:
var createStore = require('dispatchr/addons/createStore');
var MyStore = createStore({
initialize: function () {}, // Called immediately after instantiation
storeName: 'MyStore',
handlers: {
'NAVIGATE': function (payload) { ... this.emitChange() ... }
}
foo: function () { ... }
});
module.exports = MyStore;
This software is free to use under the Yahoo! Inc. BSD license. See the LICENSE file for license text and copyright information.
FAQs
A Flux dispatcher for applications that run on the server and the client.
We found that dispatchr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.