briancavalier/wire — Issue #8: Wire factory passing of an object seems to change the object
Author: fricke
Created: 2011-12-16 21:16:53+00:00
State: open

Hello, I'm also trying to use AMD/DI in our production system and ran into an issue wiring two specs together and the passing of the object. Details of the project are we are using backbone, underscore, jquery, and now wire. I have an application spec which wires itself to another spec much like what happens in PirateScript for the ResultsView.

the child spec looks like this:

define({
plugins: [
{ module: 'wire/jquery'}
],
detailContainer: { $ref: '$!#var_detail' },
detailViewModel : {
create : "viewmodels/detail"
},
detailView: {
create: {
module: 'views/detail',
args: {
el: {$ref: 'detailContainer' },
viewModel: {$ref: 'detailViewModel'}
}
},
init: {
render: { $ref: 'data' }
}
}
});

And the is the parent spec that wires it (snippet):

cardsView : {
create : {
module: "views/cards",
args: {
el : {$ref: "$!#var_results"},
model : {$ref: "cardsCollection"}
}
},
properties : {
filterPanelModel : {$ref: "filterPanelModel"},
pageView : {$ref: "pageView"},
controller : {$ref: "controller"},
apiDog : {$ref: "apiDog"},
showCard: { wire: { spec: 'specs/detailspec', defer: true } }
}
},

So, the method in the cardsView object creates a backbone model, and is passed like this:

this.showCard({
data: model
});

Which works, and passes it fine... However, beforehand it is a backbone object but then the detail method render that receives it gets a different object, one without the __proto__ attribute, chain. Backbone puts the methods you define in your Model.extend({ methods}) in that proto chain, so I'm basically losing those methods. I'm basically needing to find out how to pass this object and keep it exactly the same as it was passed from the client. I'm also wondering why it's being changed. Any help you can provide would be great! Thanks as well for this project, so much potential to change how people write their JS apps (coming from a Java, DI world, and really wanting DI in JS).

Thanks,

Chris