0.3.0 • Published 9 years ago
consus-flux v0.3.0
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 git@github.com: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 testDevelopment Scripts
- npm test: Run the test suite
- npm run lint: Run the linter
- npm run build: Build the usable- .distdirectory
- npm run coverage: Generate a code coverage report
Project File Structure
- src: The project's source code
- test: The project's tests- lib: Miscellaneous library modules
- unit: Unit tests