Last active
February 15, 2016 08:06
-
-
Save fand/cc70b35eb901bd0ccb24 to your computer and use it in GitHub Desktop.
簡易Flux
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
/** | |
* A simple Flux implementation with EventEmitter. | |
* @author amagitakayosi <amagitakayosi@hatena.ne.jp> | |
* @license MIT License | |
* / | |
'use strict'; | |
const EventEmitter = require('events').EventEmitter; | |
const Dispatcher = new EventEmitter(); | |
Dispatcher.on('__DISPATCH__', (action) => { | |
Dispatcher.emit(action.type, action.payload); | |
}); | |
// Define Actions class bound with Dispatcher | |
class Actions { | |
emit (actionType, payload) { | |
Dispatcher.emit('__DISPATCH__', { | |
type : actionType, | |
payload : payload, | |
}); | |
} | |
} | |
class Store extends EventEmitter { | |
constructor () { | |
super(); | |
this.state = {}; | |
} | |
getState () { | |
return this.state; | |
} | |
} | |
Dispatcher.Actions = Actions; | |
Dispatcher.Store = Store; | |
module.exports = Dispatcher; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
コメントミスってそうでした