Created
May 13, 2014 23:46
-
-
Save caseywebdev/01736ad5e768e04b09b4 to your computer and use it in GitHub Desktop.
React + Backbone Example
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
import React from 'react'; | |
import User from 'user'; | |
import UserComponent from 'user-component'; | |
var user = new User.Model({id: 1}); | |
React.renderComponent(User({user: user}), document.body); |
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
export default { | |
componentWillMount: function () { | |
(this.listeners = this.getListeners()).forEach(function (listener) { | |
listener.model.on(listener.events, this); | |
}, this); | |
}, | |
componentWillUnmount: function () { | |
this.listeners.forEach(function (listener) { | |
listener.model.off(listener.events, this); | |
}, this); | |
} | |
}; |
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
import React from 'react'; | |
import ListenersMixin from 'listeners-mixin'; | |
export default React.createClass({ | |
mixins: [ListenersMixin], | |
getListeners: function () { | |
return [{ | |
model: this.props.user, | |
events: {change: this.forceUpdate.bind(this, null)} | |
}]; | |
}, | |
componentWillMount: function () { | |
this.props.user.fetch(); | |
}, | |
render: function () { | |
var user = this.props.user; | |
return ( | |
<div className='user'> | |
<h1>{user.get('name')}</h1> | |
<h2>{user.get('title')}</h1> | |
</div> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment