Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wire.js has problems with backbone model #34

Closed
reduxdj opened this issue May 11, 2012 · 3 comments
Closed

Wire.js has problems with backbone model #34

reduxdj opened this issue May 11, 2012 · 3 comments

Comments

@reduxdj
Copy link

reduxdj commented May 11, 2012

I am getting errors in my code with collections, sometimes when I go to populate collections with models the second time, for instance after a reset, the models can't be instantiated correctly. This bug has been challenging to track down, I've tested other code, but this happens about one time out of 20.

TypeError: '[object Object]' is not a constructor (evaluating 'new this.model(attrs, options)')

// Prepare a model or hash of attributes to be added to this collection.
_prepareModel: function(model, options) {
options || (options = {});
if (!(model instanceof Model)) {
var attrs = model;
options.collection = this;
model = new this.model(attrs, options);
if (!model._validate(model.attributes, options)) model = false;
} else if (!model.collection) {
model.collection = this;
}
return model;
},

@briancavalier
Copy link
Member

Hey Patrick, is this the same issue as this one?

Also, have a look at the github markdown docs. There are some nice options for formatting code snippets with syntax highlighting, etc. That'll make it easier to read your code snippets. Thanks!

@briancavalier
Copy link
Member

Hmmm, I'm not sure if it's related, but @pieter-vanderwerff did run into a situation where we had to override backbone's Model.parse() function to order to filter out some extra stuff that wire was adding to an attributes object that was being injected (via wire) into a model.

The symptom was a failure in backbone's prepareModel similar to the one you described. The workaround was to:

  1. Set the model's parse option to true.
  2. Override the model's parse() method to filter attributes using hasOwnProperty().

Here's a gist of the final solution to the problem in Pieter's wire+backbone TodoMVC app. Take a look and see if that helps.

@briancavalier
Copy link
Member

Closing as discussion has moved to #51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants