-
Notifications
You must be signed in to change notification settings - Fork 21
/
ngCrossfilter.js
1205 lines (908 loc) · 36.4 KB
/
ngCrossfilter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @module ngCrossfilter
* @author Adam Timberlake
* @link https://github.com/Wildhoney/ngCrossfilter
*
* @param $angular Angular.js https://angularjs.org/ (Required)
* @param $crossfilter https://github.com/square/crossfilter (Required)
* @param $moment http://momentjs.com/
* @param _ http://underscorejs.org/
*/
(function ngCrossfilterBootstrap($angular, $crossfilter, $moment, _) {
"use strict";
/**
* @method _throwException
* @param message {String}
* @return {void}
* @private
*/
var _throwException = function _throwException(message) {
throw "ngCrossfilter: " + message + ".";
};
if (typeof $angular === 'undefined') {
// Add a check for Angular.
_throwException("ngCrossfilter Requires Angular.js");
}
if (typeof $crossfilter === 'undefined') {
// Add a check for Crossfilter.
_throwException("ngCrossfilter Requires Crossfilter");
}
/**
* Whether underscore is available or not
*
* @type {Boolean}
*/
var HAS_UNDERSCORE = (typeof _ !== 'undefined');
/**
* @method isArray
* @return {Boolean}
* @private
*/
var isArray = function isArray(item) {
if (typeof Array.isArray === 'function') {
return Array.isArray(item);
}
if (typeof _ !== 'undefined') {
return _.isArray(item);
}
/* jshint -W122 */
return (typeof item === '[object Array]');
}
/**
* List of common filters bundled into ngCrossfilter.
*
* @type {Object}
*/
var filters = {
/**
* @constant HAS_UNDERSCORE
* @type {Boolean}
* @deprecated
*/
HAS_UNDERSCORE: HAS_UNDERSCORE,
/**
* @method fuzzy
* @param flags {String}
* @return {Function}
*/
fuzzy: function fuzzyFilter(flags) {
/**
* @method fuzzy
* @param expected {String}
* @param actual {String}
* @return {Boolean}
*/
return function fuzzy(expected, actual) {
var regExp = new RegExp(expected, flags);
return !!actual.match(regExp);
};
},
/**
* @method dateTimeRange
* @param format {String}
* @param comparatorFunction {Function}
* @return {Function}
*/
dateTimeRange: function dateTimeRangeFilter(format, comparatorFunction) {
if (typeof $moment === 'undefined') {
// Ensure we have the Moment.js library installed.
_throwException("You need to install Moment.js to use dateTimeRange");
}
/**
* @method fuzzy
* @param expected {String}
* @param actual {String}
* @return {Boolean}
*/
return function dateTimeRange(expected, actual) {
// Convert each date/time into a Unix timestamp.
var start = (expected[0] === -Infinity) ? 0 : $moment(expected[0], format).unix(),
end = (expected[1] === Infinity) ? Infinity : $moment(expected[1], format).unix(),
current = $moment(actual, format).unix();
if (start < 0 || end < 0 || current < 0) {
// Ensure we're not dealing with overtly incorrect dates/times.
_throwException("Date/Time parsing appears to be using invalid format");
}
if (typeof comparatorFunction === 'function') {
// Use the user specified comparator function if it has been defined.
return comparatorFunction(current, start, end);
}
return (current >= start && current <= end);
}
},
/**
* @method regexp
* @return {Function}
*/
regexp: function regexpFilter() {
/**
* @method regexp
* @param expected {String}
* @param actual {String}
* @return {Boolean}
*/
return function regexp(expected, actual) {
if (!(expected instanceof RegExp)) {
_throwException("Expression must be an instance of RegExp");
}
return !!actual.match(expected);
}
},
/**
* @method bitwise
* @param flag {String}
* @return {Function}
*/
bitwise: function bitwiseFilter(flag) {
/**
* @method bitwise
* @param expected {Number}
* @param actual {Number}
* @return {Boolean}
*/
return function bitwise(expected, actual) {
var result = (expected & actual);
return (flag === '!') ? !result : result;
}
},
/**
* @method inArray
* @param method {String}
* @return {Function}
*/
inArray: function inArray(method) {
return this._inArray(method, false);
},
/**
* @method notInArray
* @param method {String}
* @return {Function}
*/
notInArray: function notInArray(method) {
return this._inArray(method, true);
},
/**
* @method _inArray
* @param method {String}
* @param invertInArray {Boolean}
* @return {Function}
* @private
*/
_inArray: function inArrayFilter(method, invertInArray) {
var hasUnderscore = HAS_UNDERSCORE;
/**
* @method inArray
* @param expected {String|Number|Array}
* @param actual {Array}
* @return {Boolean}
*/
return function inArray(expected, actual) {
if (!isArray(actual)) {
// Convert the expected into an array if it isn't already.
actual = [actual];
}
if (!isArray(expected)) {
// Convert the expected into an array if it isn't already.
expected = [expected];
}
// Assign a default if none specified.
method = method || 'every';
if (method && ['every', 'some'].indexOf(method) === -1) {
_throwException("You must pass either 'every' or 'some'");
}
if (!hasUnderscore && (typeof [].every !== 'function' || typeof [].some !== 'function')) {
_throwException("Browser does not support `every` and/or `some` methods");
}
/**
* @method everySome
* @param property {String|Number|Boolean}
* @return {Boolean}
*/
var everySome = function everySome(property) {
var result = (actual.indexOf(property) !== -1);
return (invertInArray) ? !result : result;
};
// Use Underscore if available, otherwise native.
return hasUnderscore ? _[method](expected, everySome) : expected[method](everySome);
}
}
};
/**
* @module ngCrossfilter
* @author Adam Timberlake
* @link https://github.com/Wildhoney/ngCrossfilter
*/
var ngCrossfilter = $angular.module('ngCrossfilter', []);
/**
* @module ngCrossfilter
* @submodule CrossfilterService
*/
ngCrossfilter.service('Crossfilter', ['$rootScope',
/*jshint maxstatements: 60 */
function CrossfilterService($rootScope) {
/**
* @module ngCrossfilter
* @submodule ngCrossfilterService
* @constructor
*/
var Service = function ngCrossfilterService(collection, primaryKey, strategy, properties) {
collection = collection || [];
// Reset all of the arrays and objects.
this._resetAll();
// Initialise the Crossfilter with the array of models.
this._initialise(collection, primaryKey, strategy, properties);
};
Service.filters = filters;
// Store a reference to the prototype.
Service.prototype = [];
/**
* @constant STRATEGY_PERSISTENT
* @type {String}
*/
Service.prototype.STRATEGY_PERSISTENT = 'persistent';
/**
* @constant STRATEGY_TRANSIENT
* @type {String}
*/
Service.prototype.STRATEGY_TRANSIENT = 'transient';
/**
* @constant PRIMARY_DIMENSION
* @type {String}
*/
Service.prototype.PRIMARY_DIMENSION = '__primaryKey';
/**
* @constant PRIMARY_SPECIAL
* @type {String}
*/
Service.prototype.PRIMARY_SPECIAL = '$id';
/**
* @constant HAS_UNDERSCORE
* @type {Boolean}
* @deprecated
*/
Service.prototype.HAS_UNDERSCORE = HAS_UNDERSCORE;
/**
* @property _crossfilter
* @type {crossfilter}
* @private
*/
Service.prototype._crossfilter = {};
/**
* @property _cacheGroups
* @type {Object}
*/
Service.prototype._cacheGroups = {};
/**
* @property _specialId
* @type {Number}
* @private
*/
Service.prototype._specialId = 1;
/**
* @property _dimensions
* @type {Object}
* @private
*/
Service.prototype._dimensions = {};
/**
* @property _primaryKey
* @type {String}
* @private
*/
Service.prototype._primaryKey = '';
/**
* @property _sortProperty
* @type {String}
* @private
*/
Service.prototype._sortProperty = '';
/**
* @property _isAscending
* @type {Boolean}
* @default true
* @private
*/
Service.prototype._isAscending = true;
/**
* @property _lastFilter
* @type {String}
* @private
*/
Service.prototype._lastFilter = '';
/**
* @property strategy
* @type {String}
* @private
*/
Service.prototype._strategy = '';
/**
* @property _deletedKeys
* @type {Array}
* @private
*/
Service.prototype._deletedKeys = [];
/**
* @property _identifier
* @type {String}
* @private
*/
Service.prototype._identifier = '';
/**
* @property _isBroadcastEventEnabled
* @type {Boolean}
* @default true
* @private
*/
Service.prototype._isBroadcastEventEnabled = true;
/**
* @property filters
* @type {Object}
* @deprecated
*/
Service.prototype.filters = filters;
/**
* @method _isArray
* @return {Boolean}
* @private
* @deprecated
*/
Service.prototype._isArray = isArray;
/**
* @method _initialise
* @param collection {Array}
* @param primaryKey {String}
* @param strategy {String} Either "persistent" or "transient"
* @param properties {Array} List of properties for the dimensions
* @return {void}
* @private
*/
Service.prototype._initialise = function _initialise(collection, primaryKey, strategy, properties) {
if (!isArray(collection)) {
// Determine if the collection is a valid array.
_throwException("Collection must be an array");
}
// Assume a default strategy if one hasn't been defined.
strategy = strategy || this.STRATEGY_PERSISTENT;
if ([this.STRATEGY_PERSISTENT, this.STRATEGY_TRANSIENT].indexOf(strategy) === -1) {
// Determine if the strategy has been defined as either persistent or transient.
_throwException("Strategy must be either '" +
this.STRATEGY_PERSISTENT + "' or '" +
this.STRATEGY_TRANSIENT + "'");
}
if (primaryKey && properties && (properties.indexOf(primaryKey) === -1)) {
// Ensure the primary key has been defined as a dimension.
_throwException("Primary key '" + primaryKey + "' as one of the dimensions");
}
if (collection[0]) {
// Determine if the primary key is missing from the model.
var missingProperty = !(primaryKey in collection[0]);
if (collection.length && (primaryKey && missingProperty && primaryKey !== this.PRIMARY_SPECIAL)) {
// Ensure the specified primary key is in the collection.
_throwException("Primary key '" + primaryKey + "' is not in the collection");
}
}
if (primaryKey === this.PRIMARY_SPECIAL) {
// If we're using the special primary key then it needs to be injected into each model.
$angular.forEach(collection, function forEach(model) {
model[this.PRIMARY_SPECIAL] = ++this._specialId;
}.bind(this));
}
// Discover the unique properties in the collection.
properties = properties || this._getProperties(collection[0]);
// Initialise the Crossfilter collection, and either use the defined primary key, or infer
// it from the properties.
this._crossfilter = $crossfilter(collection);
this._strategy = strategy;
this._primaryKey = (primaryKey || properties[0]) || '';
// Define the dimensions from the properties.
this._defineDimensions(properties);
if (this._primaryKey) {
// Define the primary key.
this.primaryKey(this._primaryKey);
}
this.broadcastEvent();
};
/**
* @method _defineDimensions
* @param properties {Array}
* @return {void}
* @private
*/
Service.prototype._defineDimensions = function _defineDimensions(properties) {
$angular.forEach(properties, function(property) {
// Iterate over each property to create its related dimension.
this.addDimension(property, null, true);
}.bind(this));
};
/**
* @method primaryKey
* @param property {String}
* @return {void}
*/
Service.prototype.primaryKey = function primaryKey(property) {
this._primaryKey = property;
// Add a special dimension for removing models.
this.addDimension(this.PRIMARY_DIMENSION, function(model) {
return model[property];
}.bind(this), true);
};
/**
* @method filterBy
* @param property {String}
* @param expected {String}
* @param customFilter {Function}
* @return {void}
*/
Service.prototype.filterBy = function filterBy(property, expected, customFilter) {
// Invalidate the groups cache.
this._cacheGroups = {};
this._assertDimensionExists(property);
if (typeof customFilter !== 'undefined' && typeof customFilter !== 'function') {
// Ensure the third argument is a function, if it has been defined.
throw _throwException("Custom filter method must be a function");
}
if (this._lastFilter && this._strategy === this.STRATEGY_TRANSIENT) {
// Clear the previous filter if we're using the transient strategy.
this.unfilterBy(this._lastFilter);
}
// Store the last filter property to allowing filtering transiently.
this._lastFilter = property;
if (typeof customFilter === 'function') {
// Filter using the developer's custom function if it's been defined.
this._dimensions[property].filterFunction(function customFilterFunction(actual) {
return customFilter(expected, actual);
});
this.broadcastEvent();
return;
}
// Let's filter by the desired filter!
this._dimensions[property].filter(expected);
this.broadcastEvent();
};
/**
* @method unfilterBy
* @param property {String}
* @return {void}
*/
Service.prototype.unfilterBy = function unfilterBy(property) {
// Invalidate the groups cache.
this._cacheGroups = {};
this._assertDimensionExists(property);
this._dimensions[property].filterAll();
this.broadcastEvent();
};
/**
* @method unfilterAll
* @return {void}
*/
Service.prototype.unfilterAll = function unfilterAll() {
// Invalidate the groups cache.
this._cacheGroups = {};
// Clear all of the dimensions that we have.
for (var key in this._dimensions) {
// Usual suspect!
if (this._dimensions.hasOwnProperty(key)) {
this._dimensions[key].filterAll();
}
}
this._finaliseDeleteRestore();
this.broadcastEvent();
};
/**
* @method sortBy
* @param property {String}
* @param isAscending {Boolean}
* @return {void}
*/
Service.prototype.sortBy = function sortBy(property, isAscending) {
this._assertDimensionExists(property);
if (typeof isAscending === 'boolean') {
// Use the sorting specified by the developer.
this._isAscending = isAscending;
this._sortProperty = property;
return;
}
// Use the primary key if the current sort property hasn't been set yet.
var currentSortProperty = this._sortProperty || this._primaryKey;
// Determine if we should invert what we currently have if we're using the same property
// as previously.
if (currentSortProperty === property) {
this._isAscending = !this._isAscending;
}
// Otherwise we'll simply update the sort property.
this._sortProperty = property;
this.broadcastEvent();
};
/**
* @method unsortAll
* @param maintainSortOrder {Boolean}
* @return {void}
*/
Service.prototype.unsortAll = function unsortAll(maintainSortOrder) {
// Sort by the default property, which is the primary key.
this._sortProperty = this._primaryKey;
if (maintainSortOrder !== true) {
// Reset the sort order unless otherwise instructed.
this._isAscending = true;
}
this.broadcastEvent();
};
/**
* @method addDimension
* @param name {String}
* @param setupFunction {Function}
* @param ignoreAssertion {Boolean}
* @return {void}
*/
Service.prototype.addDimension = function addDimension(name, setupFunction, ignoreAssertion) {
// Assume a default setup method if none has been specified.
setupFunction = setupFunction || function dimensionSetup(model) {
return model[name];
};
if (!ignoreAssertion) {
this._assertValidDimensionName(name);
}
this._dimensions[name] = this._crossfilter.dimension(setupFunction);
};
/**
* @method deleteDimension
* @param name {String}
* @return {void}
*/
Service.prototype.deleteDimension = function deleteDimension(name) {
this._assertDimensionExists(name);
this._dimensions[name].dispose();
delete this._dimensions[name];
};
/**
* @method first
* @return {Object}
*/
Service.prototype.first = function first() {
return this.collection()[0];
};
/**
* @method last
* @return {Object}
*/
Service.prototype.last = function last() {
return this.collection()[this.collection().length - 1];
};
/**
* @method countBy
* @param property {String}
* @param value {String}
* @return {Number}
*/
Service.prototype.countBy = function countBy(property, value) {
if (this._cacheGroups[property]) {
// Firstly we need to attempt to return the cached version.
return this._cacheGroups[property][value] || 0;
}
this._assertDimensionExists(property);
var groups = {};
// Use reduce method to return the count for the dimension.
var sums = this._dimensions[property].group().all();
// Iterate over each sum model to package it nicely.
for (var key in sums) {
// Usual suspect!
if (sums.hasOwnProperty(key)) {
var model = sums[key];
groups[model.key] = model.value;
}
}
// Store the cache for the next time, until it's invalidated.
this._cacheGroups[property] = groups;
return groups[value] || 0;
};
/**
* @method groupBy
* @param property {String}
* @param reduceFunctions {Object}
* @return {Array}
*/
Service.prototype.groupBy = function groupBy(property,reduceFunctions) {
this._assertDimensionExists(property);
if (typeof reduceFunctions === 'undefined') {
return this._dimensions[property].group(function group(property) {
return property;
}).all();
}
if( typeof reduceFunctions !== 'object' ){
_throwException("Custom reducer must be an object");
}
var add = reduceFunctions.add || function(p) {
return p+1;
}
var remove = reduceFunctions.remove || function(p){
return p-1;
}
var initial = reduceFunctions.initial || function(){
return 0;
}
if(typeof add !== 'function' || typeof remove !== 'function' || typeof initial !== 'function'){
_throwException("Custom reducer's `add`, `remove`, and `initial` properties must be functions")
}
return this._dimensions[property].group(function group(property) {
return property;
}).reduce(add, remove, initial)
.all();
};
/**
* @method models
* @param offset {Number}
* @param length {Number}
* @return {Array}
*/
Service.prototype.models = function models(offset, length) {
var slice = this.collection(typeof length === 'number' ? length : Infinity);
return slice.splice(typeof offset === 'number' ? offset : Infinity);
};
/**
* @method addModel
* @param model {Object}
* @return {Number}
*/
Service.prototype.addModel = function addModel(model) {
return this.addModels([model]);
};
/**
* @method addModels
* @param models {Array}
* @return {Number}
*/
Service.prototype.addModels = function addModels(models) {
// Invalidate the groups cache.
this._cacheGroups = {};
if (!this._primaryKey) {
// Determine whether to use Underscore or attempt to use the browser
// native method.
var keys = this.HAS_UNDERSCORE ? _.keys : Object.keys;
// Define the primary key if one hasn't been defined yet.
this.primaryKey(keys(models[0])[0]);
// Determine if the developer has defined any dimensions yet.
var definedDimensions = true;
for (var dimension in this._dimensions) {
if (this._dimensions.hasOwnProperty(dimension)) {
definedDimensions = false;
}
}
if (!definedDimensions) {
// Define the dimensions using the model we're adding if the developer hasn't yet
// defined any dimensions.
this._defineDimensions(this._getProperties(models[0]));
}
}
if (this._primaryKey === this.PRIMARY_SPECIAL) {
// We need to add the special property into the model if we're using the special PK.
$angular.forEach(models, function forEach(model) {
model[this.PRIMARY_SPECIAL] = ++this._specialId;
}.bind(this));
}
this._crossfilter.add(models);
this.broadcastEvent();
return models.length;
};
/**
* @method updateModel
* @return {void}
*/
Service.prototype.updateModel = function updateModel(model, properties) {
if (!model.hasOwnProperty(this.PRIMARY_SPECIAL)) {
// Method only works with the special dimension "$id".
_throwException("`updateModel` only works when PK is defined as `" + this.PRIMARY_SPECIAL + "`");
}
// Remove the model for it to be re-added.
this.deleteModel(model);
// Create a new model based on the existing model and the desired update.
for (var property in properties) {
if (properties.hasOwnProperty(property)) {
// Update model!
model[property] = properties[property];
}
}
// ...And now we can add the model to the Crossfilter collection after updating its special ID.
model[this.PRIMARY_SPECIAL] = ++this._specialId;
this.addModel(model);
this.broadcastEvent();
};
/**
* @property deleteModel
* @param model {Object}
* @return {Number}
*/
Service.prototype.deleteModel = function deleteModel(model) {
return this.deleteModels([model]);
};
/**
* @property deleteModels
* @param models {Array}
* @return {Number}
*/
Service.prototype.deleteModels = function deleteModels(models) {
// Invalidate the groups cache.
this._cacheGroups = {};
var currentKeys = this._getKeys(models);
// Store each deleted key.
for (var index = 0; index < currentKeys.length; index++) {
if (index === this.PRIMARY_DIMENSION) {
// Ignore the primary dimension.
continue;
}
this._deletedKeys.push(currentKeys[index]);
}
this._finaliseDeleteRestore();
this.broadcastEvent();
return currentKeys.length;
};
/**
* @property restoreModel
* @param model {Object}
* @return {Number}
*/
Service.prototype.restoreModel = function restoreModel(model) {
return this.restoreModels([model]);
};
/**
* @property restoreModels
* @param models {Array}
* @return {Number}
*/
Service.prototype.restoreModels = function restoreModels(models) {
var currentKeys = this._getKeys(models);
// Store each deleted key.
for (var index = 0; index < currentKeys.length; index++) {
var modelIndex = this._deletedKeys.indexOf(currentKeys[index]);