Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Documentation updated for v0.4.0

  • Loading branch information...
commit c18c97f17cb7f5a8cdca5d6a06bf616a9d4aba18 1 parent 3f26535
dhruvaray authored
View
32 README.md
@@ -15,6 +15,7 @@ It was originally born out of a need to provide a simpler and speedier implement
* [Tutorial : Defining a graph of `AssociatedModel` relationships](#tutorial-associationsdef)
* [Eventing with Associations](#eventing)
* [Tutorial : Eventing with a graph of `AssociatedModel` objects](#tutorial-eventing)
+* [Perform set and retrieve operations with fully qualified paths](#paths)
* [Pitfalls](#pitfalls)
* [Performance Comparison](#performance)
* [Change Log](#changelog)
@@ -22,8 +23,8 @@ It was originally born out of a need to provide a simpler and speedier implement
## <a name="download"/>Download
-* [Production version - 0.3.1](http://dhruvaray.github.com/backbone-associations/backbone-associations-min.js) (1.7KB packed and gzipped)
-* [Development version - 0.3.1](http://dhruvaray.github.com/backbone-associations/backbone-associations.js)
+* [Production version - 0.4.0](http://dhruvaray.github.com/backbone-associations/backbone-associations-min.js) (1.86KB packed and gzipped)
+* [Development version - 0.4.0](http://dhruvaray.github.com/backbone-associations/backbone-associations.js)
## <a name="installation"/>Installation
@@ -114,8 +115,8 @@ A string (which can be resolved to an object type on the global scope), or a ref
## <a name="tutorial-associationsdef"/> Tutorial : Defining a graph of `AssociatedModel` relationships
This tutorial demonstrates how to convert the following relationship graph into an `AssociatedModels` representation
-![cd-example](http://dhruvaray.github.com/backbone-associations/docs/img/cd-example.png)
-> The source code for this image is [here](http://dhruvaray.github.com/backbone-associations/docs/cd-example.tex).
+![cd_example](http://dhruvaray.github.com/backbone-associations/docs/img/cd_example.png)
+This image was generated via [code](https://github.com/dhruvaray/backbone-associations/blob/master/docs/cd_example.tex).
````javascript
var Location = Backbone.AssociatedModel.extend({
@@ -490,11 +491,21 @@ This tutorial demonstrates the usage of eventing and change-related methods with
//Fired emp > add:dependents...
//Fired emp > remove:dependents...
//Fired emp > reset:dependents...
-
````
-The preceding examples corresponds to this [test case](http://dhruvaray.github.com/backbone-associations/test/test-suite.html?module=Examples&testNumber=32).
+The preceding examples corresponds to this [test case](http://dhruvaray.github.com/backbone-associations/test/test-suite.html?module=Examples).
Other examples can be found in the [test suite](http://dhruvaray.github.com/backbone-associations/test/test-suite.html).
+## <a name="paths"/>Retrieve and set data with fully qualified paths
+For convenience, it is also possible to retrieve or set data by specifying a path to the destination (of the retrieve or set operation).
+
+
+````javascript
+ emp.get('works_for.controls[0].locations[0].zip') //94404
+ //Equivalent to emp.get('works_for').get('controls').at(0).get('locations').at(0).get('zip');
+ emp.set('works_for.locations[0].zip', 94403);
+ //Equivalent to emp.get('works_for').get('locations').at(0).set('zip',94403);
+````
+
## <a name="performance"/>Pitfalls
When assigning a previously created object graph to a property in an associated model, care must be taken to query the appropriate object for the changed properties.
@@ -515,8 +526,8 @@ then inside a previously defined `change` event handler
````javascript
emp.on('change:works_for', function () {
- //emp.get('works_for').hasChanged() === false; as we are querying a previously created `dept1` instance
- //emp.hasChanged('works_for') === true; as we query the emp instance whose 'works_for' property has changed
+ //emp.get('works_for').hasChanged() === false; as we query a previously created `dept1` instance
+ //emp.hasChanged('works_for') === true; as we query emp whose 'works_for' attribute has changed
});
````
@@ -529,7 +540,7 @@ emp.on('change:works_for', function () {
![Performance](http://dhruvaray.github.com/backbone-associations/docs/img/speed.png)
-Each operation comprises of n (10, 15, 20, 25, 30) inserts. The chart above compares the performance (time and operations/sec) of the two implementations. (backbone-associations v0.3.1 v/s backbone-relational v0.7.0)
+Each operation comprises of n (10, 15, 20, 25, 30) inserts. The chart above compares the performance (time and operations/sec) of the two implementations. (backbone-associations v0.4.0 v/s backbone-relational v0.7.0)
Run tests on your machine configuration instantly [here](http://dhruvaray.github.com/backbone-associations/test/speed-comparison.html)
@@ -537,6 +548,9 @@ Write your own test case [here](http://jsperf.com/backbone-associations-speed-su
## <a name="changelog"/>Change Log
+#### Version 0.4.0 - [Diff](https://github.com/dhruvaray/backbone-associations/compare/v0.4.0...v0.3.1)
+*Ability to perform set and retrieve operations with fully qualified paths
+
#### Version 0.3.1 - [Diff](https://github.com/dhruvaray/backbone-associations/compare/v0.3.0...v0.3.1)
* Bug fix for event paths involving collections at multiple levels in the object graph
* Updated README with class diagram and example for paths involving collections
View
19 backbone-associations-min.js
@@ -1,9 +1,10 @@
-(function(){var f,h,q,l,m,r,n;"undefined"!==typeof require?(f=require("underscore"),h=require("backbone"),exports=module.exports=h):(f=window._,h=window.Backbone);q=h.Model;l=h.Collection;m=q.prototype;r="change add remove reset destroy sync error sort request".split(" ");h.Many="Many";h.One="One";n=h.AssociatedModel=q.extend({relations:void 0,_proxyCalls:void 0,get:function(b){return this.getAttr.apply(this,arguments)},set:function(b,a,c){var d,e,g;if(f.isObject(b)||b==null){d=b;c=a}else{d={};d[b]=
-a}c||(c={});if(!d)return this;if(c.unset)for(g in d)d[g]=void 0;this.relations&&f.each(this.relations,function(a){var b=a.key,g=a.relatedModel,k=a.collectionType,i,p;if(d[b]){i=f.result(d,b);g&&f.isString(g)&&(g=eval(g));k&&f.isString(k)&&(k=eval(k));p=a.options?f.extend({},a.options,c):c;if(a.type===h.Many){if(k&&!k.prototype instanceof l)throw Error("collectionType must inherit from Backbone.Collection");if(i instanceof l)m.set.call(this,b,i,p);else if(this.attributes[b])this.attributes[b].reset(i,
-p);else{a=k?new k:this._createCollection(g);a.add(i,p);m.set.call(this,b,a,p)}}else if(a.type===h.One&&g){a=i instanceof n?i:new g(i);m.set.call(this,b,a,p)}if((i=this.attributes[b])&&!i._proxyCallback){i._proxyCallback=function(){return this._bubbleEvent.call(this,b,arguments)};i.on("all",i._proxyCallback,this)}!e&&(e=[]);f.indexOf(e,b)===-1&&e.push(b)}},this);if(e){b={};for(g in d)f.indexOf(e,g)===-1&&(b[g]=d[g])}else b=d;return m.set.call(this,b,c)},_bubbleEvent:function(b,a){var c=a[0].split(":"),
-d=c[0],e=a[1],g=-1,h=this.attributes[b],o=h._proxyCalls,j;if(f.contains(r,d)){f.size(c)>1&&(j=c[1]);if(h instanceof l&&"change"===d&&e){var k=s(j),i=f.initial(k);(c=h.find(function(a){var b=a.get(k);return e===!(b instanceof n||b instanceof l)?a.get(i):b}))&&(g=h.indexOf(c))}j=b+(g!==-1?"["+g+"]":"")+(j?"."+j:"");a[0]=d+":"+j;if(o){if(d=f.find(o,function(a,b){return j.indexOf(b,j.length-b.length)!==-1}))return this}else o=h._proxyCalls={};o[j]=true}this.trigger.apply(this,a);j&&o&&delete o[j];return this},
-_createCollection:function(b){var a=b;f.isString(a)&&(a=eval(a));if(a&&a.prototype instanceof n){b=new l;b.model=a}else throw Error("type must inherit from Backbone.AssociatedModel");return b},hasChanged:function(b){var a,c,d;if(!this.visitedHC){this.visitedHC=true;a=m.hasChanged.apply(this,arguments);if(!a&&this.relations)for(d=0;d<this.relations.length;++d){c=this.relations[d];if(c=this.attributes[c.key]){if(c instanceof l){c=c.filter(function(a){return a.hasChanged()===true});f.size(c)>0&&(a=true)}else a=
-c.hasChanged&&c.hasChanged();if(a)break}}delete this.visitedHC}return!!a},changedAttributes:function(b){var a,c,d,e;if(!this.visited){this.visited=true;a=m.changedAttributes.apply(this,arguments);if(this.relations)for(e=0;e<this.relations.length;++e){c=this.relations[e];if(d=this.attributes[c.key])if(d instanceof l){d=f.filter(d.map(function(a){return a.changedAttributes()}),function(a){return!!a});f.size(d)>0&&(a[c.key]=d)}else d instanceof n&&d.hasChanged()&&(a[c.key]=d.toJSON())}delete this.visited}return!a?
-false:a},previousAttributes:function(){var b,a,c,d;if(!this.visited){this.visited=true;b=m.previousAttributes.apply(this,arguments);this.relations&&f.each(this.relations,function(e){a=this.attributes[e.key];d=(c=b[e.key])?c.toJSON():void 0;c&&c==a?a instanceof n?b[e.key]=a.previousAttributes():a instanceof l&&(b[e.key]=a.map(function(a){return a.previousAttributes()})):c&&(b[e.key]=d)},this);delete this.visited}return b},previous:function(b){return this.previousAttributes()[b]},toJSON:function(b){var a,
-c;if(!this.visited){this.visited=true;a=m.toJSON.apply(this,arguments);this.relations&&f.each(this.relations,function(d){var e=this.attributes[d.key];if(e){c=e.toJSON(b);a[d.key]=f.isArray(c)?f.compact(c):c}},this);delete this.visited}return a},clone:function(){return new this.constructor(this.toJSON())},getAttr:function(b,a){var c=this,d=s(b),e,g;a||(a=function(a,b){return a instanceof l&&f.isNumber(b)?a.at(b):a.attributes[b]});for(g=0;g<d.length;g++){e=d[g];if(!c)break;c=a.call(this,c,e,d)}return c}});
-var s=function(b,a,c){if(f.isString(b)){a||(a=function(a){return a.match(/^\d+$/)?parseInt(a,10):a});return f.map(b.match(/[^\.\[\]]+/g)||[],a,c)}return b||[]}})();
+(function(){var f,k,q,l,m,s,o;"undefined"!==typeof require?(f=require("underscore"),k=require("backbone"),exports=module.exports=k):(f=window._,k=window.Backbone);q=k.Model;l=k.Collection;m=q.prototype;s="change add remove reset destroy sync error sort request".split(" ");k.Many="Many";k.One="One";o=k.AssociatedModel=q.extend({relations:void 0,_proxyCalls:void 0,get:function(d){return this.getAttr.apply(this,arguments)},set:function(d,a,c){var b,e,j,n,i=this;if(f.isObject(d)||d==null){b=d;c=a}else{b=
+{};b[d]=a}if(!b)return this;for(e in b){var a=r(e),d=f.initial(a),a=f.last(a),g=this,h=this.get(d);j||(j={});if(!(!h&&f.size(d)>0||h instanceof l)){h instanceof o&&(g=h);d=j[g.cid]||(j[g.cid]={model:g,data:{}});d.data[a]=b[e]}}if(j)for(n in j){d=j[n];this.setAttr.call(d.model,d.data,c)||(i=false)}else i=this.setAttr.call(this,b,c);return i},setAttr:function(d,a){var c,b,e;a||(a={});if(a.unset)for(e in d)d[e]=void 0;this.relations&&f.each(this.relations,function(b){var e=b.key,i=b.relatedModel,g=b.collectionType,
+h,p;if(d[e]){h=f.result(d,e);i&&f.isString(i)&&(i=eval(i));g&&f.isString(g)&&(g=eval(g));p=b.options?f.extend({},b.options,a):a;if(b.type===k.Many){if(g&&!g.prototype instanceof l)throw Error("collectionType must inherit from Backbone.Collection");if(h instanceof l)m.set.call(this,e,h,p);else if(this.attributes[e])this.attributes[e].reset(h,p);else{b=g?new g:this._createCollection(i);b.add(h,p);m.set.call(this,e,b,p)}}else if(b.type===k.One&&i){b=h instanceof o?h:new i(h);m.set.call(this,e,b,p)}if((h=
+this.attributes[e])&&!h._proxyCallback){h._proxyCallback=function(){return this._bubbleEvent.call(this,e,arguments)};h.on("all",h._proxyCallback,this)}!c&&(c=[]);f.indexOf(c,e)===-1&&c.push(e)}},this);if(c){b={};for(e in d)f.indexOf(c,e)===-1&&(b[e]=d[e])}else b=d;return m.set.call(this,b,a)},_bubbleEvent:function(d,a){var c=a[0].split(":"),b=c[0],e=a[1],j=-1,n=this.attributes[d],i=n._proxyCalls,g;if(f.contains(s,b)){f.size(c)>1&&(g=c[1]);if(n instanceof l&&"change"===b&&e){var h=r(g),k=f.initial(h);
+(c=n.find(function(b){var a=b.get(h);return e===(a instanceof o||a instanceof l)?a:b.get(k)||b}))&&(j=n.indexOf(c))}g=d+(j!==-1?"["+j+"]":"")+(g?"."+g:"");a[0]=b+":"+g;if(i){if(b=f.find(i,function(b,a){return g.indexOf(a,g.length-a.length)!==-1}))return this}else i=n._proxyCalls={};i[g]=true}this.trigger.apply(this,a);g&&i&&delete i[g];return this},_createCollection:function(d){var a=d;f.isString(a)&&(a=eval(a));if(a&&a.prototype instanceof o){d=new l;d.model=a}else throw Error("type must inherit from Backbone.AssociatedModel");
+return d},hasChanged:function(d){var a,c,b;if(!this.visitedHC){this.visitedHC=true;a=m.hasChanged.apply(this,arguments);if(!a&&this.relations)for(b=0;b<this.relations.length;++b){c=this.relations[b];if(c=this.attributes[c.key]){if(c instanceof l){c=c.filter(function(a){return a.hasChanged()===true});f.size(c)>0&&(a=true)}else a=c.hasChanged&&c.hasChanged();if(a)break}}delete this.visitedHC}return!!a},changedAttributes:function(d){var a,c,b,e;if(!this.visited){this.visited=true;a=m.changedAttributes.apply(this,
+arguments);if(this.relations)for(e=0;e<this.relations.length;++e){c=this.relations[e];if(b=this.attributes[c.key])if(b instanceof l){b=f.filter(b.map(function(a){return a.changedAttributes()}),function(a){return!!a});f.size(b)>0&&(a[c.key]=b)}else b instanceof o&&b.hasChanged()&&(a[c.key]=b.toJSON())}delete this.visited}return!a?false:a},previousAttributes:function(){var d,a,c,b;if(!this.visited){this.visited=true;d=m.previousAttributes.apply(this,arguments);this.relations&&f.each(this.relations,
+function(e){a=this.attributes[e.key];b=(c=d[e.key])?c.toJSON():void 0;c&&c==a?a instanceof o?d[e.key]=a.previousAttributes():a instanceof l&&(d[e.key]=a.map(function(a){return a.previousAttributes()})):c&&(d[e.key]=b)},this);delete this.visited}return d},previous:function(d){return this.previousAttributes()[d]},toJSON:function(d){var a,c;if(!this.visited){this.visited=true;a=m.toJSON.apply(this,arguments);this.relations&&f.each(this.relations,function(b){var e=this.attributes[b.key];if(e){c=e.toJSON(d);
+a[b.key]=f.isArray(c)?f.compact(c):c}},this);delete this.visited}return a},clone:function(){return new this.constructor(this.toJSON())},getAttr:function(d,a){var c=this,b=r(d),e,j;if(!(f.size(b)<1)){a||(a=function(a,b){return a instanceof l&&f.isNumber(b)?a.at(b):a.attributes[b]});for(j=0;j<b.length;j++){e=b[j];if(!c)break;c=a.call(this,c,e,b)}return c}}});var r=function(d,a,c){if(f.isString(d)){a||(a=function(a){return a.match(/^\d+$/)?parseInt(a,10):a});return f.map(d.match(/[^\.\[\]]+/g)||[""],
+a,c)}return d||[""]}})();
View
33 backbone-associations.js
@@ -1,5 +1,5 @@
//
-// Backbone-associations.js 0.3.1
+// Backbone-associations.js 0.4.0
//
// (c) 2013 Dhruva Ray, Jaynti Kanani
// Backbone-associations may be freely distributed under the MIT license;
@@ -12,6 +12,7 @@
(function () {
"use strict";
+
// The top-level namespace. All public Backbone classes and modules will be attached to this.
// Exported for the browser and CommonJS.
var _, Backbone, BackboneModel, BackboneCollection, ModelProto,
@@ -42,18 +43,18 @@
// Define `AssociatedModel` (Extends Backbone.Model).
AssociatedModel = Backbone.AssociatedModel = BackboneModel.extend({
// Define relations with Associated Model.
- relations: undefined,
+ relations:undefined,
// Define `Model` property which can keep track of already fired `events`,
// and prevent redundant event to be triggered in case of circular model graph.
- _proxyCalls: undefined,
+ _proxyCalls:undefined,
// Get the value of an attribute.
- get: function (attr){
+ get:function (attr) {
return this.getAttr.apply(this, arguments);
},
// Set a hash of model attributes on the Backbone Model.
- set: function (key, value, options) {
+ set:function (key, value, options) {
var attributes, attr, modelMap, modelId, obj, result = this;
// Duplicate backbone's behavior to allow separate key/value parameters,
// instead of a single 'attributes' object.
@@ -72,7 +73,7 @@
modelMap || (modelMap = {});
if ((!parentModel && _.size(initials) > 0) || parentModel instanceof BackboneCollection) continue;
parentModel instanceof AssociatedModel && (root = parentModel);
- obj = modelMap[root.cid] || (modelMap[root.cid] = {'model': root, 'data': {}});
+ obj = modelMap[root.cid] || (modelMap[root.cid] = {'model':root, 'data':{}});
obj.data[last] = attributes[attr];
}
if (modelMap) {
@@ -90,7 +91,7 @@
// fire Backbone `event` with options.
// It maintains relations between models during the set operation.
// It also bubbles up child events to the parent.
- setAttr: function (attributes, options) {
+ setAttr:function (attributes, options) {
var processedRelations, tbp, attr;
// Extract attributes and options.
options || (options = {});
@@ -175,7 +176,7 @@
return ModelProto.set.call(this, tbp, options);
},
// Bubble-up event to `parent` Model
- _bubbleEvent: function (relationKey, eventArguments) {
+ _bubbleEvent:function (relationKey, eventArguments) {
var args = eventArguments,
opt = args[0].split(":"),
eventType = opt[0],
@@ -233,7 +234,7 @@
return this;
},
// Returns New `collection` of type `relation.relatedModel`.
- _createCollection: function (type) {
+ _createCollection:function (type) {
var collection, relatedModel = type;
_.isString(relatedModel) && (relatedModel = eval(relatedModel));
// Creates new `Backbone.Collection` and defines model class.
@@ -246,7 +247,7 @@
return collection;
},
// Has the model changed. Traverse the object hierarchy to compute dirtyness.
- hasChanged: function (attr) {
+ hasChanged:function (attr) {
var isDirty, relation, attrValue, i, dirtyObjects;
// To prevent cycles, check if this node is visited.
if (!this.visitedHC) {
@@ -277,7 +278,7 @@
return !!isDirty;
},
// Returns a hash of the changed attributes.
- changedAttributes: function (diff) {
+ changedAttributes:function (diff) {
var delta, relation, attrValue, changedCollection, i;
// To prevent cycles, check if this node is visited.
if (!this.visited) {
@@ -308,7 +309,7 @@
return !delta ? false : delta;
},
// Returns the hash of the previous attributes of the graph.
- previousAttributes: function () {
+ previousAttributes:function () {
var pa, attrValue, pattrValue, pattrJSON;
// To prevent cycles, check if this node is visited.
if (!this.visited) {
@@ -338,12 +339,12 @@
return pa;
},
// Return the previous value of the passed in attribute.
- previous: function (attr) {
+ previous:function (attr) {
return this.previousAttributes()[attr];
},
// The JSON representation of the model.
- toJSON: function (options) {
+ toJSON:function (options) {
var json, aJson;
if (!this.visited) {
this.visited = true;
@@ -366,12 +367,12 @@
},
// Create a new model with identical attributes to this one.
- clone: function () {
+ clone:function () {
return new this.constructor(this.toJSON());
},
// Get `reduced` result using passed `path` array or string.
- getAttr: function (path, iterator) {
+ getAttr:function (path, iterator) {
var result = this,
attrs = getPathArray(path),
key,
View
124 docs/backbone-associations.html
72 additions, 52 deletions not shown
View
0  docs/cd-example.tex → docs/cd_example.tex
File renamed without changes
View
0  docs/img/cd-example.png → docs/img/cd_example.png
File renamed without changes
View
2  package.json
@@ -8,5 +8,5 @@
},
"lib":".",
"main":"backbone-associations.js",
- "version":"0.3.1"
+ "version":"0.4"
}
View
75 test/associated-model.js
@@ -1,11 +1,12 @@
$(document).ready(function () {
- if ( !window.console ) {
+ if (!window.console) {
window.console = {};
var names = [ 'log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml',
'group', 'groupEnd', 'time', 'timeEnd', 'count', 'trace', 'profile', 'profileEnd' ];
- for ( var i = 0; i < names.length; ++i ) {
- window.console[ names[i] ] = function() {};
+ for (var i = 0; i < names.length; ++i) {
+ window.console[ names[i] ] = function () {
+ };
}
}
@@ -227,11 +228,12 @@ $(document).ready(function () {
ok(dept1.get('locations').at(0) == loc1, "dept1's first location should be same as loc1");
});
- test("nested get", 10, function () {
+ test("nested get", 11, function () {
equal(emp.get('works_for.name'), emp.get('works_for').get('name'), 'result should be same as `get` chain');
equal(emp.get('dependents[0].fname'), emp.get('dependents').at(0).get('fname'), 'index can be defined to get model from collection, like `get("dependent[0].fname")`');
equal(emp.get('dependents[1].fname'), emp.get('dependents').at(1).get('fname'));
equal(emp.get('works_for.controls[0].locations[0].zip'), 94404);
+ equal(emp.get('works_for.controls[0].locations[0].zip'), emp.get('works_for').get('controls').at(0).get('locations').at(0).get('zip'));
deepEqual(emp.get('works_for.locations[1]').toJSON(), emp.get('works_for').get('locations').at(1).toJSON());
equal(emp.get('dependents[1000].fname'), undefined, "result should be `undefined` if indexed model in not present in collection");
@@ -242,11 +244,13 @@ $(document).ready(function () {
equal(emp.get('works_for.""'), undefined);
});
+
test("nested set", 10, function () {
equal(emp.get('works_for.name'), 'R&D');
emp.set('works_for.name', 'Marketing');
equal(emp.get('works_for.name'), 'Marketing');
+
emp.set('works_for.locations[0].zip', 94403);
equal(emp.get('works_for.locations[0].zip'), 94403, "nested `set` for model in collection should be same as normal `set`");
@@ -254,29 +258,29 @@ $(document).ready(function () {
notEqual(emp.get('dependents[0].sex'), 'X', "validate test should be passed in nested `set`");
emp.set({
- 'designation': 'Senior Manager',
- 'works_for.controls[0].locations[0].zip': 90909,
- 'dependents[1000].fname': 'outofindex',
- 'dependents[1].fname': 'John'
+ 'designation':'Senior Manager',
+ 'works_for.controls[0].locations[0].zip':90909,
+ 'dependents[1000].fname':'outofindex',
+ 'dependents[1].fname':'John'
});
equal(emp.get('dependents[1].fname'), 'John');
- emp.on('change:works_for.name', function(){
+ emp.on('change:works_for.name', function () {
ok(false);
});
emp.on('all', function (eventName) {
- ok(true, "emp, `" + eventName+ "` fired !!!");
+ ok(true, "emp, `" + eventName + "` fired !!!");
});
emp.set({
- 'works_for.name': 'Research',
- 'dependents[0].lname': 'Doe'
- }, {silent: true});
+ 'works_for.name':'Research',
+ 'dependents[0].lname':'Doe'
+ }, {silent:true});
emp.off('change:works_for.name');
emp.get('works_for').change();
emp.get('dependents[0]').change();
emp.set({
- 'wrongpath.path2.works_for.name': 'mip'
+ 'wrongpath.path2.works_for.name':'mip'
});
ok(true);
});
@@ -428,8 +432,14 @@ $(document).ready(function () {
equal(true, emp.get('works_for').hasChanged());
equal(true, emp.hasChanged());
var changed = emp.get('works_for').changedAttributes();
- deepEqual(changed['locations'], [{"zip":94403}]);
- deepEqual(changed['controls'], [{"locations":[{"zip":94403}]}]);
+ deepEqual(changed['locations'], [
+ {"zip":94403}
+ ]);
+ deepEqual(changed['controls'], [
+ {"locations":[
+ {"zip":94403}
+ ]}
+ ]);
ok(true, "Fired works_for locations0 change...");
});
@@ -475,29 +485,29 @@ $(document).ready(function () {
project2.get("locations").add(loc1);
project2.get("locations").add(loc1); //add it twice deliberately
- emp.on('change:works_for.controls[0].locations[0].zip',function(event){
- ok(true,"Fired emp > change:works_for.controls[0].locations[0].zip");
+ emp.on('change:works_for.controls[0].locations[0].zip', function (event) {
+ ok(true, "Fired emp > change:works_for.controls[0].locations[0].zip");
});
- emp.on('change:works_for.controls[0].locations[0]',function(event){
- ok(true,"Fired emp > change:works_for.controls[0].locations[0]");
+ emp.on('change:works_for.controls[0].locations[0]', function (event) {
+ ok(true, "Fired emp > change:works_for.controls[0].locations[0]");
});
- emp.on('change:works_for.controls[1].locations[1].zip',function(event){
- ok(true,"Fired emp > change:works_for.controls[1].locations[1].zip");
+ emp.on('change:works_for.controls[1].locations[1].zip', function (event) {
+ ok(true, "Fired emp > change:works_for.controls[1].locations[1].zip");
});
- emp.on('change:works_for.controls[1].locations[1]',function(event){
- ok(true,"Fired emp > change:works_for.controls[1].locations[1]");
+ emp.on('change:works_for.controls[1].locations[1]', function (event) {
+ ok(true, "Fired emp > change:works_for.controls[1].locations[1]");
});
- emp.on('change:works_for.locations[0].zip',function(event){
- ok(true,"Fired emp > change:works_for.locations[0].zip");
+ emp.on('change:works_for.locations[0].zip', function (event) {
+ ok(true, "Fired emp > change:works_for.locations[0].zip");
});
- emp.on('change:works_for.locations[0]',function(event){
- ok(true,"Fired emp > change:works_for.locations[0]");
+ emp.on('change:works_for.locations[0]', function (event) {
+ ok(true, "Fired emp > change:works_for.locations[0]");
});
emp.get('works_for').get("locations").at(0).set('zip', 94403);
@@ -1135,7 +1145,7 @@ $(document).ready(function () {
}
});
- test("example-1", 42, function () {
+ test("example-1", 43, function () {
emp.once('change', function () {
console.log("Fired emp > change...");
ok("Fired emp > change...");
@@ -1174,7 +1184,7 @@ $(document).ready(function () {
ok("Fired emp > change:works_for.name...");
equal(true, emp.get("works_for").hasChanged());
equal(true, emp.hasChanged());
- equal(true, emp.hasChanged("works_for"))
+ equal(true, emp.hasChanged("works_for"));
deepEqual(emp.changedAttributes()['works_for'], emp.get("works_for").toJSON());
equal(emp.get("works_for").previousAttributes()["name"], "R&D");
equal(emp.get("works_for").previous("name"), "R&D");
@@ -1276,6 +1286,9 @@ $(document).ready(function () {
emp.get("dependents").add(child2);
emp.get("dependents").remove([child1]);
emp.get("dependents").reset();
+
+ equal(emp.get('works_for.controls[0].locations[0].zip'), emp.get('works_for').get('controls').at(0).get('locations').at(0).get('zip'));
+
});
test("example-2", 42, function () {
@@ -1322,7 +1335,7 @@ $(document).ready(function () {
ok("Fired emp > change:works_for.name...");
equal(true, emp.get("works_for").hasChanged());
equal(true, emp.hasChanged());
- equal(true, emp.hasChanged("works_for"))
+ equal(true, emp.hasChanged("works_for"));
deepEqual(emp.changedAttributes()['works_for'], emp.get("works_for").toJSON());
equal(emp.get("works_for").previousAttributes()["name"], "R&D");
equal(emp.get("works_for").previous("name"), "R&D");
Please sign in to comment.
Something went wrong with that request. Please try again.