+
Skip to content
This repository was archived by the owner on Mar 5, 2018. It is now read-only.

TheFourFifths/consus-core

Repository files navigation

consus-flux

Flux modules for the Consus project

Installing

npm install consus-flux --save

Using the Dispatcher

import { Dispatcher } from 'consus-flux';

Dispatcher.handleAction({
    actionType: 'INCREMENT',
    data: {
        amount: 5
    }
});

Using the Store

import { Store } from 'consus-flux';

let count = 0;

class CounterStore extends Store {

    getCount() {
        return count;
    }

}

const store = new CounterStore();

store.registerHandler('INCREMENT', data => {
    count += data.amount;
    store.emitChange();
});

store.registerHandler('DECREMENT', data => {
    count -= data.amount;
    store.emitChange();
});

export default store;

Listening to a Store

import CounterStore from './counter-store';

function handleChange() {
    console.log('The count is now: ' + CounterStore.getCount());
}

CounterStore.addChangeListener(handleChange);

setTimeout(() {
    CounterStore.removeChangeListener(handleChange);
}, 10000);

About

Common modules for the Consus project

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载