revelytix / backbone-nestify Goto Github PK
View Code? Open in Web Editor NEWNest Backbone.js Models and Collections.
Home Page: http://revelytix.github.io/backbone-nestify/
License: MIT License
Nest Backbone.js Models and Collections.
Home Page: http://revelytix.github.io/backbone-nestify/
License: MIT License
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.
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 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
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.
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"
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"}
.
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()}
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;
});
It would be nice if we could install backbone-nestify via npm.
Currently change events are not fired on the parent collection. Example:
libraryCollection.at(0).get('someNestedCollection|1').set('name', 'testName');
The change event is not fired on libraryCollection.
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"
...which obviously need not be true
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.