React Flux Dash
Learning flux is hard, using it is cumbersome. Hopefully it will become easier with this library!
These are the biggest library features:
- No more Dispatcher: the logic is handled on the background
- Avoid 50% of errors: The library is very smart detecting potential omitions or errors, it even detectes if you change a store without emmiting!
- Full MVC approach.
Instalation
- Run on your terminal the following command:
$ npm install react-flux-dash --save
- To import the library anywhere you would like to use it:
; // or you can also do var Flux = ;
Let's build a Flux Workflow for autentication
1) Dispatching actions
You actions object needs to inhering from Flex.Action, then you will be able to dispatch to any store and setter
;Action { this; // you will have to create a _setAutentication inside StoreActions }
2) The Store
On your store you will be going the following
;Store { super; thisstate = autenticated: false } //you are forced to use _ to avoid using the setters anywhere else { //set the the new store state and emit this; //you can specify an event name if you want this; } { return thisstateautenticated; }
3) Handling store changes
There are 2 main way to listen to store changes:
- New lifecycle component function handleStoreChanges for store changes
; ; View { super; // bind your store on the view this; } // if you dont define this function you get an error // this function gets automatically called when SessionStore state changes { // retreive any store data var isAutenticated = SessionStore; }
- Or set event name and handler
; View { // start listening to changes on SessionStore for especific event this; // start listening to changes on SessionStore this; }
Contributors
- Alejandro Sanchez github.com/alesanchezr alesanchezr.com
- Angel Lacret github.com/alacret