Last active
August 29, 2015 14:25
-
-
Save kyldvs/9de4c5d020b46a2d45e7 to your computer and use it in GitHub Desktop.
Store with map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseStore { | |
constructor(dispatcher) { | |
this._dispatcher = dispatcher; | |
this._actionMap = this.getActionHandlers(); | |
this._dispatchToken = this._dispatcher.register(payload => { | |
this._actionMap[payload.type](payload); | |
}); | |
} | |
} | |
class Store extends BaseStore { | |
getActionHandlers() { | |
return { | |
foo(payload) { | |
console.log('foo', payload.bar); | |
}, | |
bar(payload) { | |
console.log('bar'); | |
}, | |
}; | |
} | |
} | |
var MyDispatcher = new Dispatcher(); | |
var MyStore = new FooStore(MyDispatcher); | |
MyDispatcher.dispatch({type: 'foo', bar: 100}); | |
MyDispatcher.dispatch({type: 'bar'}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment