Last active
October 22, 2015 21:06
-
-
Save tyzoid/3468773786276b212a01 to your computer and use it in GitHub Desktop.
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
var React = require('react'); | |
var Connector = require('./refluxConnector.js'); | |
var DataStore = require('./dataStore.js'); | |
var App = React.createClass( | |
Connector({ | |
render: function(){ | |
return ( | |
<div> | |
<h1>Welcome {this.state.user.firstName}!</h1> | |
</div> | |
); | |
}, | |
}, {user: DataStore}) | |
); |
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
var Reflux = require('reflux'); | |
module.exports = function(Component, stores){ | |
var reactComponent = Reflux.utils.extend(Component, Reflux.ListenerMixin); | |
var initialState = {}; | |
for (var key in stores) { | |
if (stores.hasOwnProperty(key)) { | |
if (Reflux.utils.isFunction(stores[key].output)) | |
{ | |
initialState[key] = stores[key].output(); | |
} | |
reactComponent.listenTo(stores[key], function(storeState){ | |
var newState = {}; | |
newState[key] = storeState; | |
reactComponent.setState(newState); | |
}); | |
reactComponent.getInitialState = function(){ | |
return initialState; | |
} | |
} | |
} | |
return reactComponent; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment