Skip to content

Instantly share code, notes, and snippets.

@basketofsoftkittens
Created September 29, 2011 00:22
Show Gist options
  • Save basketofsoftkittens/1249673 to your computer and use it in GitHub Desktop.
Save basketofsoftkittens/1249673 to your computer and use it in GitHub Desktop.
masterObj = {}
_.extend( masterObj, Backbone.events);
masterObj.registry = {
models:[]
register:function(name,model){
this.models[name] = model;
},
get:function(name){
if(this.models[name]) return this.models[name];
return false;
}
}
var model1=Backbone.Model.extend({
initialize:function(){
var model2 = masterObj.registry.get("model2"); // this could also be a promise if the model isnt ready at this time
if (model2){
model2.bind("change:property",function(){
// change model1 properties
});
}
});
var model2 = Backbone.Model.extend({
intitalize:function(){
}
});
var view = Backbone.View.extend({
model:model2,
events:{
"click elm" : "changeThis"
},
initialize:function(){
masterObj.registery.register( "model2", this.model);
},
changeThis:function(){
this.model.set({"property":1});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment