flux-utils
A collection of utility classes for Flux implementation
Installing
npm install --save nova-flux
Using
First it's needed to create actions:
ES5:
var flux = ; // To look more react-likevar MyActions = flux;// To look more classicvar MyActions = 'createTodo' 'removeTodo';
ES6:
; var MyActions = 'createTodo' 'removeTodo';
Actions can be called directly
// Actions can be called directly:MyActions; // Also, any number of arguments.
Then create an Store to use those actions:
ES5:
var flux = ; // You ca use flux.createStore alsovar MyStore = flux;
ES6:
; // You ca use flux.createStore alsovar MyStore = actions: MyActions methods: { let state = thisstate; // deep copies it statetodos; thisstate = state; // Saves the new state and emit changes } { } state: todos: ;
Now you can look out for events
When state is changed the event change is automatically fired:
Flux could be used without React but because is popular, here is a React component showing how it works.
Component // ... More code ... { // when you get the state is deep cloned, // so no worries and no change to modify it. this; } { // Adding the handle MyStoreevents; } { // Remove it when not needed MyStoreevents; } // ... More code ...
Events are using my custom Event Manager and they are using composition, instead of inheritance.