-
Notifications
You must be signed in to change notification settings - Fork 618
/
Copy pathangular-meteor.js
2543 lines (1953 loc) · 83.9 KB
/
angular-meteor.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
/*! angular-meteor v1.3.12 */
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("underscore"), require("jsondiffpatch"));
else if(typeof define === 'function' && define.amd)
define(["underscore", "jsondiffpatch"], factory);
else if(typeof exports === 'object')
exports["angularMeteor"] = factory(require("underscore"), require("jsondiffpatch"));
else
root["angularMeteor"] = factory(root["_"], root["jsondiffpatch"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_22__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
__webpack_require__(1);
__webpack_require__(4);
__webpack_require__(5);
__webpack_require__(6);
__webpack_require__(7);
__webpack_require__(8);
__webpack_require__(9);
__webpack_require__(10);
__webpack_require__(11);
__webpack_require__(12);
__webpack_require__(13);
__webpack_require__(14);
__webpack_require__(15);
var _utils = __webpack_require__(16);
var _mixer = __webpack_require__(17);
var _scope = __webpack_require__(18);
var _core = __webpack_require__(19);
var _viewModel = __webpack_require__(20);
var _reactive = __webpack_require__(21);
var _templates = __webpack_require__(23);
// legacy
// lib
var name = 'angular-meteor';
// new
exports.default = name;
angular.module(name, [
// new
_utils.name, _mixer.name, _scope.name, _core.name, _viewModel.name, _reactive.name, _templates.name,
// legacy
'angular-meteor.ironrouter', 'angular-meteor.utils', 'angular-meteor.subscribe', 'angular-meteor.collection', 'angular-meteor.object', 'angular-meteor.user', 'angular-meteor.methods', 'angular-meteor.session', 'angular-meteor.camera']).run([_mixer.Mixer, _core.Core, _viewModel.ViewModel, _reactive.Reactive, function ($Mixer, $$Core, $$ViewModel, $$Reactive) {
// Load all mixins
$Mixer.mixin($$Core).mixin($$ViewModel).mixin($$Reactive);
}])
// legacy
// Putting all services under $meteor service for syntactic sugar
.service('$meteor', ['$meteorCollection', '$meteorCollectionFS', '$meteorObject', '$meteorMethods', '$meteorSession', '$meteorSubscribe', '$meteorUtils', '$meteorCamera', '$meteorUser', function ($meteorCollection, $meteorCollectionFS, $meteorObject, $meteorMethods, $meteorSession, $meteorSubscribe, $meteorUtils, $meteorCamera, $meteorUser) {
var _this = this;
this.collection = $meteorCollection;
this.collectionFS = $meteorCollectionFS;
this.object = $meteorObject;
this.subscribe = $meteorSubscribe.subscribe;
this.call = $meteorMethods.call;
this.session = $meteorSession;
this.autorun = $meteorUtils.autorun;
this.getCollectionByName = $meteorUtils.getCollectionByName;
this.getPicture = $meteorCamera.getPicture;
// $meteorUser
['loginWithPassword', 'requireUser', 'requireValidUser', 'waitForUser', 'createUser', 'changePassword', 'forgotPassword', 'resetPassword', 'verifyEmail', 'loginWithMeteorDeveloperAccount', 'loginWithFacebook', 'loginWithGithub', 'loginWithGoogle', 'loginWithMeetup', 'loginWithTwitter', 'loginWithWeibo', 'logout', 'logoutOtherClients'].forEach(function (method) {
_this[method] = $meteorUser[method];
});
}]);
module.exports = exports['default'];
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
var _underscore = __webpack_require__(2);
var _underscore2 = _interopRequireDefault(_underscore);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
'use strict';
// https://github.com/DAB0mB/get-updates
/*global
angular, _
*/
(function () {
var module = angular.module('getUpdates', []);
var utils = function () {
var rip = function rip(obj, level) {
if (level < 1) return {};
return _underscore2.default.reduce(obj, function (clone, v, k) {
v = _underscore2.default.isObject(v) ? rip(v, --level) : v;
clone[k] = v;
return clone;
}, {});
};
var toPaths = function toPaths(obj) {
var keys = getKeyPaths(obj);
var values = getDeepValues(obj);
return _underscore2.default.object(keys, values);
};
var getKeyPaths = function getKeyPaths(obj) {
var keys = _underscore2.default.keys(obj).map(function (k) {
var v = obj[k];
if (!_underscore2.default.isObject(v) || _underscore2.default.isEmpty(v) || _underscore2.default.isArray(v)) return k;
return getKeyPaths(v).map(function (subKey) {
return k + '.' + subKey;
});
});
return _underscore2.default.flatten(keys);
};
var getDeepValues = function getDeepValues(obj, arr) {
arr = arr || [];
_underscore2.default.values(obj).forEach(function (v) {
if (!_underscore2.default.isObject(v) || _underscore2.default.isEmpty(v) || _underscore2.default.isArray(v)) arr.push(v);else getDeepValues(v, arr);
});
return arr;
};
var flatten = function flatten(arr) {
return arr.reduce(function (flattened, v, i) {
if (_underscore2.default.isArray(v) && !_underscore2.default.isEmpty(v)) flattened.push.apply(flattened, flatten(v));else flattened.push(v);
return flattened;
}, []);
};
var setFilled = function setFilled(obj, k, v) {
if (!_underscore2.default.isEmpty(v)) obj[k] = v;
};
var assert = function assert(result, msg) {
if (!result) throwErr(msg);
};
var throwErr = function throwErr(msg) {
throw Error('get-updates error - ' + msg);
};
return {
rip: rip,
toPaths: toPaths,
getKeyPaths: getKeyPaths,
getDeepValues: getDeepValues,
setFilled: setFilled,
assert: assert,
throwErr: throwErr
};
}();
var getDifference = function () {
var getDifference = function getDifference(src, dst, isShallow) {
var level;
if (isShallow > 1) level = isShallow;else if (isShallow) level = 1;
if (level) {
src = utils.rip(src, level);
dst = utils.rip(dst, level);
}
return compare(src, dst);
};
var compare = function compare(src, dst) {
var srcKeys = _underscore2.default.keys(src);
var dstKeys = _underscore2.default.keys(dst);
var keys = _underscore2.default.chain([]).concat(srcKeys).concat(dstKeys).uniq().without('$$hashKey').value();
return keys.reduce(function (diff, k) {
var srcValue = src[k];
var dstValue = dst[k];
if (_underscore2.default.isDate(srcValue) && _underscore2.default.isDate(dstValue)) {
if (srcValue.getTime() != dstValue.getTime()) diff[k] = dstValue;
}
if (_underscore2.default.isObject(srcValue) && _underscore2.default.isObject(dstValue)) {
var valueDiff = getDifference(srcValue, dstValue);
utils.setFilled(diff, k, valueDiff);
} else if (srcValue !== dstValue) {
diff[k] = dstValue;
}
return diff;
}, {});
};
return getDifference;
}();
var getUpdates = function () {
var getUpdates = function getUpdates(src, dst, isShallow) {
utils.assert(_underscore2.default.isObject(src), 'first argument must be an object');
utils.assert(_underscore2.default.isObject(dst), 'second argument must be an object');
var diff = getDifference(src, dst, isShallow);
var paths = utils.toPaths(diff);
var set = createSet(paths);
var unset = createUnset(paths);
var pull = createPull(unset);
var updates = {};
utils.setFilled(updates, '$set', set);
utils.setFilled(updates, '$unset', unset);
utils.setFilled(updates, '$pull', pull);
return updates;
};
var createSet = function createSet(paths) {
var undefinedKeys = getUndefinedKeys(paths);
return _underscore2.default.omit(paths, undefinedKeys);
};
var createUnset = function createUnset(paths) {
var undefinedKeys = getUndefinedKeys(paths);
var unset = _underscore2.default.pick(paths, undefinedKeys);
return _underscore2.default.reduce(unset, function (result, v, k) {
result[k] = true;
return result;
}, {});
};
var createPull = function createPull(unset) {
var arrKeyPaths = _underscore2.default.keys(unset).map(function (k) {
var split = k.match(/(.*)\.\d+$/);
return split && split[1];
});
return _underscore2.default.compact(arrKeyPaths).reduce(function (pull, k) {
pull[k] = null;
return pull;
}, {});
};
var getUndefinedKeys = function getUndefinedKeys(obj) {
return _underscore2.default.keys(obj).filter(function (k) {
var v = obj[k];
return _underscore2.default.isUndefined(v);
});
};
return getUpdates;
}();
module.value('getUpdates', getUpdates);
})();
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _underscore = __webpack_require__(3);
var _underscore2 = _interopRequireDefault(_underscore);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
if (typeof _underscore2.default === 'undefined') {
if (typeof Package.underscore === 'undefined') {
throw new Error('underscore is missing');
}
}
exports.default = _underscore2.default || Package.underscore._;
module.exports = exports['default'];
/***/ }),
/* 3 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_3__;
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
var _underscore = __webpack_require__(2);
var _underscore2 = _interopRequireDefault(_underscore);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
'use strict'; /*global
angular, _, Package
*/
var _module = angular.module('diffArray', ['getUpdates']);
_module.factory('diffArray', ['getUpdates', function (getUpdates) {
var LocalCollection = Package.minimongo.LocalCollection;
var idStringify = LocalCollection._idStringify || Package['mongo-id'].MongoID.idStringify;
var idParse = LocalCollection._idParse || Package['mongo-id'].MongoID.idParse;
// Calculates the differences between `lastSeqArray` and
// `seqArray` and calls appropriate functions from `callbacks`.
// Reuses Minimongo's diff algorithm implementation.
// XXX Should be replaced with the original diffArray function here:
// https://github.com/meteor/meteor/blob/devel/packages/observe-sequence/observe_sequence.js#L152
// When it will become nested as well, tracking here: https://github.com/meteor/meteor/issues/3764
function diffArray(lastSeqArray, seqArray, callbacks, preventNestedDiff) {
preventNestedDiff = !!preventNestedDiff;
var diffFn = Package.minimongo.LocalCollection._diffQueryOrderedChanges || Package['diff-sequence'].DiffSequence.diffQueryOrderedChanges;
var oldObjIds = [];
var newObjIds = [];
var posOld = {}; // maps from idStringify'd ids
var posNew = {}; // ditto
var posCur = {};
var lengthCur = lastSeqArray.length;
_underscore2.default.each(seqArray, function (doc, i) {
newObjIds.push({ _id: doc._id });
posNew[idStringify(doc._id)] = i;
});
_underscore2.default.each(lastSeqArray, function (doc, i) {
oldObjIds.push({ _id: doc._id });
posOld[idStringify(doc._id)] = i;
posCur[idStringify(doc._id)] = i;
});
// Arrays can contain arbitrary objects. We don't diff the
// objects. Instead we always fire 'changedAt' callback on every
// object. The consumer of `observe-sequence` should deal with
// it appropriately.
diffFn(oldObjIds, newObjIds, {
addedBefore: function addedBefore(id, doc, before) {
var position = before ? posCur[idStringify(before)] : lengthCur;
_underscore2.default.each(posCur, function (pos, id) {
if (pos >= position) posCur[id]++;
});
lengthCur++;
posCur[idStringify(id)] = position;
callbacks.addedAt(id, seqArray[posNew[idStringify(id)]], position, before);
},
movedBefore: function movedBefore(id, before) {
var prevPosition = posCur[idStringify(id)];
var position = before ? posCur[idStringify(before)] : lengthCur - 1;
_underscore2.default.each(posCur, function (pos, id) {
if (pos >= prevPosition && pos <= position) posCur[id]--;else if (pos <= prevPosition && pos >= position) posCur[id]++;
});
posCur[idStringify(id)] = position;
callbacks.movedTo(id, seqArray[posNew[idStringify(id)]], prevPosition, position, before);
},
removed: function removed(id) {
var prevPosition = posCur[idStringify(id)];
_underscore2.default.each(posCur, function (pos, id) {
if (pos >= prevPosition) posCur[id]--;
});
delete posCur[idStringify(id)];
lengthCur--;
callbacks.removedAt(id, lastSeqArray[posOld[idStringify(id)]], prevPosition);
}
});
_underscore2.default.each(posNew, function (pos, idString) {
if (!_underscore2.default.has(posOld, idString)) return;
var id = idParse(idString);
var newItem = seqArray[pos] || {};
var oldItem = lastSeqArray[posOld[idString]];
var updates = getUpdates(oldItem, newItem, preventNestedDiff);
if (!_underscore2.default.isEmpty(updates)) callbacks.changedAt(id, updates, pos, oldItem);
});
}
diffArray.shallow = function (lastSeqArray, seqArray, callbacks) {
return diffArray(lastSeqArray, seqArray, callbacks, true);
};
diffArray.deepCopyChanges = function (oldItem, newItem) {
var setDiff = getUpdates(oldItem, newItem).$set;
_underscore2.default.each(setDiff, function (v, deepKey) {
setDeep(oldItem, deepKey, v);
});
};
diffArray.deepCopyRemovals = function (oldItem, newItem) {
var unsetDiff = getUpdates(oldItem, newItem).$unset;
_underscore2.default.each(unsetDiff, function (v, deepKey) {
unsetDeep(oldItem, deepKey);
});
};
// Finds changes between two collections
diffArray.getChanges = function (newCollection, oldCollection, diffMethod) {
var changes = { added: [], removed: [], changed: [] };
diffMethod(oldCollection, newCollection, {
addedAt: function addedAt(id, item, index) {
changes.added.push({ item: item, index: index });
},
removedAt: function removedAt(id, item, index) {
changes.removed.push({ item: item, index: index });
},
changedAt: function changedAt(id, updates, index, oldItem) {
changes.changed.push({ selector: id, modifier: updates });
},
movedTo: function movedTo(id, item, fromIndex, toIndex) {
// XXX do we need this?
}
});
return changes;
};
var setDeep = function setDeep(obj, deepKey, v) {
var split = deepKey.split('.');
var initialKeys = _underscore2.default.initial(split);
var lastKey = _underscore2.default.last(split);
initialKeys.reduce(function (subObj, k, i) {
var nextKey = split[i + 1];
if (isNumStr(nextKey)) {
if (subObj[k] === null) subObj[k] = [];
if (subObj[k].length == parseInt(nextKey)) subObj[k].push(null);
} else if (subObj[k] === null || !isHash(subObj[k])) {
subObj[k] = {};
}
return subObj[k];
}, obj);
var deepObj = getDeep(obj, initialKeys);
deepObj[lastKey] = v;
return v;
};
var unsetDeep = function unsetDeep(obj, deepKey) {
var split = deepKey.split('.');
var initialKeys = _underscore2.default.initial(split);
var lastKey = _underscore2.default.last(split);
var deepObj = getDeep(obj, initialKeys);
if (_underscore2.default.isArray(deepObj) && isNumStr(lastKey)) return !!deepObj.splice(lastKey, 1);else return delete deepObj[lastKey];
};
var getDeep = function getDeep(obj, keys) {
return keys.reduce(function (subObj, k) {
return subObj[k];
}, obj);
};
var isHash = function isHash(obj) {
return _underscore2.default.isObject(obj) && Object.getPrototypeOf(obj) === Object.prototype;
};
var isNumStr = function isNumStr(str) {
return str.match(/^\d+$/);
};
return diffArray;
}]);
/***/ }),
/* 5 */
/***/ (function(module, exports) {
'use strict';
angular.module('angular-meteor.settings', []).constant('$angularMeteorSettings', {
suppressWarnings: true
});
/***/ }),
/* 6 */
/***/ (function(module, exports) {
'use strict';
angular.module('angular-meteor.ironrouter', []).run(['$compile', '$document', '$rootScope', function ($compile, $document, $rootScope) {
var Router = (Package['iron:router'] || {}).Router;
if (!Router) return;
var isLoaded = false;
// Recompile after iron:router builds page
Router.onAfterAction(function (req, res, next) {
Tracker.afterFlush(function () {
if (isLoaded) return;
$compile($document)($rootScope);
if (!$rootScope.$$phase) $rootScope.$apply();
isLoaded = true;
});
});
}]);
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /*global
angular, _, Tracker, EJSON, FS, Mongo
*/
var _underscore = __webpack_require__(2);
var _underscore2 = _interopRequireDefault(_underscore);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
'use strict';
var angularMeteorUtils = angular.module('angular-meteor.utils', ['angular-meteor.settings']);
angularMeteorUtils.service('$meteorUtils', ['$q', '$timeout', '$angularMeteorSettings', function ($q, $timeout, $angularMeteorSettings) {
var self = this;
this.autorun = function (scope, fn) {
if (!$angularMeteorSettings.suppressWarnings) console.warn('[angular-meteor.utils.autorun] Please note that this method is deprecated since 1.3.0 and will be removed in 1.4.0! For more info: http://www.angular-meteor.com/api/1.3.6/autorun. You can disable this warning by following this guide http://www.angular-meteor.com/api/1.3.6/settings');
// wrapping around Deps.autorun
var comp = Tracker.autorun(function (c) {
fn(c);
// this is run immediately for the first call
// but after that, we need to $apply to start Angular digest
if (!c.firstRun) $timeout(angular.noop, 0);
});
// stop autorun when scope is destroyed
scope.$on('$destroy', function () {
comp.stop();
});
// return autorun object so that it can be stopped manually
return comp;
};
// Borrowed from angularFire
// https://github.com/firebase/angularfire/blob/master/src/utils.js#L445-L454
this.stripDollarPrefixedKeys = function (data) {
if (!_underscore2.default.isObject(data) || data instanceof Date || data instanceof File || EJSON.toJSONValue(data).$type === 'oid' || (typeof FS === 'undefined' ? 'undefined' : _typeof(FS)) === 'object' && data instanceof FS.File) return data;
var out = _underscore2.default.isArray(data) ? [] : {};
_underscore2.default.each(data, function (v, k) {
if (typeof k !== 'string' || k.charAt(0) !== '$') out[k] = self.stripDollarPrefixedKeys(v);
});
return out;
};
// Returns a callback which fulfills promise
this.fulfill = function (deferred, boundError, boundResult) {
return function (err, result) {
if (err) deferred.reject(boundError == null ? err : boundError);else if (typeof boundResult == "function") deferred.resolve(boundResult == null ? result : boundResult(result));else deferred.resolve(boundResult == null ? result : boundResult);
};
};
// creates a function which invokes method with the given arguments and returns a promise
this.promissor = function (obj, method) {
return function () {
var deferred = $q.defer();
var fulfill = self.fulfill(deferred);
var args = _underscore2.default.toArray(arguments).concat(fulfill);
obj[method].apply(obj, args);
return deferred.promise;
};
};
// creates a $q.all() promise and call digestion loop on fulfillment
this.promiseAll = function (promises) {
var allPromise = $q.all(promises);
allPromise.finally(function () {
// calls digestion loop with no conflicts
$timeout(angular.noop);
});
return allPromise;
};
this.getCollectionByName = function (string) {
return Mongo.Collection.get(string);
};
this.findIndexById = function (collection, doc) {
var foundDoc = _underscore2.default.find(collection, function (colDoc) {
// EJSON.equals used to compare Mongo.ObjectIDs and Strings.
return EJSON.equals(colDoc._id, doc._id);
});
return _underscore2.default.indexOf(collection, foundDoc);
};
}]);
angularMeteorUtils.run(['$rootScope', '$meteorUtils', function ($rootScope, $meteorUtils) {
Object.getPrototypeOf($rootScope).$meteorAutorun = function (fn) {
return $meteorUtils.autorun(this, fn);
};
}]);
/***/ }),
/* 8 */
/***/ (function(module, exports) {
/*global
angular, Meteor
*/
'use strict';
var angularMeteorSubscribe = angular.module('angular-meteor.subscribe', ['angular-meteor.settings']);
angularMeteorSubscribe.service('$meteorSubscribe', ['$q', '$angularMeteorSettings', function ($q, $angularMeteorSettings) {
var self = this;
this._subscribe = function (scope, deferred, args) {
if (!$angularMeteorSettings.suppressWarnings) console.warn('[angular-meteor.subscribe] Please note that this module is deprecated since 1.3.0 and will be removed in 1.4.0! Replace it with the new syntax described here: http://www.angular-meteor.com/api/1.3.6/subscribe. You can disable this warning by following this guide http://www.angular-meteor.com/api/1.3.6/settings');
var subscription = null;
var lastArg = args[args.length - 1];
// User supplied onStop callback
// save it for later use and remove
// from subscription arguments
if (angular.isObject(lastArg) && angular.isFunction(lastArg.onStop)) {
var _onStop = lastArg.onStop;
args.pop();
}
args.push({
onReady: function onReady() {
deferred.resolve(subscription);
},
onStop: function onStop(err) {
if (!deferred.promise.$$state.status) {
if (err) deferred.reject(err);else deferred.reject(new Meteor.Error("Subscription Stopped", "Subscription stopped by a call to stop method. Either by the client or by the server."));
} else if (_onStop)
// After promise was resolved or rejected
// call user supplied onStop callback.
_onStop.apply(this, Array.prototype.slice.call(arguments));
}
});
subscription = Meteor.subscribe.apply(scope, args);
return subscription;
};
this.subscribe = function () {
var deferred = $q.defer();
var args = Array.prototype.slice.call(arguments);
var subscription = null;
self._subscribe(this, deferred, args);
return deferred.promise;
};
}]);
angularMeteorSubscribe.run(['$rootScope', '$q', '$meteorSubscribe', function ($rootScope, $q, $meteorSubscribe) {
Object.getPrototypeOf($rootScope).$meteorSubscribe = function () {
var deferred = $q.defer();
var args = Array.prototype.slice.call(arguments);
var subscription = $meteorSubscribe._subscribe(this, deferred, args);
this.$on('$destroy', function () {
subscription.stop();
});
return deferred.promise;
};
}]);
/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
var _underscore = __webpack_require__(2);
var _underscore2 = _interopRequireDefault(_underscore);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
'use strict'; /*global
angular, _, Tracker, check, Match, Mongo
*/
var angularMeteorCollection = angular.module('angular-meteor.collection', ['angular-meteor.stopper', 'angular-meteor.subscribe', 'angular-meteor.utils', 'diffArray', 'angular-meteor.settings']);
// The reason angular meteor collection is a factory function and not something
// that inherit from array comes from here:
// http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/
// We went with the direct extensions approach.
angularMeteorCollection.factory('AngularMeteorCollection', ['$q', '$meteorSubscribe', '$meteorUtils', '$rootScope', '$timeout', 'diffArray', '$angularMeteorSettings', function ($q, $meteorSubscribe, $meteorUtils, $rootScope, $timeout, diffArray, $angularMeteorSettings) {
function AngularMeteorCollection(curDefFunc, collection, diffArrayFunc, autoClientSave) {
if (!$angularMeteorSettings.suppressWarnings) console.warn('[angular-meteor.$meteorCollection] Please note that this method is deprecated since 1.3.0 and will be removed in 1.4.0! For more info: http://www.angular-meteor.com/api/1.3.0/meteorCollection. You can disable this warning by following this guide http://www.angular-meteor.com/api/1.3.6/settings');
var data = [];
// Server backup data to evaluate what changes come from client
// after each server update.
data._serverBackup = [];
// Array differ function.
data._diffArrayFunc = diffArrayFunc;
// Handler of the cursor observer.
data._hObserve = null;
// On new cursor autorun handler
// (autorun for reactive variables).
data._hNewCurAutorun = null;
// On new data autorun handler
// (autorun for cursor.fetch).
data._hDataAutorun = null;
if (angular.isDefined(collection)) {
data.$$collection = collection;
} else {
var cursor = curDefFunc();
data.$$collection = $meteorUtils.getCollectionByName(cursor.collection.name);
}
_underscore2.default.extend(data, AngularMeteorCollection);
data._startCurAutorun(curDefFunc, autoClientSave);
return data;
}
AngularMeteorCollection._startCurAutorun = function (curDefFunc, autoClientSave) {
var self = this;
self._hNewCurAutorun = Tracker.autorun(function () {
// When the reactive func gets recomputated we need to stop any previous
// observeChanges.
Tracker.onInvalidate(function () {
self._stopCursor();
});
if (autoClientSave) self._setAutoClientSave();
self._updateCursor(curDefFunc(), autoClientSave);
});
};
AngularMeteorCollection.subscribe = function () {
$meteorSubscribe.subscribe.apply(this, arguments);
return this;
};
AngularMeteorCollection.save = function (docs, useUnsetModifier) {
// save whole collection
if (!docs) docs = this;
// save single doc
docs = [].concat(docs);
var promises = docs.map(function (doc) {
return this._upsertDoc(doc, useUnsetModifier);
}, this);
return $meteorUtils.promiseAll(promises);
};
AngularMeteorCollection._upsertDoc = function (doc, useUnsetModifier) {
var deferred = $q.defer();
var collection = this.$$collection;
var createFulfill = _underscore2.default.partial($meteorUtils.fulfill, deferred, null);
// delete $$hashkey
doc = $meteorUtils.stripDollarPrefixedKeys(doc);
var docId = doc._id;
var isExist = collection.findOne(docId);
// update
if (isExist) {
// Deletes _id property (from the copy) so that
// it can be $set using update.
delete doc._id;
var modifier = useUnsetModifier ? { $unset: doc } : { $set: doc };
// NOTE: do not use #upsert() method, since it does not exist in some collections
collection.update(docId, modifier, createFulfill(function () {
return { _id: docId, action: 'updated' };
}));
}
// insert
else {
collection.insert(doc, createFulfill(function (id) {
return { _id: id, action: 'inserted' };
}));
}
return deferred.promise;
};
// performs $pull operations parallely.
// used for handling splice operations returned from getUpdates() to prevent conflicts.
// see issue: https://github.com/Urigo/angular-meteor/issues/793
AngularMeteorCollection._updateDiff = function (selector, update, callback) {
callback = callback || angular.noop;
var setters = _underscore2.default.omit(update, '$pull');
var updates = [setters];
_underscore2.default.each(update.$pull, function (pull, prop) {
var puller = {};
puller[prop] = pull;
updates.push({ $pull: puller });
});
this._updateParallel(selector, updates, callback);
};
// performs each update operation parallely
AngularMeteorCollection._updateParallel = function (selector, updates, callback) {
var self = this;
var done = _underscore2.default.after(updates.length, callback);
var next = function next(err, affectedDocsNum) {
if (err) return callback(err);
done(null, affectedDocsNum);
};
_underscore2.default.each(updates, function (update) {
self.$$collection.update(selector, update, next);
});
};
AngularMeteorCollection.remove = function (keyOrDocs) {
var keys;
// remove whole collection
if (!keyOrDocs) {
keys = _underscore2.default.pluck(this, '_id');
}
// remove docs
else {
keyOrDocs = [].concat(keyOrDocs);
keys = _underscore2.default.map(keyOrDocs, function (keyOrDoc) {
return keyOrDoc._id || keyOrDoc;
});
}
// Checks if all keys are correct.
check(keys, [Match.OneOf(String, Mongo.ObjectID)]);
var promises = keys.map(function (key) {
return this._removeDoc(key);
}, this);
return $meteorUtils.promiseAll(promises);
};
AngularMeteorCollection._removeDoc = function (id) {
var deferred = $q.defer();
var collection = this.$$collection;
var fulfill = $meteorUtils.fulfill(deferred, null, { _id: id, action: 'removed' });
collection.remove(id, fulfill);
return deferred.promise;
};
AngularMeteorCollection._updateCursor = function (cursor, autoClientSave) {
var self = this;
// XXX - consider adding an option for a non-orderd result for faster performance
if (self._hObserve) self._stopObserving();
self._hObserve = cursor.observe({
addedAt: function addedAt(doc, atIndex) {
self.splice(atIndex, 0, doc);
self._serverBackup.splice(atIndex, 0, doc);
self._setServerUpdateMode();
},
changedAt: function changedAt(doc, oldDoc, atIndex) {
diffArray.deepCopyChanges(self[atIndex], doc);
diffArray.deepCopyRemovals(self[atIndex], doc);
self._serverBackup[atIndex] = self[atIndex];
self._setServerUpdateMode();
},
movedTo: function movedTo(doc, fromIndex, toIndex) {
self.splice(fromIndex, 1);
self.splice(toIndex, 0, doc);
self._serverBackup.splice(fromIndex, 1);
self._serverBackup.splice(toIndex, 0, doc);
self._setServerUpdateMode();
},