consus-flux
v0.3.0
Published
Flux modules for the Consus project
Downloads
4
Readme
consus-flux
Flux modules for the Consus project
Installing
npm install consus-flux --save
Using the Dispatcher
import { Dispatcher } from 'consus-flux';
Dispatcher.handleAction('INCREMENT', {
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);
Developing
Getting Started
# Clone the repository
git clone [email protected]:TheFourFifths/consus-flux.git
# Enter the project directory
cd consus-flux
# Install dependencies
npm install
# Build the project
npm run build
# Run the test suite
npm test
Development Scripts
npm test
: Run the test suitenpm run lint
: Run the linternpm run build
: Build the usable.dist
directorynpm run coverage
: Generate a code coverage report
Project File Structure
src
: The project's source codetest
: The project's testslib
: Miscellaneous library modulesunit
: Unit tests