Created
June 30, 2014 04:04
-
-
Save andreisebastianc/1c80258b81b520b231cb 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 () { | |
return { | |
bindTo: function(model, key){ | |
return { | |
value: model.get(key), | |
requestChange: function(value){ | |
model.set(key, value); | |
}.bind(this) | |
} | |
} | |
} | |
}); |
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 () { | |
return { | |
componentDidMount: function() { | |
// Whenever there may be a change in the Backbone data, trigger a reconcile. | |
this.getBackboneModels().forEach(this.injectModel, this); | |
}, | |
componentWillUnmount: function() { | |
// Ensure that we clean up any dangling references when the component is | |
// destroyed. | |
this.__syncedModels.forEach(function(model) { | |
model.off(null, model.__updater, this); | |
}, this); | |
}, | |
injectModel: function(model){ | |
if(!this.__syncedModels) this.__syncedModels = []; | |
if(!~this.__syncedModels.indexOf(model)){ | |
var updater = this.forceUpdate.bind(this, null); | |
model.__updater = updater; | |
model.on('add change remove', updater, this); | |
this.__syncedModels.push(model); | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment