Created
January 15, 2014 09:45
-
-
Save nikcorg/8433524 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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
really nice :)