@atsi/backbone-nested
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -1,2 +0,2 @@ | ||
var t,e=(t=require("backbone"))&&"object"==typeof t&&"default"in t?t.default:t,i=e.Model,n=e.Collection;e.Model.prototype._attrConstructor=function(t,e){return t._constructor},e.Model.prototype.getParsedValue=function(t,e,s){var r,o,h=this.attributes[t],a=this.idAttribute||"id",u=[],c=[];if(s.unset&&h&&delete h.parent,null==e)return e;if(this.schema&&_.has(this.schema,t))if(o=this._attrConstructor(r=this.schema[t],e),"related"==r.type&&_.isFunction(o)){if(h&&h instanceof n)return e instanceof n||e instanceof Array?(e=e.models||e,u=_.clone(e),h.each(function(t,i){if(void 0!==t[a]){var n=_.find(e,function(e){return e[a]===t[a]});n?(t!==n&&t.set(n.toJSON?n.toJSON():n),u=_(u).reject(function(e){return e[a]===t[a]})):c.push(t)}}),_.each(c,function(t){h.remove(t)}),h.add(u)):h.each(function(t){e[a]===t[a]?t.set(e):h.remove(t)}),h;if(h&&h instanceof i){if(e instanceof o){if(e.id!=h.id)return e;e=e.attributes}return h.set(e),h}if(!_.isObject(e))return e;if(e instanceof o)return e;(e=new o(e,_.defaults({_parent:this},s))).parent=this}else _.isFunction(o)&&(e=new o(e));return e},e.Model.prototype.set=function(t,e,i){var n,s,r,o,h,a,u,c;if(null==t)return this;if("object"==typeof t?(s=t,i=e):(s={})[t]=e,i||(i={}),!this._validate(s,i))return!1;for(n in r=i.unset,h=i.silent,o=[],a=this._changing,this._changing=!0,a||(this._previousAttributes=_.clone(this.attributes),this.changed={}),c=this.attributes,u=this._previousAttributes,this.idAttribute in s&&(this.id=s[this.idAttribute]),s)e=s[n],!1!==i.handle_relations&&(e=this.getParsedValue(n,e,i)),_.isEqual(c[n],e)||o.push(n),_.isEqual(u[n],e)?delete this.changed[n]:this.changed[n]=e,r?delete c[n]:c[n]=e;if(!h){o.length&&(this._pending=!0);for(var l=0,f=o.length;l<f;l++)this.trigger("change:"+o[l],this,c[o[l]],i)}if(a)return this;if(!h)for(;this._pending;)this._pending=!1,this.trigger("change",this,i);return this._pending=!1,this._changing=!1,this},e.Model.prototype.toJSON=function(t){var e=_.clone(this.attributes);return _.each(this.schema,function(t,i){_.has(e,i)&&e[i].toJSON&&(e[i]=e[i].toJSON())}),e},e.Collection.prototype.resetRelations=function(t){_.each(this.models,function(i){_.each(i.schema,function(n,s){var r=i.get(s);r instanceof e.Collection&&r.trigger("reset",r,t)})})},e.Collection.prototype.reset=function(t,e){e||(e={});for(var i=0,n=this.models.length;i<n;i++)this._removeReference(this.models[i]);return e.previousModels=this.models,this._reset(),this.add(t,_.extend({silent:!0},e)),e.silent||(this.trigger("reset",this,e),this.resetRelations(e)),this},module.exports=e; | ||
function t(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var e=/*#__PURE__*/t(require("backbone")),i=e.default.Model,n=e.default.Collection;e.default.Model.prototype._attrConstructor=function(t,e){return t._constructor},e.default.Model.prototype.getParsedValue=function(t,e,s){var r,o,a=this.attributes[t],u=this.idAttribute||"id",h=[],c=[];if(s.unset&&a&&delete a.parent,null==e)return e;if(this.schema&&_.has(this.schema,t))if(o=this._attrConstructor(r=this.schema[t],e),"related"==r.type&&_.isFunction(o)){if(a&&a instanceof n)return e instanceof n||e instanceof Array?(e=e.models||e,h=_.clone(e),a.each(function(t,i){if(void 0!==t[u]){var n=_.find(e,function(e){return e[u]===t[u]});n?(t!==n&&t.set(n.toJSON?n.toJSON():n),h=_(h).reject(function(e){return e[u]===t[u]})):c.push(t)}}),_.each(c,function(t){a.remove(t)}),a.add(h)):a.each(function(t){e[u]===t[u]?t.set(e):a.remove(t)}),a;if(a&&a instanceof i){if(e instanceof o){if(e.id!=a.id)return e;e=e.attributes}return a.set(e),a}if(!_.isObject(e))return e;if(e instanceof o)return e;(e=new o(e,_.defaults({_parent:this},s))).parent=this}else _.isFunction(o)&&(e=new o(e));return e},e.default.Model.prototype.set=function(t,e,i){var n,s,r,o,a,u,h,c;if(null==t)return this;if("object"==typeof t?(s=t,i=e):(s={})[t]=e,i||(i={}),!this._validate(s,i))return!1;for(n in r=i.unset,a=i.silent,o=[],u=this._changing,this._changing=!0,u||(this._previousAttributes=_.clone(this.attributes),this.changed={}),c=this.attributes,h=this._previousAttributes,this.idAttribute in s&&(this.id=s[this.idAttribute]),s)e=s[n],!1!==i.handle_relations&&(e=this.getParsedValue(n,e,i)),_.isEqual(c[n],e)||o.push(n),_.isEqual(h[n],e)?delete this.changed[n]:this.changed[n]=e,r?delete c[n]:c[n]=e;if(!a){o.length&&(this._pending=!0);for(var l=0,f=o.length;l<f;l++)this.trigger("change:"+o[l],this,c[o[l]],i)}if(u)return this;if(!a)for(;this._pending;)this._pending=!1,this.trigger("change",this,i);return this._pending=!1,this._changing=!1,this},e.default.Model.prototype.toJSON=function(t){var e=_.clone(this.attributes);return _.each(this.schema,function(t,i){_.has(e,i)&&e[i].toJSON&&(e[i]=e[i].toJSON())}),e},e.default.Collection.prototype.resetRelations=function(t){_.each(this.models,function(i){_.each(i.schema,function(n,s){var r=i.get(s);r instanceof e.default.Collection&&r.trigger("reset",r,t)})})},e.default.Collection.prototype.reset=function(t,e){e||(e={});for(var i=0,n=this.models.length;i<n;i++)this._removeReference(this.models[i]);return e.previousModels=this.models,this._reset(),this.add(t,_.extend({silent:!0},e)),e.silent||(this.trigger("reset",this,e),this.resetRelations(e)),this},module.exports=e.default; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("backbone")):"function"==typeof define&&define.amd?define(["backbone"],e):t.backboneNested=e(t.backbone)}(this,function(t){var e=(t=t&&t.hasOwnProperty("default")?t.default:t).Model,i=t.Collection;return t.Model.prototype._attrConstructor=function(t,e){return t._constructor},t.Model.prototype.getParsedValue=function(t,n,s){var r,o,h=this.attributes[t],a=this.idAttribute||"id",u=[],c=[];if(s.unset&&h&&delete h.parent,null==n)return n;if(this.schema&&_.has(this.schema,t))if(o=this._attrConstructor(r=this.schema[t],n),"related"==r.type&&_.isFunction(o)){if(h&&h instanceof i)return n instanceof i||n instanceof Array?(n=n.models||n,u=_.clone(n),h.each(function(t,e){if(void 0!==t[a]){var i=_.find(n,function(e){return e[a]===t[a]});i?(t!==i&&t.set(i.toJSON?i.toJSON():i),u=_(u).reject(function(e){return e[a]===t[a]})):c.push(t)}}),_.each(c,function(t){h.remove(t)}),h.add(u)):h.each(function(t){n[a]===t[a]?t.set(n):h.remove(t)}),h;if(h&&h instanceof e){if(n instanceof o){if(n.id!=h.id)return n;n=n.attributes}return h.set(n),h}if(!_.isObject(n))return n;if(n instanceof o)return n;(n=new o(n,_.defaults({_parent:this},s))).parent=this}else _.isFunction(o)&&(n=new o(n));return n},t.Model.prototype.set=function(t,e,i){var n,s,r,o,h,a,u,c;if(null==t)return this;if("object"==typeof t?(s=t,i=e):(s={})[t]=e,i||(i={}),!this._validate(s,i))return!1;for(n in r=i.unset,h=i.silent,o=[],a=this._changing,this._changing=!0,a||(this._previousAttributes=_.clone(this.attributes),this.changed={}),c=this.attributes,u=this._previousAttributes,this.idAttribute in s&&(this.id=s[this.idAttribute]),s)e=s[n],!1!==i.handle_relations&&(e=this.getParsedValue(n,e,i)),_.isEqual(c[n],e)||o.push(n),_.isEqual(u[n],e)?delete this.changed[n]:this.changed[n]=e,r?delete c[n]:c[n]=e;if(!h){o.length&&(this._pending=!0);for(var f=0,d=o.length;f<d;f++)this.trigger("change:"+o[f],this,c[o[f]],i)}if(a)return this;if(!h)for(;this._pending;)this._pending=!1,this.trigger("change",this,i);return this._pending=!1,this._changing=!1,this},t.Model.prototype.toJSON=function(t){var e=_.clone(this.attributes);return _.each(this.schema,function(t,i){_.has(e,i)&&e[i].toJSON&&(e[i]=e[i].toJSON())}),e},t.Collection.prototype.resetRelations=function(e){_.each(this.models,function(i){_.each(i.schema,function(n,s){var r=i.get(s);r instanceof t.Collection&&r.trigger("reset",r,e)})})},t.Collection.prototype.reset=function(t,e){e||(e={});for(var i=0,n=this.models.length;i<n;i++)this._removeReference(this.models[i]);return e.previousModels=this.models,this._reset(),this.add(t,_.extend({silent:!0},e)),e.silent||(this.trigger("reset",this,e),this.resetRelations(e)),this},t}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("backbone")):"function"==typeof define&&define.amd?define(["backbone"],e):(t||self).backboneNested=e(t.backbone)}(this,function(t){function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=/*#__PURE__*/e(t),n=i.default.Model,s=i.default.Collection;return i.default.Model.prototype._attrConstructor=function(t,e){return t._constructor},i.default.Model.prototype.getParsedValue=function(t,e,i){var r,o,a=this.attributes[t],u=this.idAttribute||"id",h=[],f=[];if(i.unset&&a&&delete a.parent,null==e)return e;if(this.schema&&_.has(this.schema,t))if(o=this._attrConstructor(r=this.schema[t],e),"related"==r.type&&_.isFunction(o)){if(a&&a instanceof s)return e instanceof s||e instanceof Array?(e=e.models||e,h=_.clone(e),a.each(function(t,i){if(void 0!==t[u]){var n=_.find(e,function(e){return e[u]===t[u]});n?(t!==n&&t.set(n.toJSON?n.toJSON():n),h=_(h).reject(function(e){return e[u]===t[u]})):f.push(t)}}),_.each(f,function(t){a.remove(t)}),a.add(h)):a.each(function(t){e[u]===t[u]?t.set(e):a.remove(t)}),a;if(a&&a instanceof n){if(e instanceof o){if(e.id!=a.id)return e;e=e.attributes}return a.set(e),a}if(!_.isObject(e))return e;if(e instanceof o)return e;(e=new o(e,_.defaults({_parent:this},i))).parent=this}else _.isFunction(o)&&(e=new o(e));return e},i.default.Model.prototype.set=function(t,e,i){var n,s,r,o,a,u,h,f;if(null==t)return this;if("object"==typeof t?(s=t,i=e):(s={})[t]=e,i||(i={}),!this._validate(s,i))return!1;for(n in r=i.unset,a=i.silent,o=[],u=this._changing,this._changing=!0,u||(this._previousAttributes=_.clone(this.attributes),this.changed={}),f=this.attributes,h=this._previousAttributes,this.idAttribute in s&&(this.id=s[this.idAttribute]),s)e=s[n],!1!==i.handle_relations&&(e=this.getParsedValue(n,e,i)),_.isEqual(f[n],e)||o.push(n),_.isEqual(h[n],e)?delete this.changed[n]:this.changed[n]=e,r?delete f[n]:f[n]=e;if(!a){o.length&&(this._pending=!0);for(var c=0,l=o.length;c<l;c++)this.trigger("change:"+o[c],this,f[o[c]],i)}if(u)return this;if(!a)for(;this._pending;)this._pending=!1,this.trigger("change",this,i);return this._pending=!1,this._changing=!1,this},i.default.Model.prototype.toJSON=function(t){var e=_.clone(this.attributes);return _.each(this.schema,function(t,i){_.has(e,i)&&e[i].toJSON&&(e[i]=e[i].toJSON())}),e},i.default.Collection.prototype.resetRelations=function(t){_.each(this.models,function(e){_.each(e.schema,function(n,s){var r=e.get(s);r instanceof i.default.Collection&&r.trigger("reset",r,t)})})},i.default.Collection.prototype.reset=function(t,e){e||(e={});for(var i=0,n=this.models.length;i<n;i++)this._removeReference(this.models[i]);return e.previousModels=this.models,this._reset(),this.add(t,_.extend({silent:!0},e)),e.silent||(this.trigger("reset",this,e),this.resetRelations(e)),this},i.default}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@atsi/backbone-nested", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Backbone nested models", | ||
@@ -20,4 +20,4 @@ "source": "src/index.js", | ||
"devDependencies": { | ||
"microbundle": "=0.9.0" | ||
"microbundle": "^0.15.1" | ||
} | ||
} |
@@ -16,3 +16,2 @@ import Backbone from 'backbone'; | ||
var id = this.idAttribute || 'id'; | ||
var modelToSet; | ||
var modelsToAdd = []; | ||
@@ -19,0 +18,0 @@ var modelsToRemove = []; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
61484
10
236
1