Created
March 31, 2014 18:19
-
-
Save iamnoah/9898739 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
define(function(require) { | |
var compute = require("can/observe/compute/compute"); | |
/** | |
* Simple mixin that allows using CanJS Maps, Models and computes in React components. | |
* | |
* The render method becomes a compute. Any change calls forceUpdate. | |
* React will take the new virtual DOM and efficiently update the real DOM | |
* only if needed. | |
* | |
* Since no strings are being concatented and no DOM is being created, | |
* this is stupidly fast. | |
* | |
* Usage: | |
React.createClass({ | |
mixins: [ComputeMixin], | |
render: function() { | |
// normal render, using computes | |
} | |
}); | |
* | |
*/ | |
return { | |
componentWillMount: function() { | |
this.render = compute(this.render, this); | |
this.render.bind("change.force-react-update", (function() { | |
this.forceUpdate(); | |
}).bind(this)); | |
}, | |
componentWillUnmount: function() { | |
this.render.unbind("change.force-react-update"); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment