Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var dispatcher = new Flux.Dispatcher();
- var emitter = new EventEmitter();
- var DataStore = function() {
- this._data = null;
- Spamler.dispatcher.register(function(payload) {
- switch (payload.type) {
- case "loadAll":
- this._all();
- break;
- }
- }.bind(this));
- this._all = function () {
- // Load all into this._data
- emitter.emit("allDataReceived", this._data);
- }.bind(this);
- }
- var DataView = React.createClass({
- getInitialState: function() {
- return {data: null};
- },
- componentWillMount: function() {
- emitter.on("allDataReceived", this.dataReceived);
- },
- componentDidMount: function() {
- dispatcher.dispatch({ type: "loadAll" });
- },
- componentWillUnmount: function() {
- emitter.off("allDataReceived", this.dataReceived);
- },
- dataReceived: function(data){
- this.setProps({data: data});
- },
- render: function() {
- return <div>{this.state.data}</div>
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement