0.0.3-alpha.7 • Published 9 years ago
kefaise-flux v0.0.3-alpha.7
Lightweight yet flexible implementation of flux pattern
Usage
Store as a handler function
var flux = require("kefaise-flux");
var eventName = "event"; //this can be Symbol in future
function simpleStore(type, data, emitChanges) {
if(type === eventName) {
this.data = data;
emitChanges();
}
}
flux.getDispatcher().registerStore("simpleStore", simpleStore);
flux.getDispatcher().subscribeToStore("simpleStore", handler);
flux.getDispatcher().dispatch(eventName, {data: "testData"});
function simpleStoreListener(store) {
console.log(store.data); //should print {data: "testData"}
}
Store as an object
var flux = require("kefaise-flux");
var eventName = "event"; //this can be Symbol in future
function SimpleStore() {
this.data = {};
}
SimpleStore.prototype.dispatch(type, data, emitChanges) {
if(type === eventType) {
this.data = data;
emitChanges();
}
}
SimpleStore.prototype.getData() {
return this.data;
}
flux.getDispatcher().registerStore("simpleStore", new SimpleStore());
flux.getDispatcher().subscribeToStore("simpleStore", handler);
flux.getDispatcher().dispatch(eventName, {data: "testData"});
function simpleStoreListener(store) {
console.log(store.getData()); ///should print {data: "testData"}
}
0.0.3-alpha.7
9 years ago
0.0.3-alpha.6
9 years ago
0.0.3-alpha.5
9 years ago
0.0.3-alpha.4
9 years ago
0.0.3-alpha.3
9 years ago
0.0.3-alpha.2
9 years ago
0.0.3-alpha.1
9 years ago
0.0.2
9 years ago
0.0.1
9 years ago