Created
February 27, 2015 12:07
-
-
Save codrin-iftimie/2e79c87030c8ec5e615d 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
//manager.js | |
var _ = require("lodash"); | |
function StatusManager(){ | |
this.componentsStatus = {}; | |
} | |
_.extend(StatusManager.prototype, { | |
getStatus: function(identifier) { | |
return this.componentsStatus[identifier]; | |
}, | |
setStatus: function(identifier, newStatus) { | |
var currentStatus = this.componentsStatus[identifier] || {}; | |
return _.extend(currentStatus, newStatus); | |
} | |
}); | |
module.exports = new StatusManager(); | |
//component.jsx | |
var React = require("react"), | |
stateManager = require("./manager"); | |
module.exports = React.createClass({ | |
getInitialState: function(){ | |
return this.props.state; | |
}, | |
render: function(){ | |
return( | |
<div> | |
<button onClick={this.handleClick}> | |
Click me! | |
</button> | |
</div> | |
); | |
}, | |
handleClick: function(){ | |
stateManager.setStatus(this.props.identifier, {clicked: true}); | |
} | |
}); | |
//view.jsx | |
var React = require("react"), | |
stateManager = require("./manager"); | |
module.exports = React.createClass({ | |
render: function(){ | |
return( | |
<div> | |
<Component identifier="comp1" state={stateManager.getStatus("comp1")}/> | |
<Component identifier="comp2" state={stateManager.getStatus("comp2")}/> | |
</div> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment