array-keys
Advanced tools
Comparing version 2.3.0 to 2.3.1
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ArrayKeys = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
/*! | ||
* array-keys | ||
* version 2.3.0 | ||
* version 2.3.1 | ||
* http://github.com/silverbucket/array-keys | ||
@@ -115,3 +115,3 @@ * | ||
for (var n = this._store.length - 1; n >= idx; n = n - 1) { | ||
if ((this._store[i]) && (this._store[n][this._identifier] === id)) { | ||
if ((this._store[n]) && (this._store[n][this._identifier] === id)) { | ||
this._store.splice(n, 1); | ||
@@ -118,0 +118,0 @@ this._idx.splice(idx, 1); |
@@ -1,1 +0,1 @@ | ||
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.ArrayKeys=t()}}(function(){return function t(e,i,r){function n(s,f){if(!i[s]){if(!e[s]){var h="function"==typeof require&&require;if(!f&&h)return h(s,!0);if(o)return o(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var d=i[s]={exports:{}};e[s][0].call(d.exports,function(t){var i=e[s][1][t];return n(i?i:t)},d,d.exports,t,e,i,r)}return i[s].exports}for(var o="function"==typeof require&&require,s=0;s<r.length;s++)n(r[s]);return n}({1:[function(t,e,i){function r(t){"object"!=typeof t&&(t={}),this._identifier=t.identifier||"id",this._store=[],this._idx=[],t.emitEvents?(this._emitEvents=!0,this.events=new n):this._emitEvents=!1}var n=t("tiny-emitter");r.prototype.emitEvent=function(t,e,i){this._emitEvents&&!i&&this.events.emit(t,e)},r.prototype.getIdentifiers=function(){for(var t=[],e=this._store.length-1;e>=0;e-=1)t[t.length]=this._store[e][this._identifier];return t},r.prototype.getRecord=function(t){for(var e=this._store.length-1;e>=0;e-=1)if(this._store[e][this._identifier]===t)return this._store[e]},r.prototype.exists=function(t){return this.getIndex(t)>=0},r.prototype.getIndex=function(t){for(var e=this._idx.length-1;e>=0;e-=1)if(this._idx[e]===t)return e;return-1},r.prototype.addRecord=function(t){if("object"!=typeof t)throw new Error("cannot add non-object records.");if(!t[this._identifier])throw new Error("cannot add a record with no `"+this._identifier+"` property specified.");var e=this.removeRecord(t[this._identifier],!0);return this._idx[this._idx.length]=t[this._identifier],this._store[this._store.length]=t,setTimeout(function(){e?setTimeout(this.emitEvent.bind(this,"update",t),0):setTimeout(this.emitEvent.bind(this,"add",t),0)}.bind(this),0),!0},r.prototype.removeRecord=function(t,e){var i=this.getIndex(t);if(i<0)return!1;for(var r=i;r>=0;r-=1)if(this._store[r]&&this._store[r][this._identifier]===t)return this._store.splice(r,1),this._idx.splice(i,1),setTimeout(this.emitEvent.bind(this,"remove",t,e),0),!0;for(var n=this._store.length-1;n>=i;n-=1)if(this._store[r]&&this._store[n][this._identifier]===t)return this._store.splice(n,1),this._idx.splice(i,1),setTimeout(this.emitEvent.bind(this,"remove",t,e),0),!0;return!1},r.prototype.forEachRecord=function(t){var e=0,i=this,r=function(){};return setTimeout(function(){for(var n=i._store.length-1;n>=0;n-=1)e+=1,setTimeout(t.bind(null,i._store[n],n),0);setTimeout(r.bind(null,e),0)},0),{"finally":function(t){r=t}}},r.prototype.mapRecords=function(t){for(var e=0,i=this,r=[],n=i._store.length-1;n>=0;n-=1)e+=1,r.push(t(i._store[n],n));return r},r.prototype.getCount=function(){return this._store.length},r.prototype.removeAll=function(){for(var t=this._store.length-1;t>=0;t-=1)delete this._store[t];this._store=[]},e.exports=r},{"tiny-emitter":2}],2:[function(t,e,i){function r(){}r.prototype={on:function(t,e,i){var r=this.e||(this.e={});return(r[t]||(r[t]=[])).push({fn:e,ctx:i}),this},once:function(t,e,i){function r(){n.off(t,r),e.apply(i,arguments)}var n=this;return r._=e,this.on(t,r,i)},emit:function(t){var e=[].slice.call(arguments,1),i=((this.e||(this.e={}))[t]||[]).slice(),r=0,n=i.length;for(r;r<n;r++)i[r].fn.apply(i[r].ctx,e);return this},off:function(t,e){var i=this.e||(this.e={}),r=i[t],n=[];if(r&&e)for(var o=0,s=r.length;o<s;o++)r[o].fn!==e&&r[o].fn._!==e&&n.push(r[o]);return n.length?i[t]=n:delete i[t],this}},e.exports=r},{}]},{},[1])(1)}); | ||
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.ArrayKeys=t()}}(function(){return function t(e,i,r){function n(s,f){if(!i[s]){if(!e[s]){var h="function"==typeof require&&require;if(!f&&h)return h(s,!0);if(o)return o(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var d=i[s]={exports:{}};e[s][0].call(d.exports,function(t){var i=e[s][1][t];return n(i?i:t)},d,d.exports,t,e,i,r)}return i[s].exports}for(var o="function"==typeof require&&require,s=0;s<r.length;s++)n(r[s]);return n}({1:[function(t,e,i){function r(t){"object"!=typeof t&&(t={}),this._identifier=t.identifier||"id",this._store=[],this._idx=[],t.emitEvents?(this._emitEvents=!0,this.events=new n):this._emitEvents=!1}var n=t("tiny-emitter");r.prototype.emitEvent=function(t,e,i){this._emitEvents&&!i&&this.events.emit(t,e)},r.prototype.getIdentifiers=function(){for(var t=[],e=this._store.length-1;e>=0;e-=1)t[t.length]=this._store[e][this._identifier];return t},r.prototype.getRecord=function(t){for(var e=this._store.length-1;e>=0;e-=1)if(this._store[e][this._identifier]===t)return this._store[e]},r.prototype.exists=function(t){return this.getIndex(t)>=0},r.prototype.getIndex=function(t){for(var e=this._idx.length-1;e>=0;e-=1)if(this._idx[e]===t)return e;return-1},r.prototype.addRecord=function(t){if("object"!=typeof t)throw new Error("cannot add non-object records.");if(!t[this._identifier])throw new Error("cannot add a record with no `"+this._identifier+"` property specified.");var e=this.removeRecord(t[this._identifier],!0);return this._idx[this._idx.length]=t[this._identifier],this._store[this._store.length]=t,setTimeout(function(){e?setTimeout(this.emitEvent.bind(this,"update",t),0):setTimeout(this.emitEvent.bind(this,"add",t),0)}.bind(this),0),!0},r.prototype.removeRecord=function(t,e){var i=this.getIndex(t);if(i<0)return!1;for(var r=i;r>=0;r-=1)if(this._store[r]&&this._store[r][this._identifier]===t)return this._store.splice(r,1),this._idx.splice(i,1),setTimeout(this.emitEvent.bind(this,"remove",t,e),0),!0;for(var n=this._store.length-1;n>=i;n-=1)if(this._store[n]&&this._store[n][this._identifier]===t)return this._store.splice(n,1),this._idx.splice(i,1),setTimeout(this.emitEvent.bind(this,"remove",t,e),0),!0;return!1},r.prototype.forEachRecord=function(t){var e=0,i=this,r=function(){};return setTimeout(function(){for(var n=i._store.length-1;n>=0;n-=1)e+=1,setTimeout(t.bind(null,i._store[n],n),0);setTimeout(r.bind(null,e),0)},0),{finally:function(t){r=t}}},r.prototype.mapRecords=function(t){for(var e=0,i=this,r=[],n=i._store.length-1;n>=0;n-=1)e+=1,r.push(t(i._store[n],n));return r},r.prototype.getCount=function(){return this._store.length},r.prototype.removeAll=function(){for(var t=this._store.length-1;t>=0;t-=1)delete this._store[t];this._store=[]},e.exports=r},{"tiny-emitter":2}],2:[function(t,e,i){function r(){}r.prototype={on:function(t,e,i){var r=this.e||(this.e={});return(r[t]||(r[t]=[])).push({fn:e,ctx:i}),this},once:function(t,e,i){function r(){n.off(t,r),e.apply(i,arguments)}var n=this;return r._=e,this.on(t,r,i)},emit:function(t){var e=[].slice.call(arguments,1),i=((this.e||(this.e={}))[t]||[]).slice(),r=0,n=i.length;for(r;r<n;r++)i[r].fn.apply(i[r].ctx,e);return this},off:function(t,e){var i=this.e||(this.e={}),r=i[t],n=[];if(r&&e)for(var o=0,s=r.length;o<s;o++)r[o].fn!==e&&r[o].fn._!==e&&n.push(r[o]);return n.length?i[t]=n:delete i[t],this}},e.exports=r},{}]},{},[1])(1)}); |
/*! | ||
* array-keys | ||
* version 2.3.0 | ||
* version 2.3.1 | ||
* http://github.com/silverbucket/array-keys | ||
@@ -114,3 +114,3 @@ * | ||
for (var n = this._store.length - 1; n >= idx; n = n - 1) { | ||
if ((this._store[i]) && (this._store[n][this._identifier] === id)) { | ||
if ((this._store[n]) && (this._store[n][this._identifier] === id)) { | ||
this._store.splice(n, 1); | ||
@@ -117,0 +117,0 @@ this._idx.splice(idx, 1); |
{ | ||
"name": "array-keys", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "a simple interface to manage large arrays of objects easily", | ||
@@ -19,7 +19,7 @@ "license": "MIT", | ||
"devDependencies": { | ||
"browserify": "^10.2.4", | ||
"browserify": "^13.3.0", | ||
"gulp": "^3.9.1", | ||
"gulp-rename": "^1.2.0", | ||
"gulp-streamify": "0.0.5", | ||
"gulp-uglify": "^1.5.4", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-streamify": "^1.0.2", | ||
"gulp-uglify": "^2.0.0", | ||
"jaribu": "^2.2.1", | ||
@@ -26,0 +26,0 @@ "vinyl-source-stream": "^1.1.0" |
@@ -59,4 +59,7 @@ function getTests() { | ||
{ | ||
desc: "# removeRecord 1", | ||
desc: '# INDEX BUG', | ||
run: function (env, test) { | ||
test.assertAnd(env.mod.addRecord({id:'thingy1'}), true); | ||
test.assertAnd(env.mod.addRecord({id:'thingy2'}), true); | ||
env.mod._store.reverse(); | ||
env.mod.events.once('remove', function addHandler(d) { | ||
@@ -70,2 +73,13 @@ test.assert('thingy1', d); | ||
{ | ||
desc: "# removeRecord 2", | ||
run: function (env, test) { | ||
env.mod.events.once('remove', function addHandler(d) { | ||
test.assert('thingy2', d); | ||
}); | ||
test.assertAnd(env.mod.removeRecord('thingy2'), true); | ||
} | ||
}, | ||
{ | ||
desc: '# addRecord 1', | ||
@@ -271,2 +285,3 @@ run: function (env, test) { | ||
desc: "basic tests", | ||
abortOnFail: true, | ||
setup: function (env, test) { | ||
@@ -282,2 +297,3 @@ var Mod = require('./../index'); | ||
desc: "basic tests (browserify)", | ||
abortOnFail: true, | ||
setup: function (env, test) { | ||
@@ -293,2 +309,3 @@ var Mod = require('./../browser/array-keys.js'); | ||
desc: "basic tests (browserify minified)", | ||
abortOnFail: true, | ||
setup: function (env, test) { | ||
@@ -295,0 +312,0 @@ var Mod = require('./../browser/array-keys.min.js'); |
31444
685