Skip to content

Instantly share code, notes, and snippets.

@isabek
Forked from nikcorg/React.LayoutManager.js
Last active August 29, 2015 14:08
Show Gist options
  • Save isabek/eadfb9caa9928e37e355 to your computer and use it in GitHub Desktop.
Save isabek/eadfb9caa9928e37e355 to your computer and use it in GitHub Desktop.
React.createBackboneComponent = function (spec, compname) {
return React.createClass(_.extend({
// Assistants
serializeState: function () {
this.replaceState(this.serialize());
},
getModel: function () {
return this.props.model;
},
el: function () {
return this._rootNode || this.getDOMNode();
},
// React internals
getInitialState: function () {
this.initialize(this.props);
return this.serialize();
},
componentDidMount: function () {
console.log("component did mount", compname);
if (this.getModel() && this.replaceStateOn) {
this.listenTo(this.getModel(), this.replaceStateOn, this.serializeState);
}
},
componentWillUpdate: function () {
if (_.isFunction(this.beforeRender)) {
this.beforeRender();
}
},
componentDidUpdate: function () {
if (_.isFunction(this.afterRender)) {
this.afterRender();
}
},
// Probably not a good idea
replaceStateOn: "change",
// Mocking a familiar interface
initialize: function (options) {
},
serialize: function () {
return this.getModel() && this.getModel().toJSON() || {};
}
}, Backbone.Events, spec));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment