collectionize
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -73,3 +73,3 @@ (function () { | ||
self.name = name; // Used for localStorage property naming. | ||
self.idIndex = []; | ||
self.idIndex = {}; | ||
@@ -173,8 +173,25 @@ nativeEach(LODASH_METHODS, function (methodName) { | ||
} | ||
_addToIndex(obj); | ||
self.trigger('updated', match); | ||
} | ||
function _addToIndex(obj) { | ||
if (obj && obj.id) { | ||
self.idIndex[obj.id + ''] = obj; | ||
} | ||
self.trigger('updated', match); | ||
} | ||
function _removeFromIndex(obj) { | ||
if (obj && obj.id) { | ||
self.idIndex[obj.id + ''] = null; | ||
} | ||
} | ||
function _resetIndex() { | ||
self.idIndex = {}; | ||
self.each(function (obj) { | ||
_addToIndex(obj); | ||
}); | ||
} | ||
self.getById = function (id) { | ||
@@ -200,5 +217,3 @@ return self.idIndex[id + '']; | ||
nativeEach(removed, function (obj) { | ||
if (obj && obj.id) { | ||
self.idIndex[obj.id + ''] = null; | ||
} | ||
_removeFromIndex(obj); | ||
self.trigger('removed', obj); | ||
@@ -211,3 +226,3 @@ }); | ||
self.db = db || []; | ||
self.idIndex = []; | ||
_resetIndex(); | ||
self.trigger('flushed'); | ||
@@ -214,0 +229,0 @@ }; |
{ | ||
"name": "collectionize", | ||
"description": "A lightweight JS model/collection library.", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"repository": "https://github.com/andrewchilds/collectionize.git", | ||
@@ -6,0 +6,0 @@ "author": { |
19358
261
9