JSFiddle - React, Tailwind, and code Playground
by Adam Boduch
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/flux/2.1.1/Flux.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/EventEmitter/4.3.0/EventEmitter.js"></script>
JavaScript
const dispatcher = new Flux.Dispatcher();
var _store = {
ready: false
};
class MyStore extends EventEmitter {
constructor() {
super();
this.dispatchToken = dispatcher.register((payload) => {
switch (payload.action) {
case 'INIT':
_store.ready = true;
break;
}
this.emit('change', _store);
});
}
}
const store = new MyStore();
store.on('change', (store) => {
console.log('store change', store);
})
dispatcher.dispatch({
action: 'INIT'
});