backbone-associations
Advanced tools
Comparing version 0.5.4 to 0.5.5
@@ -1,13 +0,13 @@ | ||
(function(){var z=this,f,e,w,p,u,v,C,s,D,E,F,q;"undefined"!==typeof exports?(f=require("underscore"),e=require("backbone"),"undefined"!==typeof module&&module.exports&&(module.exports=e),exports=e):(f=z._,e=z.Backbone);w=e.Model;p=e.Collection;u=w.prototype;v=p.prototype;C="change add remove reset sort destroy".split(" ");E=["reset","sort"];e.Associations={VERSION:"0.5.4"};var G=function(){return q},A=function(a){if(!f.isString(a)||1>f.size(a))a=".";q=a;D=RegExp("[\\"+q+"\\[\\]]+","g");F=RegExp("[^\\"+ | ||
q+"\\[\\]]+","g")};try{Object.defineProperty(e.Associations,"SEPARATOR",{enumerable:!0,get:G,set:A})}catch(J){}e.Associations.Many=e.Many="Many";e.Associations.One=e.One="One";e.Associations.Self=e.Self="Self";e.Associations.SEPARATOR=".";e.Associations.getSeparator=G;e.Associations.setSeparator=A;A();s=e.AssociatedModel=e.Associations.AssociatedModel=w.extend({relations:void 0,_proxyCalls:void 0,get:function(a){var c=u.get.call(this,a);return c?c:this._getAttr.apply(this,arguments)},set:function(a, | ||
c,d){var b;f.isObject(a)||null==a?(b=a,d=c):(b={},b[a]=c);a=this._set(b,d);this._processPendingEvents();return a},_set:function(a,c){var d,b,H,g,e=this;if(!a)return this;for(d in a)if(b||(b={}),d.match(D)){var n=B(d);g=f.initial(n);n=n[n.length-1];g=this.get(g);g instanceof s&&(g=b[g.cid]||(b[g.cid]={model:g,data:{}}),g.data[n]=a[d])}else g=b[this.cid]||(b[this.cid]={model:this,data:{}}),g.data[d]=a[d];if(b)for(H in b)g=b[H],this._setAttr.call(g.model,g.data,c)||(e=!1);else e=this._setAttr.call(this, | ||
a,c);return e},_setAttr:function(a,c){var d;c||(c={});if(c.unset)for(d in a)a[d]=void 0;this.parents=this.parents||[];this.relations&&f.each(this.relations,function(b){var d=b.key,g=b.relatedModel,m=b.collectionType,n=b.map,k=this.attributes[d],l=k&&k.idAttribute,h,t,r,q=!1;!g||g.prototype instanceof w||(g=f.isFunction(g)?g.call(this,b,a):g);g&&f.isString(g)&&(g=g===e.Self?this.constructor:x(g));m&&f.isString(m)&&(m=x(m));n&&f.isString(n)&&(n=x(n));t=b.options?f.extend({},b.options,c):c;if(!g&&!m)throw Error("specify either a relatedModel or collectionType"); | ||
if(a[d]){h=f.result(a,d);h=n?n.call(this,h,m?m:g):h;if(b.type===e.Many){if(m&&!m.prototype instanceof p)throw Error("collectionType must inherit from Backbone.Collection");k?(k._deferEvents=!0,k[t.reset?"reset":"set"](h instanceof p?h.models:h,t),b=k):(q=!0,h instanceof p?b=h:(b=m?new m:this._createCollection(g),b[t.reset?"reset":"set"](h,t)))}else if(b.type===e.One){if(!g)throw Error("specify a relatedModel for Backbone.One type");if(!(g.prototype instanceof e.AssociatedModel))throw Error("specify an AssociatedModel for Backbone.One type"); | ||
b=h instanceof s?h:new g(h,t);k&&b.attributes[l]&&k.attributes[l]===b.attributes[l]?(k._deferEvents=!0,k._set(h instanceof s?h.attributes:h,t),b=k):q=!0}else throw Error("type attribute must be specified and have the values Backbone.One or Backbone.Many");r=a[d]=b;if(q||r&&!r._proxyCallback)r._proxyCallback=function(){return this._bubbleEvent.call(this,d,r,arguments)},r.on("all",r._proxyCallback,this)}a.hasOwnProperty(d)&&(k=a[d],l=this.attributes[d],k?(k.parents=k.parents||[],-1==f.indexOf(k.parents, | ||
this)&&k.parents.push(this)):l&&0<l.parents.length&&(l.parents=f.difference(l.parents,[this]),l._proxyCallback&&l.off("all",l._proxyCallback,this)))},this);return u.set.call(this,a,c)},_bubbleEvent:function(a,c,d){var b=d[0].split(":"),e=b[0],g="nested-change"==d[0],m=d[1],n=d[2],k=-1,l=c._proxyCalls,h,t=-1!==f.indexOf(C,e);if(!g){1<f.size(b)&&(h=b[1]);-1!==f.indexOf(E,e)&&(n=m);if(c instanceof p&&t&&m){var r=B(h),u=f.initial(r);(b=c.find(function(a){if(m===a)return!0;if(!a)return!1;var b=a.get(u); | ||
if((b instanceof s||b instanceof p)&&m===b)return!0;b=a.get(r);if((b instanceof s||b instanceof p)&&m===b||b instanceof p&&n&&n===b)return!0}))&&(k=c.indexOf(b))}h=a+(-1===k||"change"!==e&&!h?"":"["+k+"]")+(h?q+h:"");if(/\[\*\]/g.test(h))return this;b=h.replace(/\[\d+\]/g,"[*]");k=[];k.push.apply(k,d);k[0]=e+":"+h;l=c._proxyCalls=l||{};if(this._isEventAvailable.call(this,l,h))return this;l[h]=!0;"change"===e&&(this._previousAttributes[a]=c._previousAttributes,this.changed[a]=c);this.trigger.apply(this, | ||
k);"change"===e&&this.get(h)!=d[2]&&(a=["nested-change",h,d[1]],d[2]&&a.push(d[2]),this.trigger.apply(this,a));l&&h&&delete l[h];h!==b&&(k[0]=e+":"+b,this.trigger.apply(this,k));return this}},_isEventAvailable:function(a,c){return f.find(a,function(a,b){return-1!==c.indexOf(b,c.length-b.length)})},_createCollection:function(a){var c=a;f.isString(c)&&(c=x(c));if(c&&c.prototype instanceof s||f.isFunction(c))a=new p,a.model=c;else throw Error("type must inherit from Backbone.AssociatedModel");return a}, | ||
_processPendingEvents:function(){this._processedEvents||(this._processedEvents=!0,this._deferEvents=!1,f.each(this._pendingEvents,function(a){a.c.trigger.apply(a.c,a.a)}),this._pendingEvents=[],f.each(this.relations,function(a){(a=this.attributes[a.key])&&a._processPendingEvents()},this),delete this._processedEvents)},trigger:function(a){this._deferEvents?(this._pendingEvents=this._pendingEvents||[],this._pendingEvents.push({c:this,a:arguments})):u.trigger.apply(this,arguments)},toJSON:function(a){var c= | ||
{},d;c[this.idAttribute]=this.id;this.visited||(this.visited=!0,c=u.toJSON.apply(this,arguments),this.relations&&f.each(this.relations,function(b){var e=this.attributes[b.key];e&&(d=e.toJSON?e.toJSON(a):e,c[b.key]=f.isArray(d)?f.compact(d):d)},this),delete this.visited);return c},clone:function(){return new this.constructor(this.toJSON())},cleanup:function(){f.each(this.relations,function(a){(a=this.attributes[a.key])&&(a.parents=f.difference(a.parents,[this]))},this);this.off()},_getAttr:function(a){var c= | ||
this;a=B(a);var d,b;if(!(1>f.size(a))){for(b=0;b<a.length;b++){d=a[b];if(!c)break;c=c instanceof p?isNaN(d)?void 0:c.at(d):c.attributes[d]}return c}}});var B=function(a){return""===a?[""]:f.isString(a)?a.match(F):a||[]},x=function(a){return f.reduce(a.split(q),function(a,d){return a[d]},z)},I=function(a,c,d){var b,e;f.find(a,function(a){if(b=f.find(a.relations,function(b){return a.get(b.key)===c},this))return e=a,!0},this);return b&&b.map?b.map.call(e,d,c):d},y={};f.each(["set","remove","reset"], | ||
function(a){y[a]=p.prototype[a];v[a]=function(c,d){this.model.prototype instanceof s&&this.parents&&(arguments[0]=I(this.parents,this,c));return y[a].apply(this,arguments)}});y.trigger=v.trigger;v.trigger=function(a){this._deferEvents?(this._pendingEvents=this._pendingEvents||[],this._pendingEvents.push({c:this,a:arguments})):y.trigger.apply(this,arguments)};v._processPendingEvents=s.prototype._processPendingEvents}).call(this); | ||
(function(){var z=this,g,e,u,q,v,w,r,C,D,p,A;"undefined"!==typeof exports?(g=require("underscore"),e=require("backbone"),"undefined"!==typeof module&&module.exports&&(module.exports=e),exports=e):(g=z._,e=z.Backbone);u=e.Model;q=e.Collection;v=u.prototype;w=q.prototype;e.Associations={VERSION:"0.5.5"};var E=function(){return p},B=function(a){if(!g.isString(a)||1>g.size(a))a=".";p=a;C=RegExp("[\\"+p+"\\[\\]]+","g");D=RegExp("[^\\"+p+"\\[\\]]+","g")};try{Object.defineProperty(e.Associations,"SEPARATOR", | ||
{enumerable:!0,get:E,set:B})}catch(H){}e.Associations.Many=e.Many="Many";e.Associations.One=e.One="One";e.Associations.Self=e.Self="Self";e.Associations.SEPARATOR=".";e.Associations.getSeparator=E;e.Associations.setSeparator=B;e.Associations.EVENTS_BUBBLE=!0;e.Associations.EVENTS_WILDCARD=!0;e.Associations.EVENTS_NC=!0;B();r=e.AssociatedModel=e.Associations.AssociatedModel=u.extend({relations:void 0,_proxyCalls:void 0,get:function(a){var c=v.get.call(this,a);return c?c:this._getAttr.apply(this,arguments)}, | ||
set:function(a,c,d){var b;g.isObject(a)||null==a?(b=a,d=c):(b={},b[a]=c);a=this._set(b,d);this._processPendingEvents();return a},_set:function(a,c){var d,b,e,f,h=this;if(!a)return this;for(d in a)if(b||(b={}),d.match(C)){var l=F(d);f=g.initial(l);l=l[l.length-1];f=this.get(f);f instanceof r&&(f=b[f.cid]||(b[f.cid]={model:f,data:{}}),f.data[l]=a[d])}else f=b[this.cid]||(b[this.cid]={model:this,data:{}}),f.data[d]=a[d];if(b)for(e in b)f=b[e],this._setAttr.call(f.model,f.data,c)||(h=!1);else h=this._setAttr.call(this, | ||
a,c);return h},_setAttr:function(a,c){var d;c||(c={});if(c.unset)for(d in a)a[d]=void 0;this.parents=this.parents||[];this.relations&&g.each(this.relations,function(b){var d=b.key,f=b.relatedModel,h=b.collectionType,l=b.map,k=this.attributes[d],n=k&&k.idAttribute,m,s,t,p=!1;!f||f.prototype instanceof u||(f=g.isFunction(f)?f.call(this,b,a):f);f&&g.isString(f)&&(f=f===e.Self?this.constructor:x(f));h&&g.isString(h)&&(h=x(h));l&&g.isString(l)&&(l=x(l));s=b.options?g.extend({},b.options,c):c;if(!f&&!h)throw Error("specify either a relatedModel or collectionType"); | ||
if(a[d]){m=g.result(a,d);m=l?l.call(this,m,h?h:f):m;if(b.type===e.Many){if(h&&!h.prototype instanceof q)throw Error("collectionType must inherit from Backbone.Collection");k?(k._deferEvents=!0,k[s.reset?"reset":"set"](m instanceof q?m.models:m,s),b=k):(p=!0,m instanceof q?b=m:(b=h?new h:this._createCollection(f),b[s.reset?"reset":"set"](m,s)))}else if(b.type===e.One){if(!f)throw Error("specify a relatedModel for Backbone.One type");if(!(f.prototype instanceof e.AssociatedModel))throw Error("specify an AssociatedModel for Backbone.One type"); | ||
b=m instanceof r?m:new f(m,s);k&&b.attributes[n]&&k.attributes[n]===b.attributes[n]?(k._deferEvents=!0,k._set(m instanceof r?m.attributes:m,s),b=k):p=!0}else throw Error("type attribute must be specified and have the values Backbone.One or Backbone.Many");t=a[d]=b;if(p||t&&!t._proxyCallback)t._proxyCallback=function(){return e.Associations.EVENTS_BUBBLE&&this._bubbleEvent.call(this,d,t,arguments)},t.on("all",t._proxyCallback,this)}a.hasOwnProperty(d)&&(k=a[d],n=this.attributes[d],k?(k.parents=k.parents|| | ||
[],-1==g.indexOf(k.parents,this)&&k.parents.push(this)):n&&0<n.parents.length&&(n.parents=g.difference(n.parents,[this]),n._proxyCallback&&n.off("all",n._proxyCallback,this)))},this);return v.set.call(this,a,c)},_bubbleEvent:function(a,c,d){var b=d[0].split(":"),g=b[0],f="change"===g,h=d[1],l=-1,k=c._proxyCalls,b=b[1],n;if("nested-change"!=d[0]){if(e.Associations.EVENTS_WILDCARD&&/\[\*\]/g.test(b))return this;c instanceof q&&(f||b)&&(l=c.indexOf(A||h));this instanceof u&&(A=this);b=a+(-1!==l&&(f|| | ||
b)?"["+l+"]":"")+(b?p+b:"");e.Associations.EVENTS_WILDCARD&&(n=b.replace(/\[\d+\]/g,"[*]"));h=[];h.push.apply(h,d);h[0]=g+":"+b;e.Associations.EVENTS_WILDCARD&&b!==n&&(h[0]=h[0]+" "+g+":"+n);k=c._proxyCalls=k||{};if(this._isEventAvailable.call(this,k,b))return this;k[b]=!0;f&&(this._previousAttributes[a]=c._previousAttributes,this.changed[a]=c);this.trigger.apply(this,h);e.Associations.EVENTS_NC&&(f&&this.get(b)!=d[2])&&(a=["nested-change",b,d[1]],d[2]&&a.push(d[2]),this.trigger.apply(this,a));k&& | ||
b&&delete k[b];A=void 0;return this}},_isEventAvailable:function(a,c){return g.find(a,function(a,b){return-1!==c.indexOf(b,c.length-b.length)})},_createCollection:function(a){var c=a;g.isString(c)&&(c=x(c));if(c&&c.prototype instanceof r||g.isFunction(c))a=new q,a.model=c;else throw Error("type must inherit from Backbone.AssociatedModel");return a},_processPendingEvents:function(){this._processedEvents||(this._processedEvents=!0,this._deferEvents=!1,g.each(this._pendingEvents,function(a){a.c.trigger.apply(a.c, | ||
a.a)}),this._pendingEvents=[],g.each(this.relations,function(a){(a=this.attributes[a.key])&&a._processPendingEvents()},this),delete this._processedEvents)},trigger:function(a){this._deferEvents?(this._pendingEvents=this._pendingEvents||[],this._pendingEvents.push({c:this,a:arguments})):v.trigger.apply(this,arguments)},toJSON:function(a){var c={},d;c[this.idAttribute]=this.id;this.visited||(this.visited=!0,c=v.toJSON.apply(this,arguments),this.relations&&g.each(this.relations,function(b){var e=b.key, | ||
f=b.remoteKey,h=this.attributes[e];b=!b.isTransient;delete c[e];b&&(d=h&&h.toJSON?h.toJSON(a):h,c[f||e]=g.isArray(d)?g.compact(d):d)},this),delete this.visited);return c},clone:function(){return new this.constructor(this.toJSON())},cleanup:function(){g.each(this.relations,function(a){(a=this.attributes[a.key])&&(a.parents=g.difference(a.parents,[this]))},this);this.off()},_getAttr:function(a){var c=this;a=F(a);var d,b;if(!(1>g.size(a))){for(b=0;b<a.length;b++){d=a[b];if(!c)break;c=c instanceof q? | ||
isNaN(d)?void 0:c.at(d):c.attributes[d]}return c}}});var F=function(a){return""===a?[""]:g.isString(a)?a.match(D):a||[]},x=function(a){return g.reduce(a.split(p),function(a,d){return a[d]},z)},G=function(a,c,d){var b,e;g.find(a,function(a){if(b=g.find(a.relations,function(b){return a.get(b.key)===c},this))return e=a,!0},this);return b&&b.map?b.map.call(e,d,c):d},y={};g.each(["set","remove","reset"],function(a){y[a]=q.prototype[a];w[a]=function(c,d){this.model.prototype instanceof r&&this.parents&& | ||
(arguments[0]=G(this.parents,this,c));return y[a].apply(this,arguments)}});y.trigger=w.trigger;w.trigger=function(a){this._deferEvents?(this._pendingEvents=this._pendingEvents||[],this._pendingEvents.push({c:this,a:arguments})):y.trigger.apply(this,arguments)};w._processPendingEvents=r.prototype._processPendingEvents}).call(this); |
// | ||
// Backbone-associations.js 0.5.4 | ||
// Backbone-associations.js 0.5.5 | ||
// | ||
@@ -22,4 +22,4 @@ // (c) 2013 Dhruva Ray, Jaynti Kanani, Persistent Systems Ltd. | ||
var _, Backbone, BackboneModel, BackboneCollection, ModelProto, | ||
CollectionProto, defaultEvents, AssociatedModel, pathChecker, | ||
collectionEvents, delimiters, pathSeparator; | ||
CollectionProto, AssociatedModel, pathChecker, | ||
delimiters, pathSeparator, source; | ||
@@ -43,8 +43,4 @@ if (typeof exports !== 'undefined') { | ||
// Built-in Backbone `events`. | ||
defaultEvents = ["change", "add", "remove", "reset", "sort", "destroy"]; | ||
collectionEvents = ["reset", "sort"]; | ||
Backbone.Associations = { | ||
VERSION: "0.5.4" | ||
VERSION: "0.5.5" | ||
}; | ||
@@ -87,3 +83,10 @@ | ||
Backbone.Associations.setSeparator = setSeparator; | ||
Backbone.Associations.EVENTS_BUBBLE = true; | ||
Backbone.Associations.EVENTS_WILDCARD = true; | ||
Backbone.Associations.EVENTS_NC = true; | ||
setSeparator(); | ||
// Define `AssociatedModel` (Extends Backbone.Model). | ||
@@ -97,2 +100,3 @@ AssociatedModel = Backbone.AssociatedModel = Backbone.Associations.AssociatedModel = BackboneModel.extend({ | ||
// Get the value of an attribute. | ||
@@ -268,3 +272,4 @@ get:function (attr) { | ||
relationValue._proxyCallback = function () { | ||
return this._bubbleEvent.call(this, relationKey, relationValue, arguments); | ||
return Backbone.Associations.EVENTS_BUBBLE && | ||
this._bubbleEvent.call(this, relationKey, relationValue, arguments); | ||
}; | ||
@@ -294,2 +299,4 @@ relationValue.on("all", relationValue._proxyCallback, this); | ||
}, | ||
// Bubble-up event to `parent` Model | ||
@@ -301,56 +308,38 @@ _bubbleEvent:function (relationKey, relationValue, eventArguments) { | ||
catch_all = args[0] == "nested-change", | ||
isChangeEvent = eventType === "change", | ||
eventObject = args[1], | ||
colObject = args[2], | ||
indexEventObject = -1, | ||
_proxyCalls = relationValue._proxyCalls, | ||
cargs, | ||
eventPath, | ||
basecolEventPath, | ||
isDefaultEvent = _.indexOf(defaultEvents, eventType) !== -1; | ||
eventPath = opt[1], | ||
basecolEventPath; | ||
//Short circuit the listen in to the nested-graph event | ||
// Short circuit the listen in to the nested-graph event | ||
if (catch_all) return; | ||
// Change the event name to a fully qualified path. | ||
_.size(opt) > 1 && (eventPath = opt[1]); | ||
// Short circuit the listen in to the wild-card event | ||
if (Backbone.Associations.EVENTS_WILDCARD) { | ||
if (/\[\*\]/g.test(eventPath)) return this; | ||
} | ||
if (_.indexOf(collectionEvents, eventType) !== -1) { | ||
colObject = eventObject; | ||
if (relationValue instanceof BackboneCollection && (isChangeEvent || eventPath)) { | ||
// O(n) search :( | ||
indexEventObject = relationValue.indexOf(source || eventObject); | ||
} | ||
// Find the specific object in the collection which has changed. | ||
if (relationValue instanceof BackboneCollection && isDefaultEvent && eventObject) { | ||
var pathTokens = getPathArray(eventPath), | ||
initialTokens = _.initial(pathTokens), colModel; | ||
colModel = relationValue.find(function (model) { | ||
if (eventObject === model) return true; | ||
if (!model) return false; | ||
var changedModel = model.get(initialTokens); | ||
if ((changedModel instanceof AssociatedModel || changedModel instanceof BackboneCollection) | ||
&& eventObject === changedModel) | ||
return true; | ||
changedModel = model.get(pathTokens); | ||
if ((changedModel instanceof AssociatedModel || changedModel instanceof BackboneCollection) | ||
&& eventObject === changedModel) | ||
return true; | ||
if (changedModel instanceof BackboneCollection && colObject | ||
&& colObject === changedModel) | ||
return true; | ||
}); | ||
colModel && (indexEventObject = relationValue.indexOf(colModel)); | ||
if (this instanceof BackboneModel) { | ||
// A quicker way to identify the model which caused an update inside the collection (while bubbling up) | ||
source = this; | ||
} | ||
// Manipulate `eventPath`. | ||
eventPath = relationKey + ((indexEventObject !== -1 && (eventType === "change" || eventPath)) ? | ||
eventPath = relationKey + ((indexEventObject !== -1 && (isChangeEvent || eventPath)) ? | ||
"[" + indexEventObject + "]" : "") + (eventPath ? pathSeparator + eventPath : ""); | ||
// Short circuit collection * events | ||
if (/\[\*\]/g.test(eventPath)) return this; | ||
basecolEventPath = eventPath.replace(/\[\d+\]/g, '[*]'); | ||
if (Backbone.Associations.EVENTS_WILDCARD) { | ||
basecolEventPath = eventPath.replace(/\[\d+\]/g, '[*]'); | ||
} | ||
cargs = []; | ||
@@ -360,2 +349,7 @@ cargs.push.apply(cargs, args); | ||
// Create a collection modified event with wild-card | ||
if (Backbone.Associations.EVENTS_WILDCARD && eventPath !== basecolEventPath) { | ||
cargs[0] = cargs[0] + " " + eventType + ":" + basecolEventPath; | ||
} | ||
// If event has been already triggered as result of same source `eventPath`, | ||
@@ -369,4 +363,5 @@ // no need to re-trigger event to prevent cycle. | ||
// Set up previous attributes correctly. | ||
if ("change" === eventType) { | ||
if (isChangeEvent) { | ||
this._previousAttributes[relationKey] = relationValue._previousAttributes; | ||
@@ -377,6 +372,7 @@ this.changed[relationKey] = relationValue; | ||
// Bubble up event to parent `model` with new changed arguments. | ||
this.trigger.apply(this, cargs); | ||
//Only fire for change. Not change:attribute | ||
if ("change" === eventType && this.get(eventPath) != args[2]) { | ||
if (Backbone.Associations.EVENTS_NC && isChangeEvent && this.get(eventPath) != args[2]) { | ||
var ncargs = ["nested-change", eventPath, args[1]]; | ||
@@ -392,7 +388,3 @@ args[2] && ncargs.push(args[2]); //args[2] will be options if present | ||
// Create a collection modified event with wild-card | ||
if (eventPath !== basecolEventPath) { | ||
cargs[0] = eventType + ":" + basecolEventPath; | ||
this.trigger.apply(this, cargs); | ||
} | ||
source = undefined; | ||
@@ -471,7 +463,17 @@ return this; | ||
_.each(this.relations, function (relation) { | ||
var attr = this.attributes[relation.key]; | ||
if (attr) { | ||
aJson = attr.toJSON ? attr.toJSON(options) : attr; | ||
json[relation.key] = _.isArray(aJson) ? _.compact(aJson) : aJson; | ||
var key = relation.key, | ||
remoteKey = relation.remoteKey, | ||
attr = this.attributes[key], | ||
serialize = !relation.isTransient; | ||
// Remove default Backbone serialization for associations. | ||
delete json[key]; | ||
//Assign to remoteKey if specified. Otherwise use the default key. | ||
//Only for non-transient relationships | ||
if (serialize) { | ||
aJson = attr && attr.toJSON ? attr.toJSON(options) : attr; | ||
json[remoteKey || key] = _.isArray(aJson) ? _.compact(aJson) : aJson; | ||
} | ||
}, this); | ||
@@ -478,0 +480,0 @@ } |
{ | ||
"name":"backbone-associations", | ||
"version": "0.5.4", | ||
"version": "0.5.5", | ||
"main":"./backbone-associations.js", | ||
@@ -8,3 +8,4 @@ "dependencies":{ | ||
"underscore":">=1.4.3" | ||
} | ||
}, | ||
"ignore": ["docs", "test", "*.yml"] | ||
} |
@@ -0,1 +1,8 @@ | ||
### Version 0.5.5 - [Diff](https://github.com/dhruvaray/backbone-associations/compare/v0.5.4...v0.5.5) | ||
* Improve event bubbling performance for large object graphs. | ||
* Introduces flags to switch off/on events. Set Backbone.Associations.EVENTS_WILDCARD = false to stop throwing wild-char events. Set Backbone.Associations.EVENTS_NC = false to stop throwing nested-change events. Set Backbone.Associations.EVENTS_BUBBLE = false to conditionally stop events from bubbling up. May be useful when constructing complex object (sub) graphs. After construction the value can be set to true. Note that all of these flags can be toggled at any time during the application flow. | ||
* Introduces isTransient flag to avoid serializing the particular attribute in toJSON(). | ||
* Introduces remoteKey for serializing relations to a different key name. Useful in ROR nested-attributes like scenarios. | ||
### Version 0.5.4 - [Diff](https://github.com/dhruvaray/backbone-associations/compare/v0.5.3...v0.5.4) | ||
@@ -2,0 +9,0 @@ |
@@ -33,3 +33,3 @@ { | ||
"main":"backbone-associations.js", | ||
"version": "0.5.4", | ||
"version": "0.5.5", | ||
"repository":"git://github.com/dhruvaray/backbone-associations.git", | ||
@@ -36,0 +36,0 @@ "licenses":[ |
### Backbone-associations [![Build Status](https://travis-ci.org/dhruvaray/backbone-associations.png?branch=master)](https://travis-ci.org/dhruvaray/backbone-associations) | ||
Associations allows Backbone applications to model 1:1 & 1:N associations between application models and Collections. More importantly, applications can listen to any kind of change (change, add, remove, reset, sort, destroy) in this hierarchy using standard Backbone events and respond to them. (views can re-render for example). The implementation strives to be tiny (2.2KB), easy-to-understand, light-weight and fast. | ||
Associations allows Backbone applications to model 1:1 & 1:N associations between application models and Collections. More importantly, applications can listen to any kind of change (change, add, remove, reset, sort, destroy) in this hierarchy using standard Backbone events and respond to them. (views can re-render for example). The implementation strives to be tiny (2.6KB), easy-to-understand, light-weight and fast. | ||
@@ -10,4 +10,10 @@ For features, performance #s, API documentation, tutorials and recipes, please visit : | ||
### Who uses Backbone-Associations? | ||
See https://github.com/dhruvaray/backbone-associations/issues/55 | ||
We encourage you to add your experiences to this list! | ||
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/dhruvaray/backbone-associations/trend.png)](https://bitdeli.com/free "Bitdeli Badge") | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
948320
24556
19