diff --git a/CHANGELOG.md b/CHANGELOG.md index dc11ade..c1ff740 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Change log +### v1.0.0 + +* Updated Backbone and Underscore version ranges again + +### v1.0.0-pre.2 + +* Updated Backbone and Underscore version ranges + +### v1.0.0-pre.1 + +* Moved Backbone and Underscore to peerDependencies + ### v0.1.12 * Bump version range of backbone support. diff --git a/bower.json b/bower.json index 0d73887..52dd388 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "backbone.babysitter", - "version": "0.1.12", + "version": "1.0.0", "homepage": "https://github.com/marionettejs/backbone.babysitter", "authors": [ "Derick Bailey " @@ -17,8 +17,8 @@ "browser" ], "dependencies": { - "backbone": ">=0.9.9 <1.4", - "underscore": ">=1.4.0 <=1.8.3" + "backbone": ">=1.3.3", + "underscore": ">=1.8.3" }, "license": "MIT", "ignore": [ diff --git a/lib/backbone.babysitter.js b/lib/backbone.babysitter.js index 92db27b..fb0401d 100644 --- a/lib/backbone.babysitter.js +++ b/lib/backbone.babysitter.js @@ -1,8 +1,8 @@ // Backbone.BabySitter // ------------------- -// v0.1.11 +// v1.0.0 // -// Copyright (c)2016 Derick Bailey, Muted Solutions, LLC. +// Copyright (c)2019 Derick Bailey, Muted Solutions, LLC. // Distributed under MIT license // // http://github.com/marionettejs/backbone.babysitter @@ -43,7 +43,7 @@ this._indexByCustom = {}; this._updateLength(); - _.each(views, this.add, this); + _.each(views, _.bind(this.add, this)); }; // Container Methods @@ -56,23 +56,8 @@ // cid (and model itself). Optionally specify // a custom key to store an retrieve the view. add: function(view, customIndex){ - var viewCid = view.cid; - - // store the view - this._views[viewCid] = view; - - // index it by model - if (view.model){ - this._indexByModel[view.model.cid] = viewCid; - } - - // index by custom - if (customIndex){ - this._indexByCustom[customIndex] = viewCid; - } - - this._updateLength(); - return this; + return this._add(view, customIndex) + ._updateLength(); }, // Find a view by the model that was attached to @@ -108,34 +93,15 @@ // Remove a view remove: function(view){ - var viewCid = view.cid; - - // delete model index - if (view.model){ - delete this._indexByModel[view.model.cid]; - } - - // delete custom index - _.any(this._indexByCustom, function(cid, key) { - if (cid === viewCid) { - delete this._indexByCustom[key]; - return true; - } - }, this); - - // remove the view from the container - delete this._views[viewCid]; - - // update the length - this._updateLength(); - return this; + return this._remove(view) + ._updateLength(); }, // Call a method on every view in the container, // passing parameters to the call method one at a // time, like `function.call`. call: function(method){ - this.apply(method, _.tail(arguments)); + this.apply(method, _.toArray(arguments).slice(1)); }, // Apply a method on every view in the container, @@ -152,6 +118,53 @@ // Update the `.length` attribute on this container _updateLength: function(){ this.length = _.size(this._views); + + return this; + }, + // To be used when avoiding call _updateLength + // When you are done adding all your new views + // call _updateLength + _add: function(view, customIndex){ + var viewCid = view.cid; + + // store the view + this._views[viewCid] = view; + + // index it by model + if (view.model){ + this._indexByModel[view.model.cid] = viewCid; + } + + // index by custom + if (customIndex){ + this._indexByCustom[customIndex] = viewCid; + } + + return this; + }, + // To be used when avoiding call _updateLength + // When you are done adding all your new views + // call _updateLength + _remove: function (view){ + var viewCid = view.cid; + + // delete model index + if (view.model){ + delete this._indexByModel[view.model.cid]; + } + + // delete custom index + _.some(this._indexByCustom, _.bind(function(cid, key) { + if (cid === viewCid) { + delete this._indexByCustom[key]; + return true; + } + }, this)); + + // remove the view from the container + delete this._views[viewCid]; + + return this; } }); @@ -178,7 +191,7 @@ })(Backbone, _); - Backbone.ChildViewContainer.VERSION = '0.1.11'; + Backbone.ChildViewContainer.VERSION = '1.0.0'; Backbone.ChildViewContainer.noConflict = function () { Backbone.ChildViewContainer = previousChildViewContainer; diff --git a/lib/backbone.babysitter.map b/lib/backbone.babysitter.map deleted file mode 100644 index cab6c38..0000000 --- a/lib/backbone.babysitter.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["?"],"names":["root","factory","define","amd","Backbone","_","exports","require","module","this","previousChildViewContainer","ChildViewContainer","Container","views","_views","_indexByModel","_indexByCustom","_updateLength","each","add","extend","prototype","view","customIndex","viewCid","cid","model","findByModel","findByModelCid","modelCid","findByCid","findByCustom","index","findByIndex","values","remove","any","key","call","method","apply","tail","arguments","args","isFunction","length","size","methods","concat","toArray","VERSION","noConflict"],"mappings":"CASC,SAASA,EAAMC,GAEd,GAAsB,kBAAXC,SAAyBA,OAAOC,IACzCD,QAAQ,WAAY,cAAe,SAASE,EAAUC,GACpD,MAAOJ,GAAQG,EAAUC,SAEtB,IAAuB,mBAAZC,SAAyB,CACzC,GAAIF,GAAWG,QAAQ,YACnBF,EAAIE,QAAQ,aAChBC,QAAOF,QAAUL,EAAQG,EAAUC,OAEnCJ,GAAQD,EAAKI,SAAUJ,EAAKK,KAG9BI,KAAM,SAASL,EAAUC,GACzB,YAEA,IAAIK,GAA6BN,EAASO,kBAiK1C,OAzJAP,GAASO,mBAAqB,SAAWP,EAAUC,GAKjD,GAAIO,GAAY,SAASC,GACvBJ,KAAKK,UACLL,KAAKM,iBACLN,KAAKO,kBACLP,KAAKQ,gBAELZ,EAAEa,KAAKL,EAAOJ,KAAKU,IAAKV,MAM1BJ,GAAEe,OAAOR,EAAUS,WAMjBF,IAAK,SAASG,EAAMC,GAClB,GAAIC,GAAUF,EAAKG,GAgBnB,OAbAhB,MAAKK,OAAOU,GAAWF,EAGnBA,EAAKI,QACPjB,KAAKM,cAAcO,EAAKI,MAAMD,KAAOD,GAInCD,IACFd,KAAKO,eAAeO,GAAeC,GAGrCf,KAAKQ,gBACER,MAKTkB,YAAa,SAASD,GACpB,MAAOjB,MAAKmB,eAAeF,EAAMD,MAMnCG,eAAgB,SAASC,GACvB,GAAIL,GAAUf,KAAKM,cAAcc,EACjC,OAAOpB,MAAKqB,UAAUN,IAIxBO,aAAc,SAASC,GACrB,GAAIR,GAAUf,KAAKO,eAAegB,EAClC,OAAOvB,MAAKqB,UAAUN,IAKxBS,YAAa,SAASD,GACpB,MAAO3B,GAAE6B,OAAOzB,KAAKK,QAAQkB,IAI/BF,UAAW,SAASL,GAClB,MAAOhB,MAAKK,OAAOW,IAIrBU,OAAQ,SAASb,GACf,GAAIE,GAAUF,EAAKG,GAoBnB,OAjBIH,GAAKI,aACAjB,MAAKM,cAAcO,EAAKI,MAAMD,KAIvCpB,EAAE+B,IAAI3B,KAAKO,eAAgB,SAASS,EAAKY,GACvC,MAAIZ,KAAQD,SACHf,MAAKO,eAAeqB,IACpB,GAFT,QAIC5B,YAGIA,MAAKK,OAAOU,GAGnBf,KAAKQ,gBACER,MAMT6B,KAAM,SAASC,GACb9B,KAAK+B,MAAMD,EAAQlC,EAAEoC,KAAKC,aAM5BF,MAAO,SAASD,EAAQI,GACtBtC,EAAEa,KAAKT,KAAKK,OAAQ,SAASQ,GACvBjB,EAAEuC,WAAWtB,EAAKiB,KACpBjB,EAAKiB,GAAQC,MAAMlB,EAAMqB,UAM/B1B,cAAe,WACbR,KAAKoC,OAASxC,EAAEyC,KAAKrC,KAAKK,UAS9B,IAAIiC,IAAW,UAAW,OAAQ,MAAO,OAAQ,SAAU,SACzD,SAAU,SAAU,QAAS,MAAO,OAAQ,MAAO,UACnD,WAAY,SAAU,UAAW,QAAS,UAAW,OACrD,OAAQ,UAAW,UAAW,QAAS,SAWzC,OATA1C,GAAEa,KAAK6B,EAAS,SAASR,GACvB3B,EAAUS,UAAUkB,GAAU,WAC5B,GAAI1B,GAAQR,EAAE6B,OAAOzB,KAAKK,QACtB6B,GAAQ9B,GAAOmC,OAAO3C,EAAE4C,QAAQP,WACpC,OAAOrC,GAAEkC,GAAQC,MAAMnC,EAAGsC,MAKvB/B,GACNR,EAAUC,GAGbD,EAASO,mBAAmBuC,QAAU,SAEtC9C,EAASO,mBAAmBwC,WAAa,WAEvC,MADA/C,GAASO,mBAAqBD,EACvBD,MAGFL,EAASO","file":"lib/backbone.babysitter.min.js"} \ No newline at end of file diff --git a/lib/backbone.babysitter.min.js b/lib/backbone.babysitter.min.js index d9db642..b4ae39c 100644 --- a/lib/backbone.babysitter.min.js +++ b/lib/backbone.babysitter.min.js @@ -1,12 +1,12 @@ // Backbone.BabySitter // ------------------- -// v0.1.11 +// v1.0.0 // -// Copyright (c)2016 Derick Bailey, Muted Solutions, LLC. +// Copyright (c)2019 Derick Bailey, Muted Solutions, LLC. // Distributed under MIT license // // http://github.com/marionettejs/backbone.babysitter -!function(a,b){if("function"==typeof define&&define.amd)define(["backbone","underscore"],function(a,c){return b(a,c)});else if("undefined"!=typeof exports){var c=require("backbone"),d=require("underscore");module.exports=b(c,d)}else b(a.Backbone,a._)}(this,function(a,b){"use strict";var c=a.ChildViewContainer;return a.ChildViewContainer=function(a,b){var c=function(a){this._views={},this._indexByModel={},this._indexByCustom={},this._updateLength(),b.each(a,this.add,this)};b.extend(c.prototype,{add:function(a,b){var c=a.cid;return this._views[c]=a,a.model&&(this._indexByModel[a.model.cid]=c),b&&(this._indexByCustom[b]=c),this._updateLength(),this},findByModel:function(a){return this.findByModelCid(a.cid)},findByModelCid:function(a){var b=this._indexByModel[a];return this.findByCid(b)},findByCustom:function(a){var b=this._indexByCustom[a];return this.findByCid(b)},findByIndex:function(a){return b.values(this._views)[a]},findByCid:function(a){return this._views[a]},remove:function(a){var c=a.cid;return a.model&&delete this._indexByModel[a.model.cid],b.any(this._indexByCustom,function(a,b){return a===c?(delete this._indexByCustom[b],!0):void 0},this),delete this._views[c],this._updateLength(),this},call:function(a){this.apply(a,b.tail(arguments))},apply:function(a,c){b.each(this._views,function(d){b.isFunction(d[a])&&d[a].apply(d,c||[])})},_updateLength:function(){this.length=b.size(this._views)}});var d=["forEach","each","map","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","toArray","first","initial","rest","last","without","isEmpty","pluck","reduce"];return b.each(d,function(a){c.prototype[a]=function(){var c=b.values(this._views),d=[c].concat(b.toArray(arguments));return b[a].apply(b,d)}}),c}(a,b),a.ChildViewContainer.VERSION="0.1.11",a.ChildViewContainer.noConflict=function(){return a.ChildViewContainer=c,this},a.ChildViewContainer}); +!function(a,b){if("function"==typeof define&&define.amd)define(["backbone","underscore"],function(a,c){return b(a,c)});else if("undefined"!=typeof exports){var c=require("backbone"),d=require("underscore");module.exports=b(c,d)}else b(a.Backbone,a._)}(this,function(a,b){"use strict";var c=a.ChildViewContainer;return a.ChildViewContainer=function(a,b){var c=function(a){this._views={},this._indexByModel={},this._indexByCustom={},this._updateLength(),b.each(a,b.bind(this.add,this))};b.extend(c.prototype,{add:function(a,b){return this._add(a,b)._updateLength()},findByModel:function(a){return this.findByModelCid(a.cid)},findByModelCid:function(a){var b=this._indexByModel[a];return this.findByCid(b)},findByCustom:function(a){var b=this._indexByCustom[a];return this.findByCid(b)},findByIndex:function(a){return b.values(this._views)[a]},findByCid:function(a){return this._views[a]},remove:function(a){return this._remove(a)._updateLength()},call:function(a){this.apply(a,b.toArray(arguments).slice(1))},apply:function(a,c){b.each(this._views,function(d){b.isFunction(d[a])&&d[a].apply(d,c||[])})},_updateLength:function(){return this.length=b.size(this._views),this},_add:function(a,b){var c=a.cid;return this._views[c]=a,a.model&&(this._indexByModel[a.model.cid]=c),b&&(this._indexByCustom[b]=c),this},_remove:function(a){var c=a.cid;return a.model&&delete this._indexByModel[a.model.cid],b.some(this._indexByCustom,b.bind(function(a,b){if(a===c)return delete this._indexByCustom[b],!0},this)),delete this._views[c],this}});var d=["forEach","each","map","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","toArray","first","initial","rest","last","without","isEmpty","pluck","reduce"];return b.each(d,function(a){c.prototype[a]=function(){var c=b.values(this._views),d=[c].concat(b.toArray(arguments));return b[a].apply(b,d)}}),c}(a,b),a.ChildViewContainer.VERSION="1.0.0",a.ChildViewContainer.noConflict=function(){return a.ChildViewContainer=c,this},a.ChildViewContainer}); //# sourceMappingURL=backbone.babysitter.min.js.map \ No newline at end of file diff --git a/lib/backbone.babysitter.min.js.map b/lib/backbone.babysitter.min.js.map index 264d171..b680293 100644 --- a/lib/backbone.babysitter.min.js.map +++ b/lib/backbone.babysitter.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["backbone.babysitter.js"],"names":["root","factory","define","amd","Backbone","_","exports","require","module","this","previousChildViewContainer","ChildViewContainer","Container","views","_views","_indexByModel","_indexByCustom","_updateLength","each","add","extend","prototype","view","customIndex","viewCid","cid","model","findByModel","findByModelCid","modelCid","findByCid","findByCustom","index","findByIndex","values","remove","any","key","call","method","apply","tail","arguments","args","isFunction","length","size","methods","concat","toArray","VERSION","noConflict"],"mappings":";;;;;;;;;;CASC,SAASA,EAAMC,GAEd,GAAsB,kBAAXC,SAAyBA,OAAOC,IACzCD,QAAQ,WAAY,cAAe,SAASE,EAAUC,GACpD,MAAOJ,GAAQG,EAAUC,SAEtB,IAAuB,mBAAZC,SAAyB,CACzC,GAAIF,GAAWG,QAAQ,YACnBF,EAAIE,QAAQ,aAChBC,QAAOF,QAAUL,EAAQG,EAAUC,OAEnCJ,GAAQD,EAAKI,SAAUJ,EAAKK,IAG9BI,KAAM,SAASL,EAAUC,GACzB,YAEA,IAAIK,GAA6BN,EAASO,kBAiK1C,OAzJAP,GAASO,mBAAqB,SAAWP,EAAUC,GAKjD,GAAIO,GAAY,SAASC,GACvBJ,KAAKK,UACLL,KAAKM,iBACLN,KAAKO,kBACLP,KAAKQ,gBAELZ,EAAEa,KAAKL,EAAOJ,KAAKU,IAAKV,MAM1BJ,GAAEe,OAAOR,EAAUS,WAMjBF,IAAK,SAASG,EAAMC,GAClB,GAAIC,GAAUF,EAAKG,GAgBnB,OAbAhB,MAAKK,OAAOU,GAAWF,EAGnBA,EAAKI,QACPjB,KAAKM,cAAcO,EAAKI,MAAMD,KAAOD,GAInCD,IACFd,KAAKO,eAAeO,GAAeC,GAGrCf,KAAKQ,gBACER,MAKTkB,YAAa,SAASD,GACpB,MAAOjB,MAAKmB,eAAeF,EAAMD,MAMnCG,eAAgB,SAASC,GACvB,GAAIL,GAAUf,KAAKM,cAAcc,EACjC,OAAOpB,MAAKqB,UAAUN,IAIxBO,aAAc,SAASC,GACrB,GAAIR,GAAUf,KAAKO,eAAegB,EAClC,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end of file +{"version":3,"sources":["backbone.babysitter.js"],"names":["root","factory","define","amd","Backbone","_","exports","require","module","this","previousChildViewContainer","ChildViewContainer","Container","views","_views","_indexByModel","_indexByCustom","_updateLength","each","bind","add","extend","prototype","view","customIndex","_add","findByModel","model","findByModelCid","cid","modelCid","viewCid","findByCid","findByCustom","index","findByIndex","values","remove","_remove","call","method","apply","toArray","arguments","slice","args","isFunction","length","size","some","key","methods","concat","VERSION","noConflict"],"mappings":";;;;;;;;;;CASC,SAASA,EAAMC,GAEd,GAAsB,kBAAXC,SAAyBA,OAAOC,IACzCD,QAAQ,WAAY,cAAe,SAASE,EAAUC,GACpD,MAAOJ,GAAQG,EAAUC,SAEtB,IAAuB,mBAAZC,SAAyB,CACzC,GAAIF,GAAWG,QAAQ,YACnBF,EAAIE,QAAQ,aAChBC,QAAOF,QAAUL,EAAQG,EAAUC,OAEnCJ,GAAQD,EAAKI,SAAUJ,EAAKK,IAG9BI,KAAM,SAASL,EAAUC,GACzB,YAEA,IAAIK,GAA6BN,EAASO,kBA8K1C,OAtKAP,GAASO,mBAAqB,SAAWP,EAAUC,GAKjD,GAAIO,GAAY,SAASC,GACvBJ,KAAKK,UACLL,KAAKM,iBACLN,KAAKO,kBACLP,KAAKQ,gBAELZ,EAAEa,KAAKL,EAAOR,EAAEc,KAAKV,KAAKW,IAAKX,OAMjCJ,GAAEgB,OAAOT,EAAUU,WAMjBF,IAAK,SAASG,EAAMC,GAClB,MAAOf,MAAKgB,KAAKF,EAAMC,GACXP,iBAKdS,YAAa,SAASC,GACpB,MAAOlB,MAAKmB,eAAeD,EAAME,MAMnCD,eAAgB,SAASE,GACvB,GAAIC,GAAUtB,KAAKM,cAAce,EACjC,OAAOrB,MAAKuB,UAAUD,IAIxBE,aAAc,SAASC,GACrB,GAAIH,GAAUtB,KAAKO,eAAekB,EAClC,OAAOzB,MAAKuB,UAAUD,IAKxBI,YAAa,SAASD,GACpB,MAAO7B,GAAE+B,OAAO3B,KAAKK,QAAQoB,I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C,GAAQC,MAAMpC,EAAGwC,MAKvBjC,GACNR,EAAUC,GAGbD,EAASO,mBAAmB0C,QAAU,QAEtCjD,EAASO,mBAAmB2C,WAAa,WAEvC,MADAlD,GAASO,mBAAqBD,EACvBD,MAGFL,EAASO","file":"backbone.babysitter.min.js"} \ No newline at end of file diff --git a/package.json b/package.json index e0e3010..852d31f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "backbone.babysitter", "description": "Manage child views in a Backbone.View", - "version": "0.1.12", + "version": "1.0.0", "homepage": "https://github.com/marionettejs/backbone.babysitter", "main": "lib/backbone.babysitter.js", "keywords": [ @@ -37,11 +37,12 @@ "url": "https://github.com/marionettejs/backbone.babysitter.git" }, "github": "https://github.com/marionettejs/backbone.babysitter", - "dependencies": { - "backbone": ">=0.9.9 <=1.3.x", - "underscore": ">=1.4.0 <=1.8.3" + "peerDependencies": { + "backbone": "^1.3.3", + "underscore": "^1.8.3" }, "devDependencies": { + "backbone": ">=1.3.3", "grunt": "0.4.4", "grunt-cli": "0.1.13", "grunt-contrib-concat": "0.1.2", @@ -51,6 +52,7 @@ "grunt-contrib-uglify": "1.0.1", "grunt-contrib-watch": "0.2.0", "grunt-preprocess": "4.0.0", - "grunt-template": "0.2.3" + "grunt-template": "0.2.3", + "underscore": ">=1.4.0 <=1.9.1" } } diff --git a/spec/javascripts/childviewContainer.spec.js b/spec/javascripts/childviewContainer.spec.js index 9018440..eaa795d 100644 --- a/spec/javascripts/childviewContainer.spec.js +++ b/spec/javascripts/childviewContainer.spec.js @@ -8,7 +8,7 @@ describe("childview container", function(){ new Backbone.View(), new Backbone.View(), new Backbone.View() - ] + ]; container = new Backbone.ChildViewContainer(views); }); @@ -85,11 +85,11 @@ describe("childview container", function(){ }); describe("when removing a view", function(){ - var container, view, model, col, cust; + var container, view, model, cust; beforeEach(function(){ model = new Backbone.Model(); - cust = "custome indexer"; + cust = "custom indexer"; view = new Backbone.View({ model: model @@ -101,9 +101,9 @@ describe("childview container", function(){ container.remove(view); }); - it("should update the size of the chidren", function(){ + it("should update the size of the children", function(){ expect(container.length).toBe(0); - }) + }); it("should remove the index by model", function(){ var v = container.findByModel(model); @@ -230,7 +230,7 @@ describe("childview container", function(){ container = new Backbone.ChildViewContainer(); container.add(view); - container.each(function(v, k){ + container.each(function(v){ views.push(v); }); }); diff --git a/src/childviewcontainer.js b/src/childviewcontainer.js index a72df18..8ad1333 100644 --- a/src/childviewcontainer.js +++ b/src/childviewcontainer.js @@ -15,7 +15,7 @@ Backbone.ChildViewContainer = (function (Backbone, _) { this._indexByCustom = {}; this._updateLength(); - _.each(views, this.add, this); + _.each(views, _.bind(this.add, this)); }; // Container Methods @@ -28,23 +28,8 @@ Backbone.ChildViewContainer = (function (Backbone, _) { // cid (and model itself). Optionally specify // a custom key to store an retrieve the view. add: function(view, customIndex){ - var viewCid = view.cid; - - // store the view - this._views[viewCid] = view; - - // index it by model - if (view.model){ - this._indexByModel[view.model.cid] = viewCid; - } - - // index by custom - if (customIndex){ - this._indexByCustom[customIndex] = viewCid; - } - - this._updateLength(); - return this; + return this._add(view, customIndex) + ._updateLength(); }, // Find a view by the model that was attached to @@ -80,34 +65,15 @@ Backbone.ChildViewContainer = (function (Backbone, _) { // Remove a view remove: function(view){ - var viewCid = view.cid; - - // delete model index - if (view.model){ - delete this._indexByModel[view.model.cid]; - } - - // delete custom index - _.any(this._indexByCustom, function(cid, key) { - if (cid === viewCid) { - delete this._indexByCustom[key]; - return true; - } - }, this); - - // remove the view from the container - delete this._views[viewCid]; - - // update the length - this._updateLength(); - return this; + return this._remove(view) + ._updateLength(); }, // Call a method on every view in the container, // passing parameters to the call method one at a // time, like `function.call`. call: function(method){ - this.apply(method, _.tail(arguments)); + this.apply(method, _.toArray(arguments).slice(1)); }, // Apply a method on every view in the container, @@ -124,6 +90,53 @@ Backbone.ChildViewContainer = (function (Backbone, _) { // Update the `.length` attribute on this container _updateLength: function(){ this.length = _.size(this._views); + + return this; + }, + // To be used when avoiding call _updateLength + // When you are done adding all your new views + // call _updateLength + _add: function(view, customIndex){ + var viewCid = view.cid; + + // store the view + this._views[viewCid] = view; + + // index it by model + if (view.model){ + this._indexByModel[view.model.cid] = viewCid; + } + + // index by custom + if (customIndex){ + this._indexByCustom[customIndex] = viewCid; + } + + return this; + }, + // To be used when avoiding call _updateLength + // When you are done adding all your new views + // call _updateLength + _remove: function (view){ + var viewCid = view.cid; + + // delete model index + if (view.model){ + delete this._indexByModel[view.model.cid]; + } + + // delete custom index + _.some(this._indexByCustom, _.bind(function(cid, key) { + if (cid === viewCid) { + delete this._indexByCustom[key]; + return true; + } + }, this)); + + // remove the view from the container + delete this._views[viewCid]; + + return this; } });