Code Monkey home page Code Monkey logo

backbone-nested-models's People

Contributors

bitdeli-chef avatar blittle avatar cjmalloy avatar colllin avatar johtso avatar mittsh avatar phudinsky avatar rharriso avatar royling avatar tobiaszcudnik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

backbone-nested-models's Issues

events not firing on nested children

I have an options model in which one of the options is a center. I've set this up to be a center model in the relations.

When I change the center using set, nothing is fired from the events. If I change another attribute in the options model, events are fired normally.

Am I missing something here?

Options not passed along when performing CRUD actions

It's currently not possible to silently reset a model with nested data, as any nested things created will be created noisily, as the options object with silent=true are not passed along.

I ended up doing this:

                             model.set(rModel.toJSON ? rModel.toJSON() : rModel);

                             // Remove the model from the incoming list because all remaining models
                             // will be added to the relation
                             modelsToAdd.splice(i,1);
                         } else {
                             modelsToRemove.push(model);
                         }

                     });

                     _.each(modelsToRemove, function(model) {
-                        relation.remove(model);
+                        relation.remove(model, options);
                     });

-                    relation.add(modelsToAdd);
+                    relation.add(modelsToAdd, options);

                 } else {

                     // The incoming val that is being set is not an array or collection, then it represents
                     // a single model.  Go through each of the models in the existing relation and remove
                     // all models that aren't the same as this one (by id). If it is the same, call set on that
                     // model.

                     relation.each(function(model) {
                         if(val[id] === model[id]) {
-                            model.set(val);
+                            model.set(val, options);
                         } else {
-                            relation.remove(model);
+                            relation.remove(model, options);
                         }
                     });
                 }

                 return relation;
             }

             if(relation && relation instanceof Model) {
-                relation.set(val);
+                relation.set(val, options);
                 return relation;
             }

             options._parent = this;

             val = new this.relations[attr](val, options);
             val.parent = this;
         }

         return val;
     };

Does that seem viable?

get of relation doesn't work in initialize function

var someModel = Backbone.Model.extend({
__defaults: {
____attr1: "comment",
____attr2: false
__},
__relations: {
____someRelation: Backbone.Collection
__},
__initialize: function() {
____this.get("attr1") // work well
____this.get("someRelation") // returm undefined
__}
});

Reference to parent should be available at initialisation

Currently parent is added to the newly created collection/model as a property, but this means that there is no way to know what the parent is within the initialize method.

Maybe just adding parent to the options is a reasonable solution?

Can't install via NPM + UMD wrapper is broken

backbone-nested on NPM is not this library, despite the package.json saying so.

I managed to pull down this module using Napa, but it appears the UMD wrapper is broken.

I am using webpack (common.js). :)

A model relation with default value is set wrongly

see the below example:

var Author = Backbone.Model.extend({
  defaults: {
    name: 'test',
    age: 20
  }
});
var Book = Backbone.Model.extend({
  relations: {
    author: Author
  },
  defaults: {
    author: new Author()
  }
});

var book = new Book({name: 'go!'});

book.toJSON().author is a Backbone.Model like instance (because instanceof Backbone.Model returns false), instead of the JSON of the defaults of Author.
it seems that book.attributes.author = new Author(new Author)

Same name?

Does you library have any relation (no pun intended) with Bakbone-Nested (http://afeld.github.com/backbone-nested/) ? I just came across your project when searching for the other (older) one and was confused, not recognizing what I was looking at :)

Multiple level nesting

I have this objects definition:

var Item = Backbone.Model.extend({
    relations: {
      "Outlooks": OutlookCollection
    }
});

var OutlookCollection = Backbone.Collection.extend({
    model: Outlook
});

var Outlook = Backbone.Model.extend(
    relations: {
     "Scenarios": Backbone.Collection
    }
); 

when I fetch an Item the attribute Outlook is an OutlookCollection but in every Outlook the attribute Scenarios is an array not a Backbone.Collection.

Should work it or I'm missing something?

Issues with events for nested Models/Collections

I'm struggling to get my head around how backbone-nested is dealing with firing events on nested Backbone structures.

As far as I can tell, no reset events are fired for nested collections, when the parent collection is reset.

Am I right in thinking that this is currently a shortcoming in the library? Would be great to have this functionality, currently I'm having to do strange things like listening to events on the top level collection, and I don't think I'm going to be able to get much further with that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.