Skip to content

NorbertSzydlik/kefaise-flux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"}
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published