GithubHelp home page GithubHelp logo

revelytix / backbone-nestify Goto Github PK

View Code? Open in Web Editor NEW
23.0 23.0 2.0 336 KB

Nest Backbone.js Models and Collections.

Home Page: http://revelytix.github.io/backbone-nestify/

License: MIT License

JavaScript 99.13% HTML 0.87%

backbone-nestify's People

Contributors

scottbale 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

Watchers

 avatar  avatar

backbone-nestify's Issues

support deep Model.hasChanged()

Backbone.Model hasChanged() will currently return false even if a nested Model has changed.

This is tricky, because a naive solution would require a full recursive tree traversal.

Provide a changelog

Please provide a log of what changed. The library is great for our workflow and we intend to use it in production, so a short overview of what's changed between versions would be perfect! Thanks a lot!

nestify.auto() infinite loop

Nestify 0.4.0 release. Chrome browser only gives me a truncated stack trace. I see this part repeated:

anonymous function) underscore.js:115
j.each.j.forEach underscore.js:86
j.reduce.j.foldl.j.inject underscore.js:113
_core.prepAttributes backbone-nestify.js?v=1400782399273:196
set backbone-nestify.js?v=1400782399273:793
_container.model.merge backbone-nestify.js?v=1400782399273:402
(anonymous function) backbone-nestify.js?v=1400782399273:598
(anonymous function) backbone-nestify.js?v=1400782399273:200
(anonymous function) underscore.js:115

The very top of the stack trace looks like this:

<error> backbone-nestify.js?v=1400782399273:266
_matchers.isArray backbone-nestify.js?v=1400782399273:266
(anonymous function) backbone-nestify.js?v=1400782399273:319
(anonymous function) backbone-nestify.js?v=1400782399273:294
j.reduce.j.foldl.j.inject underscore.js:112
(anonymous function) backbone-nestify.js?v=1400782399273:293
(anonymous function) backbone-nestify.js?v=1400782399273:365
(anonymous function) underscore.js:157
j.some.j.any underscore.js:207
j.find.j.detect underscore.js:155
_container.findContainerFn backbone-nestify.js?v=1400782399273:364
(anonymous function) backbone-nestify.js?v=1400782399273:199
(anonymous function) underscore.js:115

Declared nested collection doesn't play nice when json value is null instead of empty array

If you set up a model, with a declared nested collection like this
nestify({
"nestedArray":{constructor:SomeDefinedCollection}
})

and the json returned contains
'nestedArray' : null

nestify will throw an error.
WARNING! expected array but found: null
Uncaught TypeError: Cannot read property 'length' of null underscore.js:235

so the warning is there for cases like this, but I suggest nestify add the capability to translate null values for expected arrays as [] instead.

Backbone clone of nestified model?

Issues with cloning a nestified model...

var m = new Backbone.Model({name:"Rosco"});
undefined
var m_ = nestify.instance(new Backbone.Model({name:"Rosco"}));
undefined
var m2 = _.clone(m);
undefined
m2.get("name");
"Rosco"
var m2_ = _.clone(m_);
undefined
m2_.get("name");
undefined    // <<-----BUG
var m3 = m.clone();
undefined
m3.get("name");
"Rosco"
var m3_ = m_.clone(); // note m3_ is not a nestified instance - expected?
undefined
m3_.get("name"); 
"Rosco"

nested Collection merge update corrupts state of Collection

Nestify's merge update functionality for nested Collections (which is the default) modifies a Collection's .models array directly, but neglects to update the internal ._byId Object. This breaks get and remove, possibly other things.

A workaround is to update a Collection using a different nestify update option, such as{update: "smart"}.

anonymous use of nestify.auto() causes extra model properties to be created

when using nestify.auto() to create a collection, and populating it with models with JSON like this

"531f2d1d-5fa9-49eb-bfcb-8d269ae283d9":{

"job.progress/duration":79274,
"job/status":"completed",
"jobName":"stadiumWeaver",
"process/jobIdentifier":"531f2d1d-4b73-4494-a7ad-3ca52b625b89",
"entity/name":"stadiumWeaver",
"entity/id":"531f2d1d-5fa9-49eb-bfcb-8d269ae283d9",
"entity/type":[
    "process/ProcessUse"
],
"entity/modifiedBy":"531f29c9-04be-4e17-81c2-190c64a11b7e"

},

In addition to having all the right attributes, the created model has 8 new unexpected, numbered properties (from firebug js console)
0 Object { _matcherFn=function(), _containerFn=function()}
1 Object { _containerFn=function(), _matcherFn=function()}
2 Object { _containerFn=function(), _matcherFn=function()}
3 Object { _matcherFn=function(), _containerFn=function()}
4 Object { _matcherFn=function(), _containerFn=function()}
5 Object { _matcherFn=function(), _containerFn=function()}
6 Object { _matcherFn=function(), _containerFn=function()}
7 Object { _matcherFn=function(), _containerFn=function()}

Nested update 'hasChanged' bug

The following hasChanged test case should pass but doesn't. Doesn't work for any of the update options reset, merge or smart.

        it('should support nested Collections', function(){
            var c1 = new Backbone.Model({baz1:"Baz1"}),
                c2 = new Backbone.Model({baz:"Baz"}),
                cs = new Backbone.Collection([c1, c2]),
                b = new Backbone.Model({bars: cs}),
                a = new Backbone.Model({foo: b});
            a = nestify.instance(a);
            reset(a, b, c1, c2);
            a.set("foo|bars|1|baz", "BAAGHS!", {update: "smart"});

            expect(a.hasChanged("foo|bars")).to.be.false;
            expect(a.hasChanged("foo|bars|1|baz")).to.be.true;
            expect(a.hasChanged("foo|bars", {nested:true})).to.be.true;
            expect(a.hasChanged("foo|bars|1|baz", {nested:true})).to.be.true;
        });

publish to npm

It would be nice if we could install backbone-nestify via npm.

auto-parsing index Numbers out of delimited Strings broken in many cases

The intention of the getter syntax delimited string convenience is that backbone-nestify will interpret simple integers within a delimited string such as this

"foo|bar|2|baz"

as indices into nested Backbone Collections. It should leave all other path components alone, as Strings. However, currently it is over eager and (incorrectly) parsing some expressions into Numbers. For example:

hex:

"AF23"

arithmetic expressions:

"2-3"

UUIDs (see #2):

"531f2d1d-5fa9-49eb-bfcb-8d269ae283d9"

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.