Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@fand
Last active February 15, 2016 08:06
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fand/cc70b35eb901bd0ccb24 to your computer and use it in GitHub Desktop.
Save fand/cc70b35eb901bd0ccb24 to your computer and use it in GitHub Desktop.
簡易Flux
/**
* 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;
@masawada
Copy link

/**
 * A simple Flux implementation with EventEmitter.
 * @author amagitakayosi <amagitakayosi@hatena.ne.jp>
 * @license MIT License
 * / # ココ

コメントミスってそうでした

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment