@fireflysemantics/slice 15.0.18 → 15.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/README.md +1 -0
  2. package/esm2020/lib/AbstractStore.mjs +296 -0
  3. package/{esm2015/lib/EStore.js → esm2020/lib/EStore.mjs} +10 -10
  4. package/esm2020/lib/Slice.mjs +222 -0
  5. package/esm2020/lib/utilities.mjs +226 -0
  6. package/{esm2015/public-api.js → esm2020/public-api.mjs} +1 -1
  7. package/fesm2015/{fireflysemantics-slice.js → fireflysemantics-slice.mjs} +35 -22
  8. package/fesm2015/fireflysemantics-slice.mjs.map +1 -0
  9. package/fesm2020/fireflysemantics-slice.mjs +1494 -0
  10. package/fesm2020/fireflysemantics-slice.mjs.map +1 -0
  11. package/lib/models/Predicate.d.ts +1 -1
  12. package/lib/models/scrollPosition.d.ts +1 -1
  13. package/lib/utilities.d.ts +12 -1
  14. package/package.json +22 -9
  15. package/bundles/fireflysemantics-slice.umd.js +0 -1891
  16. package/bundles/fireflysemantics-slice.umd.js.map +0 -1
  17. package/esm2015/lib/AbstractStore.js +0 -296
  18. package/esm2015/lib/Slice.js +0 -222
  19. package/esm2015/lib/utilities.js +0 -213
  20. package/fesm2015/fireflysemantics-slice.js.map +0 -1
  21. /package/{esm2015/fireflysemantics-slice.js → esm2020/fireflysemantics-slice.mjs} +0 -0
  22. /package/{esm2015/lib/OStore.js → esm2020/lib/OStore.mjs} +0 -0
  23. /package/{esm2015/lib/models/ActionTypes.js → esm2020/lib/models/ActionTypes.mjs} +0 -0
  24. /package/{esm2015/lib/models/Delta.js → esm2020/lib/models/Delta.mjs} +0 -0
  25. /package/{esm2015/lib/models/Entity.js → esm2020/lib/models/Entity.mjs} +0 -0
  26. /package/{esm2015/lib/models/Predicate.js → esm2020/lib/models/Predicate.mjs} +0 -0
  27. /package/{esm2015/lib/models/StoreConfig.js → esm2020/lib/models/StoreConfig.mjs} +0 -0
  28. /package/{esm2015/lib/models/constants.js → esm2020/lib/models/constants.mjs} +0 -0
  29. /package/{esm2015/lib/models/index.js → esm2020/lib/models/index.mjs} +0 -0
  30. /package/{esm2015/lib/models/scrollPosition.js → esm2020/lib/models/scrollPosition.mjs} +0 -0
  31. /package/{fireflysemantics-slice.d.ts → index.d.ts} +0 -0
@@ -1,1891 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('rxjs'), require('rxjs/operators'), require('nanoid')) :
3
- typeof define === 'function' && define.amd ? define('@fireflysemantics/slice', ['exports', 'rxjs', 'rxjs/operators', 'nanoid'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.fireflysemantics = global.fireflysemantics || {}, global.fireflysemantics.slice = {}), global.rxjs, global.rxjs.operators, global.nanoid));
5
- }(this, (function (exports, rxjs, operators, nanoid) { 'use strict';
6
-
7
- ;
8
-
9
- /**
10
- * Abstract Entity base class with the
11
- * gid and id properties declared.
12
- */
13
- var Entity = /** @class */ (function () {
14
- function Entity() {
15
- }
16
- return Entity;
17
- }());
18
-
19
- var SCROLL_UP_DEBOUNCE_TIME_20 = 20;
20
- var SEARCH_DEBOUNCE_TIME_300 = 300;
21
-
22
- var freeze = Object.freeze;
23
- var ESTORE_DEFAULT_ID_KEY = "id";
24
- var ESTORE_DEFAULT_GID_KEY = "gid";
25
- var ESTORE_CONFIG_DEFAULT = freeze({
26
- idKey: ESTORE_DEFAULT_ID_KEY,
27
- guidKey: ESTORE_DEFAULT_GID_KEY
28
- });
29
- var AbstractStore = /** @class */ (function () {
30
- function AbstractStore(config) {
31
- /**
32
- * Notifies observers of the store query.
33
- */
34
- this.notifyQuery = new rxjs.ReplaySubject(1);
35
- /**
36
- * The current query state.
37
- */
38
- this._query = '';
39
- /**
40
- * Primary index for the stores elements.
41
- */
42
- this.entries = new Map();
43
- /**
44
- * The element entries that are keyed by
45
- * an id generated on the server.
46
- */
47
- this.idEntries = new Map();
48
- /**
49
- * Create notifications that broacast
50
- * the entire set of entries.
51
- */
52
- this.notify = new rxjs.ReplaySubject(1);
53
- /**
54
- * Create notifications that broacast
55
- * store or slice delta state changes.
56
- */
57
- this.notifyDelta = new rxjs.ReplaySubject(1);
58
- /**
59
- * An Observable<E[]> reference
60
- * to the entities in the store or
61
- * Slice instance.
62
- *
63
- */
64
- this.obs = this.observe();
65
- this.config = config
66
- ? freeze(Object.assign(Object.assign({}, ESTORE_CONFIG_DEFAULT), config))
67
- : ESTORE_CONFIG_DEFAULT;
68
- }
69
- Object.defineProperty(AbstractStore.prototype, "query", {
70
- /**
71
- * @return A snapshot of the query state.
72
- */
73
- get: function () {
74
- return this._query;
75
- },
76
- /**
77
- * Sets the current query state and notifies observers.
78
- */
79
- set: function (query) {
80
- this._query = query;
81
- this.notifyQuery.next(this._query);
82
- },
83
- enumerable: false,
84
- configurable: true
85
- });
86
- /**
87
- * Observe the query.
88
- * @example
89
- <pre>
90
- let query$ = source.observeQuery();
91
- </pre>
92
- */
93
- AbstractStore.prototype.observeQuery = function () {
94
- return this.notifyQuery.asObservable();
95
- };
96
- Object.defineProperty(AbstractStore.prototype, "ID_KEY", {
97
- /**
98
- * The current id key for the EStore instance.
99
- * @return this.config.idKey;
100
- */
101
- get: function () {
102
- return this.config.idKey;
103
- },
104
- enumerable: false,
105
- configurable: true
106
- });
107
- Object.defineProperty(AbstractStore.prototype, "GUID_KEY", {
108
- /**
109
- * The current guid key for the EStore instance.
110
- * @return this.config.guidKey;
111
- */
112
- get: function () {
113
- return this.config.guidKey;
114
- },
115
- enumerable: false,
116
- configurable: true
117
- });
118
- /**
119
- * Call all the notifiers at once.
120
- *
121
- * @param v
122
- * @param delta
123
- */
124
- AbstractStore.prototype.notifyAll = function (v, delta) {
125
- this.notify.next(v);
126
- this.notifyDelta.next(delta);
127
- };
128
- /**
129
- * Observe store state changes.
130
- * @param sort Optional sorting function yielding a sorted observable.
131
- * @example
132
- ```
133
- let todos$ = source.observe();
134
- //or with a sort by title function
135
- let todos$ = source.observe((a, b)=>(a.title > b.title ? -1 : 1));
136
- ```
137
- */
138
- AbstractStore.prototype.observe = function (sort) {
139
- if (sort) {
140
- return this.notify.pipe(operators.map(function (e) { return e.sort(sort); }));
141
- }
142
- return this.notify.asObservable();
143
- };
144
- /**
145
- * Observe delta updates.
146
- * @example
147
- <pre>
148
- let todos$ = source.observeDelta();
149
- </pre>
150
- */
151
- AbstractStore.prototype.observeDelta = function () {
152
- return this.notifyDelta.asObservable();
153
- };
154
- /**
155
- * Check whether the store is empty.
156
- *
157
- * @return A hot {@link Observable} that indicates whether the store is empty.
158
- *
159
- * @example
160
- <pre>
161
- source.isEmpty();
162
- </pre>
163
- */
164
- AbstractStore.prototype.isEmpty = function () {
165
- return this.notify.pipe(operators.map(function (entries) { return entries.length == 0; }));
166
- };
167
- /**
168
- * Check whether the store is empty.
169
- *
170
- * @return A snapshot that indicates whether the store is empty.
171
- *
172
- * @example
173
- <pre>
174
- source.isEmpty();
175
- </pre>
176
- */
177
- AbstractStore.prototype.isEmptySnapshot = function () {
178
- return Array.from(this.entries.values()).length == 0;
179
- };
180
- /**
181
- * Returns the number of entries contained.
182
- * @param p The predicate to apply in order to filter the count
183
- */
184
- AbstractStore.prototype.count = function (p) {
185
- if (p) {
186
- return this.notify.pipe(operators.map(function (e) { return e.reduce(function (total, e) { return total + (p(e) ? 1 : 0); }, 0); }));
187
- }
188
- return this.notify.pipe(operators.map(function (entries) { return entries.length; }));
189
- };
190
- /**
191
- * Returns a snapshot of the number of entries contained in the store.
192
- * @param p The predicate to apply in order to filter the count
193
- */
194
- AbstractStore.prototype.countSnapshot = function (p) {
195
- if (p) {
196
- return Array.from(this.entries.values()).filter(p).length;
197
- }
198
- return Array.from(this.entries.values()).length;
199
- };
200
- /**
201
- * Snapshot of all entries.
202
- *
203
- * @return Snapshot array of all the elements the entities the store contains.
204
- *
205
- * @example Observe a snapshot of all the entities in the store.
206
- ```
207
- let selectedTodos:Todo[] = source.allSnapshot();
208
- ```
209
- */
210
- AbstractStore.prototype.allSnapshot = function () {
211
- return Array.from(this.entries.values());
212
- };
213
- /**
214
- * Returns true if the entries contain the identified instance.
215
- *
216
- * @param target Either an instance of type `E` or a `guid` identifying the instance.
217
- * @param byId Whether the lookup should be performed with the `id` key rather than the `guid`.
218
- * @returns true if the instance identified by the guid exists, false otherwise.
219
- *
220
- * @example
221
- <pre>
222
- let contains:boolean = source.contains(guid);
223
- </pre>
224
- */
225
- AbstractStore.prototype.contains = function (target) {
226
- if (typeof target === "string") {
227
- return this.entries.get(target) ? true : false;
228
- }
229
- var guid = target[this.config.guidKey];
230
- return this.entries.get(guid) ? true : false;
231
- };
232
- /**
233
- * Returns true if the entries contain the identified instance.
234
- *
235
- * @param target Either an instance of type `E` or a `id` identifying the instance.
236
- * @returns true if the instance identified by the `id` exists, false otherwise.
237
- *
238
- * @example
239
- <pre>
240
- let contains:boolean = source.contains(guid);
241
- </pre>
242
- */
243
- AbstractStore.prototype.containsById = function (target) {
244
- if (typeof target === "string") {
245
- return this.idEntries.get(target) ? true : false;
246
- }
247
- var id = target[this.config.idKey];
248
- return this.idEntries.get(id) ? true : false;
249
- };
250
- /**
251
- * Find and return the entity identified by the GUID parameter
252
- * if it exists and return it.
253
- *
254
- * @param guid
255
- * @return The entity instance if it exists, null otherwise
256
- */
257
- AbstractStore.prototype.findOne = function (guid) {
258
- return this.entries.get(guid);
259
- };
260
- /**
261
- * Find and return the entity identified by the ID parameter
262
- * if it exists and return it.
263
- *
264
- * @param id
265
- * @return The entity instance if it exists, null otherwise
266
- */
267
- AbstractStore.prototype.findOneByID = function (id) {
268
- return this.idEntries.get(id);
269
- };
270
- /**
271
- * Snapshot of the entries that match the predicate.
272
- *
273
- * @param p The predicate used to query for the selection.
274
- * @return A snapshot array containing the entities that match the predicate.
275
- *
276
- * @example Select all the `Todo` instance where the `title` length is greater than 100.
277
- ```
278
- let todos:Todo[]=store.select(todo=>todo.title.length>100);
279
- ```
280
- */
281
- AbstractStore.prototype.select = function (p) {
282
- var selected = [];
283
- Array.from(this.entries.values()).forEach(function (e) {
284
- if (p(e)) {
285
- selected.push(e);
286
- }
287
- });
288
- return selected;
289
- };
290
- /**
291
- * Compare entities by GUID
292
- * @param e1 The first entity
293
- * @param e2 The second entity
294
- * @return true if the two entities have equal GUID ids
295
- * @example Compare `todo1` with `todo2` by `gid`.
296
- ```
297
- if (equalsByGUID(todo1, todo2)){...};
298
- ```
299
- */
300
- AbstractStore.prototype.equalsByGUID = function (e1, e2) {
301
- return e1[this.GUID_KEY] == e2[this.GUID_KEY];
302
- };
303
- /**
304
- * Compare entities by ID
305
- * @param e1 The first entity
306
- * @param e2 The second entity
307
- * @return true if the two entities have equal ID ids
308
- * @example Compare `todo1` with `todo2` by `id`.
309
- ```
310
- if (equalsByID(todo1, todo2)){...};
311
- ```
312
- */
313
- AbstractStore.prototype.equalsByID = function (e1, e2) {
314
- return e1[this.ID_KEY] == e2[this.ID_KEY];
315
- };
316
- /**
317
- * Calls complete on all {@link BehaviorSubject} instances.
318
- *
319
- * Call destroy when disposing of the store.
320
- */
321
- AbstractStore.prototype.destroy = function () {
322
- this.notify.complete();
323
- this.notifyDelta.complete();
324
- this.notifyQuery.complete();
325
- };
326
- return AbstractStore;
327
- }());
328
-
329
- /*! *****************************************************************************
330
- Copyright (c) Microsoft Corporation.
331
-
332
- Permission to use, copy, modify, and/or distribute this software for any
333
- purpose with or without fee is hereby granted.
334
-
335
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
336
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
337
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
338
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
339
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
340
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
341
- PERFORMANCE OF THIS SOFTWARE.
342
- ***************************************************************************** */
343
- /* global Reflect, Promise */
344
- var extendStatics = function (d, b) {
345
- extendStatics = Object.setPrototypeOf ||
346
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
347
- function (d, b) { for (var p in b)
348
- if (Object.prototype.hasOwnProperty.call(b, p))
349
- d[p] = b[p]; };
350
- return extendStatics(d, b);
351
- };
352
- function __extends(d, b) {
353
- if (typeof b !== "function" && b !== null)
354
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
355
- extendStatics(d, b);
356
- function __() { this.constructor = d; }
357
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
358
- }
359
- var __assign = function () {
360
- __assign = Object.assign || function __assign(t) {
361
- for (var s, i = 1, n = arguments.length; i < n; i++) {
362
- s = arguments[i];
363
- for (var p in s)
364
- if (Object.prototype.hasOwnProperty.call(s, p))
365
- t[p] = s[p];
366
- }
367
- return t;
368
- };
369
- return __assign.apply(this, arguments);
370
- };
371
- function __rest(s, e) {
372
- var t = {};
373
- for (var p in s)
374
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
375
- t[p] = s[p];
376
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
377
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
378
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
379
- t[p[i]] = s[p[i]];
380
- }
381
- return t;
382
- }
383
- function __decorate(decorators, target, key, desc) {
384
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
385
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
386
- r = Reflect.decorate(decorators, target, key, desc);
387
- else
388
- for (var i = decorators.length - 1; i >= 0; i--)
389
- if (d = decorators[i])
390
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
391
- return c > 3 && r && Object.defineProperty(target, key, r), r;
392
- }
393
- function __param(paramIndex, decorator) {
394
- return function (target, key) { decorator(target, key, paramIndex); };
395
- }
396
- function __metadata(metadataKey, metadataValue) {
397
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
398
- return Reflect.metadata(metadataKey, metadataValue);
399
- }
400
- function __awaiter(thisArg, _arguments, P, generator) {
401
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
402
- return new (P || (P = Promise))(function (resolve, reject) {
403
- function fulfilled(value) { try {
404
- step(generator.next(value));
405
- }
406
- catch (e) {
407
- reject(e);
408
- } }
409
- function rejected(value) { try {
410
- step(generator["throw"](value));
411
- }
412
- catch (e) {
413
- reject(e);
414
- } }
415
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
416
- step((generator = generator.apply(thisArg, _arguments || [])).next());
417
- });
418
- }
419
- function __generator(thisArg, body) {
420
- var _ = { label: 0, sent: function () { if (t[0] & 1)
421
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
422
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
423
- function verb(n) { return function (v) { return step([n, v]); }; }
424
- function step(op) {
425
- if (f)
426
- throw new TypeError("Generator is already executing.");
427
- while (_)
428
- try {
429
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
430
- return t;
431
- if (y = 0, t)
432
- op = [op[0] & 2, t.value];
433
- switch (op[0]) {
434
- case 0:
435
- case 1:
436
- t = op;
437
- break;
438
- case 4:
439
- _.label++;
440
- return { value: op[1], done: false };
441
- case 5:
442
- _.label++;
443
- y = op[1];
444
- op = [0];
445
- continue;
446
- case 7:
447
- op = _.ops.pop();
448
- _.trys.pop();
449
- continue;
450
- default:
451
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
452
- _ = 0;
453
- continue;
454
- }
455
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
456
- _.label = op[1];
457
- break;
458
- }
459
- if (op[0] === 6 && _.label < t[1]) {
460
- _.label = t[1];
461
- t = op;
462
- break;
463
- }
464
- if (t && _.label < t[2]) {
465
- _.label = t[2];
466
- _.ops.push(op);
467
- break;
468
- }
469
- if (t[2])
470
- _.ops.pop();
471
- _.trys.pop();
472
- continue;
473
- }
474
- op = body.call(thisArg, _);
475
- }
476
- catch (e) {
477
- op = [6, e];
478
- y = 0;
479
- }
480
- finally {
481
- f = t = 0;
482
- }
483
- if (op[0] & 5)
484
- throw op[1];
485
- return { value: op[0] ? op[1] : void 0, done: true };
486
- }
487
- }
488
- var __createBinding = Object.create ? (function (o, m, k, k2) {
489
- if (k2 === undefined)
490
- k2 = k;
491
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
492
- }) : (function (o, m, k, k2) {
493
- if (k2 === undefined)
494
- k2 = k;
495
- o[k2] = m[k];
496
- });
497
- function __exportStar(m, o) {
498
- for (var p in m)
499
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
500
- __createBinding(o, m, p);
501
- }
502
- function __values(o) {
503
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
504
- if (m)
505
- return m.call(o);
506
- if (o && typeof o.length === "number")
507
- return {
508
- next: function () {
509
- if (o && i >= o.length)
510
- o = void 0;
511
- return { value: o && o[i++], done: !o };
512
- }
513
- };
514
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
515
- }
516
- function __read(o, n) {
517
- var m = typeof Symbol === "function" && o[Symbol.iterator];
518
- if (!m)
519
- return o;
520
- var i = m.call(o), r, ar = [], e;
521
- try {
522
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
523
- ar.push(r.value);
524
- }
525
- catch (error) {
526
- e = { error: error };
527
- }
528
- finally {
529
- try {
530
- if (r && !r.done && (m = i["return"]))
531
- m.call(i);
532
- }
533
- finally {
534
- if (e)
535
- throw e.error;
536
- }
537
- }
538
- return ar;
539
- }
540
- /** @deprecated */
541
- function __spread() {
542
- for (var ar = [], i = 0; i < arguments.length; i++)
543
- ar = ar.concat(__read(arguments[i]));
544
- return ar;
545
- }
546
- /** @deprecated */
547
- function __spreadArrays() {
548
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
549
- s += arguments[i].length;
550
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
551
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
552
- r[k] = a[j];
553
- return r;
554
- }
555
- function __spreadArray(to, from, pack) {
556
- if (pack || arguments.length === 2)
557
- for (var i = 0, l = from.length, ar; i < l; i++) {
558
- if (ar || !(i in from)) {
559
- if (!ar)
560
- ar = Array.prototype.slice.call(from, 0, i);
561
- ar[i] = from[i];
562
- }
563
- }
564
- return to.concat(ar || from);
565
- }
566
- function __await(v) {
567
- return this instanceof __await ? (this.v = v, this) : new __await(v);
568
- }
569
- function __asyncGenerator(thisArg, _arguments, generator) {
570
- if (!Symbol.asyncIterator)
571
- throw new TypeError("Symbol.asyncIterator is not defined.");
572
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
573
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
574
- function verb(n) { if (g[n])
575
- i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
576
- function resume(n, v) { try {
577
- step(g[n](v));
578
- }
579
- catch (e) {
580
- settle(q[0][3], e);
581
- } }
582
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
583
- function fulfill(value) { resume("next", value); }
584
- function reject(value) { resume("throw", value); }
585
- function settle(f, v) { if (f(v), q.shift(), q.length)
586
- resume(q[0][0], q[0][1]); }
587
- }
588
- function __asyncDelegator(o) {
589
- var i, p;
590
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
591
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
592
- }
593
- function __asyncValues(o) {
594
- if (!Symbol.asyncIterator)
595
- throw new TypeError("Symbol.asyncIterator is not defined.");
596
- var m = o[Symbol.asyncIterator], i;
597
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
598
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
599
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
600
- }
601
- function __makeTemplateObject(cooked, raw) {
602
- if (Object.defineProperty) {
603
- Object.defineProperty(cooked, "raw", { value: raw });
604
- }
605
- else {
606
- cooked.raw = raw;
607
- }
608
- return cooked;
609
- }
610
- ;
611
- var __setModuleDefault = Object.create ? (function (o, v) {
612
- Object.defineProperty(o, "default", { enumerable: true, value: v });
613
- }) : function (o, v) {
614
- o["default"] = v;
615
- };
616
- function __importStar(mod) {
617
- if (mod && mod.__esModule)
618
- return mod;
619
- var result = {};
620
- if (mod != null)
621
- for (var k in mod)
622
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
623
- __createBinding(result, mod, k);
624
- __setModuleDefault(result, mod);
625
- return result;
626
- }
627
- function __importDefault(mod) {
628
- return (mod && mod.__esModule) ? mod : { default: mod };
629
- }
630
- function __classPrivateFieldGet(receiver, state, kind, f) {
631
- if (kind === "a" && !f)
632
- throw new TypeError("Private accessor was defined without a getter");
633
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
634
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
635
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
636
- }
637
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
638
- if (kind === "m")
639
- throw new TypeError("Private method is not writable");
640
- if (kind === "a" && !f)
641
- throw new TypeError("Private accessor was defined without a setter");
642
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
643
- throw new TypeError("Cannot write private member to an object whose class did not declare it");
644
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
645
- }
646
-
647
- /**
648
- * Returns all the entities are distinct by the
649
- * `property` value argument.
650
- *
651
- * Note that the implementation uses a `Map<string, E>` to
652
- * index the entities by key. Therefore the more recent occurences
653
- * matching a key instance will overwrite the previous ones.
654
- *
655
- * @param property The name of the property to check for distinct values by.
656
- * @param entities The entities in the array.
657
- *
658
- * @example
659
- ```
660
- let todos: Todo[] = [
661
- { id: 1, title: "Lets do it!" },
662
- { id: 1, title: "Lets do it again!" },
663
- { id: 2, title: "All done!" }
664
- ];
665
-
666
- let todos2: Todo[] = [
667
- { id: 1, title: "Lets do it!" },
668
- { id: 2, title: "All done!" }
669
- ];
670
-
671
- expect(distinct(todos, "id").length).toEqual(2);
672
- expect(distinct(todos2, "id").length).toEqual(2);
673
-
674
- ```
675
- */
676
- function distinct(entities, property) {
677
- var entitiesByProperty = new Map(entities.map(function (e) { return [e[property], e]; }));
678
- return Array.from(entitiesByProperty.values());
679
- }
680
- /**
681
- * Returns true if all the entities are distinct by the
682
- * `property` value argument.
683
- *
684
- * @param property The name of the property to check for distinct values by.
685
- * @param entities The entities in the array.
686
- *
687
- * @example
688
- *
689
- ```
690
- let todos: Todo[] = [
691
- { id: 1, title: "Lets do it!" },
692
- { id: 1, title: "Lets do it again!" },
693
- { id: 2, title: "All done!" }
694
- ];
695
-
696
- let todos2: Todo[] = [
697
- { id: 1, title: "Lets do it!" },
698
- { id: 2, title: "All done!" }
699
- ];
700
-
701
- expect(unique(todos, "id")).toBeFalsy();
702
- expect(unique(todos2, "id")).toBeTruthy();
703
- ```
704
- */
705
- function unique(entities, property) {
706
- return entities.length == distinct(entities, property).length ? true : false;
707
- }
708
- /**
709
- * Create a global ID
710
- * @return The global id.
711
- *
712
- * @example
713
- * let e.guid = GUID();
714
- */
715
- function GUID() {
716
- return nanoid.nanoid();
717
- }
718
- /**
719
- * Set the global identfication property on the instance.
720
- *
721
- * @param e Entity we want to set the global identifier on.
722
- * @param gid The name of the `gid` property. If not specified it defaults to `ESTORE_CONFIG_DEFAULT.guidKey`.
723
- */
724
- function attachGUID(e, gid) {
725
- var guidKey = gid ? gid : ESTORE_CONFIG_DEFAULT.guidKey;
726
- var id = nanoid.nanoid();
727
- e[guidKey] = id;
728
- return id;
729
- }
730
- /**
731
- * Set the global identfication property on the instance.
732
- *
733
- * @param e[] Entity array we want to set the global identifiers on.
734
- * @param gid The name of the `gid` property. If not specified it defaults to `gid`.
735
- */
736
- function attachGUIDs(e, gid) {
737
- e.forEach(function (e) {
738
- attachGUID(e, gid);
739
- });
740
- }
741
- /**
742
- * Create a shallow copy of the argument.
743
- * @param o The object to copy
744
- */
745
- function shallowCopy(o) {
746
- return Object.assign({}, o);
747
- }
748
- /**
749
- * Create a deep copy of the argument.
750
- * @param o The object to copy
751
- */
752
- function deepCopy(o) {
753
- return JSON.parse(JSON.stringify(o));
754
- }
755
- /**
756
- * Gets the current active value from the `active`
757
- * Map.
758
- *
759
- * This is used for the scenario where we are managing
760
- * a single active instance. For example
761
- * when selecting a book from a collection of books.
762
- *
763
- * The selected `Book` instance becomes the active value.
764
- *
765
- * @example
766
- * const book:Book = getActiveValue(bookStore.active);
767
- * @param m
768
- */
769
- function getActiveValue(m) {
770
- if (m.size) {
771
- return m.entries().next().value[1];
772
- }
773
- return null;
774
- }
775
- /**
776
- * The method can be used to exclude keys from an instance
777
- * of type `E`.
778
- *
779
- * We can use this to exclude values when searching an object.
780
- *
781
- * @param entity An instance of type E
782
- * @param exclude The keys to exclude
783
- *
784
- * @example
785
- * todo = { id: '1', description: 'Do it!' }
786
- * let keys = excludeKeys<Todo>(todo, ['id]);
787
- * // keys = ['description']
788
- */
789
- function excludeKeys(entity, exclude) {
790
- var keys = Object.keys(entity);
791
- return keys.filter(function (key) {
792
- return exclude.indexOf(key) < 0;
793
- });
794
- }
795
- /**
796
- *
797
- * @param entities The entity to search
798
- * @param exclude Keys to exclude from each entity
799
- *
800
- * @return E[] Array of entities with properties containing the search term.
801
- */
802
- function search(query, entities, exclude) {
803
- if (query === void 0) { query = ''; }
804
- if (exclude === void 0) { exclude = []; }
805
- var isArray = Array.isArray;
806
- query = query.toLowerCase();
807
- return entities.filter(function (e) {
808
- //Do the keys calculation on each instance e:E
809
- //because an instance can have optional parameters,
810
- //and thus we have to check each instance, not just
811
- //the first one in the array.
812
- var keys = excludeKeys(e, exclude);
813
- return keys.some(function (key) {
814
- var value = e[key];
815
- if (!value) {
816
- return false;
817
- }
818
- if (isArray(value)) {
819
- return value.some(function (v) {
820
- return String(v).toLowerCase().includes(query);
821
- });
822
- }
823
- else {
824
- return String(value).toLowerCase().includes(query);
825
- }
826
- });
827
- });
828
- }
829
- /**
830
- * @param scrollable The element being scrolled
831
- * @param debounceMS The number of milliseconds to debounce scroll events
832
- * @param sp The function returning the scroll position coordinates.
833
- * @return A boolean valued observable indicating whether the element is scrolling up or down
834
- */
835
- function scrollingUp(scrollable, debounceMS, sp) {
836
- return rxjs.fromEvent(scrollable, 'scroll').pipe(operators.debounceTime(debounceMS), operators.distinctUntilChanged(), operators.map(function (v) { return sp(); }), operators.pairwise(), operators.switchMap(function (p) {
837
- var y1 = p[0][1];
838
- var y2 = p[1][1];
839
- return y1 - y2 > 0 ? rxjs.of(false) : rxjs.of(true);
840
- }));
841
- }
842
- /**
843
- * Filters the entities properties to the set contained in the
844
- * `keys` array.
845
- *
846
- * @param keys The array of keys that the entity be limited to
847
- * @param entity The entity to map
848
- * @return An entity instance that has only the keys provided in the keys array
849
- */
850
- function mapEntity(keys, entity) {
851
- var result = {};
852
- keys.forEach(function (k) {
853
- result[k] = entity[k];
854
- });
855
- return result;
856
- }
857
-
858
- var isArray = Array.isArray;
859
- var Slice = /** @class */ (function (_super) {
860
- __extends(Slice, _super);
861
- /**
862
- * perform initial notification to all observers,
863
- * such that operations like {@link combineLatest}{}
864
- * will execute at least once.
865
- *
866
- * @param label The slice label
867
- * @param predicate The slice predicate
868
- * @param eStore The EStore instance containing the elements considered for slicing
869
- *
870
- * @example
871
- <pre>
872
- //Empty slice
873
- new Slice<Todo>(Todo.COMPLETE, todo=>!todo.complete);
874
-
875
- //Initialized slice
876
- let todos = [new Todo(false, "You complete me!"),
877
- new Todo(true, "You completed me!")];
878
- new Slice<Todo>(Todo.COMPLETE, todo=>!todo.complete, todos);
879
- </pre>
880
- */
881
- function Slice(label, predicate, eStore) {
882
- var _this = _super.call(this) || this;
883
- _this.label = label;
884
- _this.predicate = predicate;
885
- _this.eStore = eStore;
886
- /* The slice element entries */
887
- _this.entries = new Map();
888
- var entities = eStore.allSnapshot();
889
- _this.config = eStore.config;
890
- var passed = _this.test(predicate, entities);
891
- var delta = { type: "Initialize" /* INTIALIZE */, entries: passed };
892
- _this.post(passed);
893
- _this.notifyDelta.next(delta);
894
- return _this;
895
- }
896
- /**
897
- * Add the element if it satisfies the predicate
898
- * and notify subscribers that an element was added.
899
- *
900
- * @param e The element to be considered for slicing
901
- */
902
- Slice.prototype.post = function (e) {
903
- if (isArray(e)) {
904
- this.postA(e);
905
- }
906
- else {
907
- if (this.predicate(e)) {
908
- var id = e[this.config.guidKey];
909
- this.entries.set(id, e);
910
- var delta = { type: "Post" /* POST */, entries: [e] };
911
- this.notifyAll(__spreadArray([], __read(Array.from(this.entries.values()))), delta);
912
- }
913
- }
914
- };
915
- /**
916
- * Add the elements if they satisfy the predicate
917
- * and notify subscribers that elements were added.
918
- *
919
- * @param e The element to be considered for slicing
920
- */
921
- Slice.prototype.postN = function () {
922
- var e = [];
923
- for (var _i = 0; _i < arguments.length; _i++) {
924
- e[_i] = arguments[_i];
925
- }
926
- this.postA(e);
927
- };
928
- /**
929
- * Add the elements if they satisfy the predicate
930
- * and notify subscribers that elements were added.
931
- *
932
- * @param e The element to be considered for slicing
933
- */
934
- Slice.prototype.postA = function (e) {
935
- var _this = this;
936
- var d = [];
937
- e.forEach(function (e) {
938
- if (_this.predicate(e)) {
939
- var id = e[_this.config.guidKey];
940
- _this.entries.set(id, e);
941
- d.push(e);
942
- }
943
- });
944
- var delta = { type: "Post" /* POST */, entries: d };
945
- this.notifyAll(__spreadArray([], __read(Array.from(this.entries.values()))), delta);
946
- };
947
- /**
948
- * Delete an element from the slice.
949
- *
950
- * @param e The element to be deleted if it satisfies the predicate
951
- */
952
- Slice.prototype.delete = function (e) {
953
- if (isArray(e)) {
954
- this.deleteA(e);
955
- }
956
- else {
957
- if (this.predicate(e)) {
958
- var id = e[this.config.guidKey];
959
- this.entries.delete(id);
960
- var delta = { type: "Delete" /* DELETE */, entries: [e] };
961
- this.notifyAll(Array.from(this.entries.values()), delta);
962
- }
963
- }
964
- };
965
- /**
966
- * @param e The elements to be deleted if it satisfies the predicate
967
- */
968
- Slice.prototype.deleteN = function () {
969
- var e = [];
970
- for (var _i = 0; _i < arguments.length; _i++) {
971
- e[_i] = arguments[_i];
972
- }
973
- this.deleteA(e);
974
- };
975
- /**
976
- * @param e The elements to be deleted if they satisfy the predicate
977
- */
978
- Slice.prototype.deleteA = function (e) {
979
- var _this = this;
980
- var d = [];
981
- e.forEach(function (e) {
982
- if (_this.predicate(e)) {
983
- var id = e[_this.config.guidKey];
984
- d.push(_this.entries.get(id));
985
- _this.entries.delete(id);
986
- }
987
- });
988
- var delta = { type: "Delete" /* DELETE */, entries: d };
989
- this.notifyAll(__spreadArray([], __read(Array.from(this.entries.values()))), delta);
990
- };
991
- /**
992
- * Update the slice when an Entity instance mutates.
993
- *
994
- * @param e The element to be added or deleted depending on predicate reevaluation
995
- */
996
- Slice.prototype.put = function (e) {
997
- if (isArray(e)) {
998
- this.putA(e);
999
- }
1000
- else {
1001
- var id = e[this.config.guidKey];
1002
- if (this.entries.get(id)) {
1003
- if (!this.predicate(e)) {
1004
- //Note that this is a ActionTypes.DELETE because we are removing the
1005
- //entity from the slice.
1006
- var delta = { type: "Delete" /* DELETE */, entries: [e] };
1007
- this.entries.delete(id);
1008
- this.notifyAll(__spreadArray([], __read(Array.from(this.entries.values()))), delta);
1009
- }
1010
- }
1011
- else if (this.predicate(e)) {
1012
- this.entries.set(id, e);
1013
- var delta = { type: "Put" /* PUT */, entries: [e] };
1014
- this.notifyAll(__spreadArray([], __read(Array.from(this.entries.values()))), delta);
1015
- }
1016
- }
1017
- };
1018
- /**
1019
- * Update the slice with mutated Entity instances.
1020
- *
1021
- * @param e The elements to be deleted if it satisfies the predicate
1022
- */
1023
- Slice.prototype.putN = function () {
1024
- var e = [];
1025
- for (var _i = 0; _i < arguments.length; _i++) {
1026
- e[_i] = arguments[_i];
1027
- }
1028
- this.putA(e);
1029
- };
1030
- /**
1031
- * @param e The elements to be put
1032
- */
1033
- Slice.prototype.putA = function (e) {
1034
- var _this = this;
1035
- var d = []; //instances to delete
1036
- var u = []; //instances to update
1037
- e.forEach(function (e) {
1038
- var id = e[_this.config.guidKey];
1039
- if (_this.entries.get(id)) {
1040
- if (!_this.predicate(e)) {
1041
- d.push(_this.entries.get(id));
1042
- }
1043
- }
1044
- else if (_this.predicate(e)) {
1045
- u.push(e);
1046
- }
1047
- });
1048
- if (d.length > 0) {
1049
- d.forEach(function (e) {
1050
- _this.entries.delete(e[_this.config.guidKey]);
1051
- });
1052
- var delta = { type: "Delete" /* DELETE */, entries: d };
1053
- this.notifyAll(__spreadArray([], __read(Array.from(this.entries.values()))), delta);
1054
- }
1055
- if (u.length > 0) {
1056
- u.forEach(function (e) {
1057
- _this.entries.set(e[_this.config.guidKey], e);
1058
- });
1059
- var delta = { type: "Put" /* PUT */, entries: u };
1060
- this.notifyAll(__spreadArray([], __read(Array.from(this.entries.values()))), delta);
1061
- }
1062
- };
1063
- /**
1064
- * Resets the slice to empty.
1065
- */
1066
- Slice.prototype.reset = function () {
1067
- var delta = {
1068
- type: "Reset" /* RESET */,
1069
- entries: __spreadArray([], __read(Array.from(this.entries.values())))
1070
- };
1071
- this.notifyAll([], delta);
1072
- this.entries = new Map();
1073
- };
1074
- /**
1075
- * Utility method that applies the predicate to an array
1076
- * of entities and return the ones that pass the test.
1077
- *
1078
- * Used to create an initial set of values
1079
- * that should be part of the `Slice`.
1080
- *
1081
- * @param p
1082
- * @param e
1083
- * @return The the array of entities that pass the predicate test.
1084
- */
1085
- Slice.prototype.test = function (p, e) {
1086
- var v = [];
1087
- e.forEach(function (e) {
1088
- if (p(e)) {
1089
- v.push(e);
1090
- }
1091
- });
1092
- return v;
1093
- };
1094
- return Slice;
1095
- }(AbstractStore));
1096
-
1097
- /**
1098
- * This `todoFactory` code will be used to illustrate the API examples. The following
1099
- * utilities are used in the tests and the API Typedoc examples contained here.
1100
- * @example Utilities for API Examples
1101
- ```
1102
- export const enum TodoSliceEnum {
1103
- COMPLETE = "Complete",
1104
- INCOMPLETE = "Incomplete"
1105
- }
1106
-
1107
- export class Todo {
1108
- constructor(public complete: boolean, public title: string,public gid?:string, public id?:string) {}
1109
- }
1110
-
1111
- export let todos = [new Todo(false, "You complete me!"), new Todo(true, "You completed me!")];
1112
-
1113
- export function todosFactory():Todo[] {
1114
- return [new Todo(false, "You complete me!"), new Todo(true, "You completed me!")];
1115
- }
1116
- ```
1117
- */
1118
- var EStore = /** @class */ (function (_super) {
1119
- __extends(EStore, _super);
1120
- /**
1121
- * Store constructor (Initialization with element is optional)
1122
- *
1123
- * perform initial notification to all observers,
1124
- * such that function like {@link combineLatest}{}
1125
- * will execute at least once.
1126
- * @param entities
1127
- * @example Dynamic `EStore<Todo>` Creation
1128
- ```
1129
- // Initialize the Store
1130
- let store: EStore<Todo> = new EStore<Todo>(todosFactory());
1131
- ```*/
1132
- function EStore(entities, config) {
1133
- if (entities === void 0) { entities = []; }
1134
- var _this = _super.call(this, config) || this;
1135
- /**
1136
- * Notifies observers when the store is empty.
1137
- */
1138
- _this.notifyActive = new rxjs.ReplaySubject(1);
1139
- /**
1140
- * `Map` of active entties. The instance is public and can be used
1141
- * directly to add and remove active entities, however we recommend
1142
- * using the {@link addActive} and {@link deleteActive} methods.
1143
- */
1144
- _this.active = new Map();
1145
- /**
1146
- * Notifies observers when the store is loading.
1147
- *
1148
- * This is a common pattern found when implementing
1149
- * `Observable` data sources.
1150
- */
1151
- _this.notifyLoading = new rxjs.ReplaySubject(1);
1152
- /**
1153
- * The current loading state. Use loading when fetching new
1154
- * data for the store. The default loading state is `true`.
1155
- *
1156
- * This is such that if data is fetched asynchronously
1157
- * in a service, components can wait on loading notification
1158
- * before attempting to retrieve data from the service.
1159
- *
1160
- * Loading could be based on a composite response. For example
1161
- * when the stock and mutual funds have loaded, set loading to `false`.
1162
- */
1163
- _this._loading = true;
1164
- /**
1165
- * Notifies observers that a search is in progress.
1166
- *
1167
- * This is a common pattern found when implementing
1168
- * `Observable` data sources.
1169
- */
1170
- _this.notifySearching = new rxjs.ReplaySubject(1);
1171
- /**
1172
- * The current `searching` state. Use `searching`
1173
- * for example to display a spinnner
1174
- * when performing a search.
1175
- * The default `searching` state is `false`.
1176
- */
1177
- _this._searching = false;
1178
- /**
1179
- * Store slices
1180
- */
1181
- _this.slices = new Map();
1182
- var delta = { type: "Initialize" /* INTIALIZE */, entries: entities };
1183
- _this.post(entities);
1184
- _this.notifyDelta.next(delta);
1185
- return _this;
1186
- }
1187
- /**
1188
- * Calls complete on all {@link BehaviorSubject} instances.
1189
- *
1190
- * Call destroy when disposing of the store.
1191
- */
1192
- EStore.prototype.destroy = function () {
1193
- _super.prototype.destroy.call(this);
1194
- this.notifyLoading.complete();
1195
- this.notifyActive.complete();
1196
- this.slices.forEach(function (slice) { return slice.destroy(); });
1197
- };
1198
- /**
1199
- * Toggles the entity:
1200
- *
1201
- * If the store contains the entity
1202
- * it will be deleted. If the store
1203
- * does not contains the entity,
1204
- * it is added.
1205
- * @param e
1206
- * @example Toggle the `Todo` instance
1207
- ```
1208
- estore.post(todo);
1209
- // Remove todo
1210
- estore.toggle(todo);
1211
- // Add it back
1212
- estore.toggle(todo);
1213
-
1214
- ```
1215
- */
1216
- EStore.prototype.toggle = function (e) {
1217
- if (this.contains(e)) {
1218
- this.delete(e);
1219
- }
1220
- else {
1221
- this.post(e);
1222
- }
1223
- };
1224
- /**
1225
- * Add multiple entity entities to active.
1226
- *
1227
- * If the entity is not contained in the store it is added
1228
- * to the store before it is added to `active`.
1229
- *
1230
- * Also we clone the map prior to broadcasting it with
1231
- * `notifyActive` to make sure we will trigger Angular
1232
- * change detection in the event that it maintains
1233
- * a reference to the `active` state `Map` instance.
1234
- *
1235
- * @example Add a `todo1` and `todo2` as active
1236
- ```
1237
- addActive(todo1);
1238
- addActive(todo2);
1239
- ```
1240
- */
1241
- EStore.prototype.addActive = function (e) {
1242
- if (this.contains(e)) {
1243
- this.active.set(e.gid, e);
1244
- this.notifyActive.next(new Map(this.active));
1245
- }
1246
- else {
1247
- this.post(e);
1248
- this.active.set(e.gid, e);
1249
- this.notifyActive.next(new Map(this.active));
1250
- }
1251
- };
1252
- /**
1253
- * Delete an entity as active.
1254
- *
1255
- * Also we clone the map prior to broadcasting it with
1256
- * `notifyActive` to make sure we will trigger Angular
1257
- * change detection in the event that it maintains
1258
- * a reference to the `active` state `Map` instance.
1259
- *
1260
- * @example Mark a `todo` instance as active
1261
- ```
1262
- deleteActive(todo1);
1263
- deleteActive(todo2);
1264
- ```
1265
- */
1266
- EStore.prototype.deleteActive = function (e) {
1267
- this.active.delete(e.gid);
1268
- this.notifyActive.next(new Map(this.active));
1269
- };
1270
- /**
1271
- * Clear / reset the active entity map.
1272
- *
1273
- * Also we clone the map prior to broadcasting it with
1274
- * `notifyActive` to make sure we will trigger Angular
1275
- * change detection in the event that it maintains
1276
- * a reference to the `active` state `Map` instance.
1277
- *
1278
- * @example Mark a `todo` instance as active
1279
- ```
1280
- deleteActive(todo1);
1281
- deleteActive(todo2);
1282
- ```
1283
- */
1284
- EStore.prototype.clearActive = function () {
1285
- this.active.clear();
1286
- this.notifyActive.next(new Map(this.active));
1287
- };
1288
- /**
1289
- * Observe the active entity.
1290
- * @example
1291
- <pre>
1292
- let active$ = source.observeActive();
1293
- </pre>
1294
- */
1295
- EStore.prototype.observeActive = function () {
1296
- return this.notifyActive.asObservable();
1297
- };
1298
- /**
1299
- * Observe the active entity.
1300
- * @example
1301
- <pre>
1302
- let active$ = source.activeSnapshot();
1303
- </pre>
1304
- */
1305
- EStore.prototype.activeSnapshot = function () {
1306
- return Array.from(this.active.values());
1307
- };
1308
- Object.defineProperty(EStore.prototype, "loading", {
1309
- /**
1310
- * @return A snapshot of the loading state.
1311
- */
1312
- get: function () {
1313
- return this._loading;
1314
- },
1315
- /**
1316
- * Sets the current loading state and notifies observers.
1317
- */
1318
- set: function (loading) {
1319
- this._loading = loading;
1320
- this.notifyLoading.next(this._loading);
1321
- },
1322
- enumerable: false,
1323
- configurable: true
1324
- });
1325
- /**
1326
- * Observe loading.
1327
- * @example
1328
- <pre>
1329
- let loading$ = source.observeLoading();
1330
- </pre>
1331
-
1332
- Note that this obverable piped through
1333
- `takeWhile(v->v, true), such that it will
1334
- complete after each emission.
1335
-
1336
- See:
1337
- https://medium.com/@ole.ersoy/waiting-on-estore-to-load-8dcbe161613c
1338
-
1339
- For more details.
1340
- */
1341
- EStore.prototype.observeLoading = function () {
1342
- return this.notifyLoading.asObservable().
1343
- pipe(operators.takeWhile(function (v) { return v; }, true));
1344
- };
1345
- /**
1346
- * Notfiies when loading has completed.
1347
- */
1348
- EStore.prototype.observeLoadingComplete = function () {
1349
- return this.observeLoading().pipe(operators.filter(function (loading) { return loading == false; }), operators.switchMap(function () { return rxjs.of(true); }));
1350
- };
1351
- Object.defineProperty(EStore.prototype, "searching", {
1352
- /**
1353
- * @return A snapshot of the searching state.
1354
- */
1355
- get: function () {
1356
- return this._searching;
1357
- },
1358
- /**
1359
- * Sets the current searching state and notifies observers.
1360
- */
1361
- set: function (searching) {
1362
- this._searching = searching;
1363
- this.notifySearching.next(this._searching);
1364
- },
1365
- enumerable: false,
1366
- configurable: true
1367
- });
1368
- /**
1369
- * Observe searching.
1370
- * @example
1371
- <pre>
1372
- let searching$ = source.observeSearching();
1373
- </pre>
1374
-
1375
- Note that this obverable piped through
1376
- `takeWhile(v->v, true), such that it will
1377
- complete after each emission.
1378
-
1379
- See:
1380
- https://medium.com/@ole.ersoy/waiting-on-estore-to-load-8dcbe161613c
1381
-
1382
- For more details.
1383
- */
1384
- EStore.prototype.observeSearching = function () {
1385
- return this.notifySearching.asObservable().
1386
- pipe(operators.takeWhile(function (v) { return v; }, true));
1387
- };
1388
- /**
1389
- * Notfiies when searching has completed.
1390
- */
1391
- EStore.prototype.observeSearchingComplete = function () {
1392
- return this.observeSearching().pipe(operators.filter(function (searching) { return searching == false; }), operators.switchMap(function () { return rxjs.of(true); }));
1393
- };
1394
- /**
1395
- * Adds a slice to the store and keys it by the slices label.
1396
- *
1397
- * @param p
1398
- * @param label
1399
- *
1400
- * @example Setup a Todo Slice for COMPLETE Todos
1401
- ```
1402
- source.addSlice(todo => todo.complete, TodoSlices.COMPLETE);
1403
- ```
1404
- */
1405
- EStore.prototype.addSlice = function (p, label) {
1406
- var slice = new Slice(label, p, this);
1407
- this.slices.set(slice.label, slice);
1408
- };
1409
- /**
1410
- * Remove a slice
1411
- * @param label The label identifying the slice
1412
- *
1413
- * @example Remove the TodoSlices.COMPLETE Slice
1414
- ```
1415
- source.removeSlice(TodoSlices.COMPLETE);
1416
- ```
1417
- */
1418
- EStore.prototype.removeSlice = function (label) {
1419
- this.slices.delete(label);
1420
- };
1421
- /**
1422
- * Get a slice
1423
- * @param label The label identifying the slice
1424
- * @return The Slice instance or undefined
1425
- *
1426
- * @example Get the TodoSlices.COMPLETE slice
1427
- ```
1428
- source.getSlice(TodoSlices.COMPLETE);
1429
- ```
1430
- */
1431
- EStore.prototype.getSlice = function (label) {
1432
- return this.slices.get(label);
1433
- };
1434
- /**
1435
- * Post (Add a new) element(s) to the store.
1436
- * @param e An indiidual entity or an array of entities
1437
- * @example Post a `todo`.
1438
- ```
1439
- store.post(todo);
1440
- ```
1441
- */
1442
- EStore.prototype.post = function (e) {
1443
- if (!Array.isArray(e)) {
1444
- var guid = e[this.GUID_KEY]
1445
- ? e[this.GUID_KEY]
1446
- : GUID();
1447
- e[this.GUID_KEY] = guid;
1448
- this.entries.set(guid, e);
1449
- this.updateIDEntry(e);
1450
- Array.from(this.slices.values()).forEach(function (s) {
1451
- s.post(e);
1452
- });
1453
- //Create a new array reference to trigger Angular change detection.
1454
- var v = __spreadArray([], __read(Array.from(this.entries.values())));
1455
- var delta = { type: "Post" /* POST */, entries: [e] };
1456
- this.notifyAll(v, delta);
1457
- }
1458
- else {
1459
- this.postA(e);
1460
- }
1461
- };
1462
- /**
1463
- * Post elements to the store.
1464
- * @param ...e
1465
- * @example Post two `Todo` instances.
1466
- ```
1467
- store.post(todo1, todo2);
1468
- ```
1469
- */
1470
- EStore.prototype.postN = function () {
1471
- var _this = this;
1472
- var e = [];
1473
- for (var _i = 0; _i < arguments.length; _i++) {
1474
- e[_i] = arguments[_i];
1475
- }
1476
- e.forEach(function (e) {
1477
- var guid = e[_this.GUID_KEY]
1478
- ? e[_this.GUID_KEY]
1479
- : GUID();
1480
- e[_this.GUID_KEY] = guid;
1481
- _this.entries.set(guid, e);
1482
- _this.updateIDEntry(e);
1483
- });
1484
- Array.from(this.slices.values()).forEach(function (s) {
1485
- s.postA(e);
1486
- });
1487
- //Create a new array reference to trigger Angular change detection.
1488
- var v = __spreadArray([], __read(Array.from(this.entries.values())));
1489
- var delta = { type: "Post" /* POST */, entries: e };
1490
- this.notifyAll(v, delta);
1491
- };
1492
- /**
1493
- * Post (Add) an array of elements to the store.
1494
- * @param e
1495
- * @example Post a `Todo` array.
1496
- ```
1497
- store.post([todo1, todo2]);
1498
- ```
1499
- */
1500
- EStore.prototype.postA = function (e) {
1501
- this.postN.apply(this, __spreadArray([], __read(e)));
1502
- };
1503
- /**
1504
- * Put (Update) an element.
1505
- * @param e
1506
- * @example Put a Todo instance.
1507
- ```
1508
- store.put(todo1);
1509
- ```
1510
- */
1511
- EStore.prototype.put = function (e) {
1512
- if (!Array.isArray(e)) {
1513
- var id = e[this.GUID_KEY];
1514
- this.entries.set(id, e);
1515
- this.updateIDEntry(e);
1516
- var v = __spreadArray([], __read(Array.from(this.entries.values())));
1517
- this.notify.next(v);
1518
- var delta = { type: "Put" /* PUT */, entries: [e] };
1519
- this.notifyDelta.next(delta);
1520
- Array.from(this.slices.values()).forEach(function (s) {
1521
- s.put(e);
1522
- });
1523
- }
1524
- else {
1525
- this.putA(e);
1526
- }
1527
- };
1528
- /**
1529
- * Put (Update) an element or add an element that was read from a persistence source
1530
- * and thus already has an assigned global id`.
1531
- * @param e
1532
- * @example Put Todo instances.
1533
- ```
1534
- store.put(todo1, todo2);
1535
- ```
1536
- */
1537
- EStore.prototype.putN = function () {
1538
- var e = [];
1539
- for (var _i = 0; _i < arguments.length; _i++) {
1540
- e[_i] = arguments[_i];
1541
- }
1542
- this.putA(e);
1543
- };
1544
- /**
1545
- * Put (Update) the array of elements.
1546
- * @param e
1547
- * @example Put Todo instances.
1548
- ```
1549
- store.put([todo1, todo2]);
1550
- ```
1551
- */
1552
- EStore.prototype.putA = function (e) {
1553
- var _this = this;
1554
- e.forEach(function (e) {
1555
- var guid = e[_this.GUID_KEY];
1556
- _this.entries.set(guid, e);
1557
- _this.updateIDEntry(e);
1558
- });
1559
- //Create a new array reference to trigger Angular change detection.
1560
- var v = __spreadArray([], __read(Array.from(this.entries.values())));
1561
- this.notify.next(v);
1562
- var delta = { type: "Put" /* PUT */, entries: e };
1563
- this.notifyDelta.next(delta);
1564
- Array.from(this.slices.values()).forEach(function (s) {
1565
- s.putA(e);
1566
- });
1567
- };
1568
- /**
1569
- * Delete (Update) the array of elements.
1570
- * @param e
1571
- * @example Delete todo1.
1572
- ```
1573
- store.delete(todo1]);
1574
- ```
1575
- */
1576
- EStore.prototype.delete = function (e) {
1577
- if (!Array.isArray(e)) {
1578
- this.deleteActive(e);
1579
- var guid_1 = e[this.GUID_KEY];
1580
- this.entries.delete(guid_1);
1581
- this.deleteIDEntry(e);
1582
- Array.from(this.slices.values()).forEach(function (s) {
1583
- s.entries.delete(guid_1);
1584
- });
1585
- //Create a new array reference to trigger Angular change detection.
1586
- var v = __spreadArray([], __read(Array.from(this.entries.values())));
1587
- var delta = { type: "Delete" /* DELETE */, entries: [e] };
1588
- this.notifyAll(v, delta);
1589
- Array.from(this.slices.values()).forEach(function (s) {
1590
- s.delete(e);
1591
- });
1592
- }
1593
- else {
1594
- this.deleteA(e);
1595
- }
1596
- };
1597
- /**
1598
- * Delete N elements.
1599
- * @param ...e
1600
- * @example Put Todo instances.
1601
- ```
1602
- store.delete(todo1, todo2);
1603
- ```
1604
- */
1605
- EStore.prototype.deleteN = function () {
1606
- var e = [];
1607
- for (var _i = 0; _i < arguments.length; _i++) {
1608
- e[_i] = arguments[_i];
1609
- }
1610
- this.deleteA(e);
1611
- };
1612
- /**
1613
- * Delete N elements.
1614
- * @param ...e
1615
- * @example Put Todo instances.
1616
- ```
1617
- store.delete(todo1, todo2);
1618
- ```
1619
- */
1620
- EStore.prototype.deleteA = function (e) {
1621
- var _this = this;
1622
- e.forEach(function (e) {
1623
- _this.deleteActive(e);
1624
- var guid = e[_this.GUID_KEY];
1625
- _this.entries.delete(guid);
1626
- _this.deleteIDEntry(e);
1627
- Array.from(_this.slices.values()).forEach(function (s) {
1628
- s.entries.delete(guid);
1629
- });
1630
- });
1631
- //Create a new array reference to trigger Angular change detection.
1632
- var v = __spreadArray([], __read(Array.from(this.entries.values())));
1633
- var delta = { type: "Delete" /* DELETE */, entries: e };
1634
- this.notifyAll(v, delta);
1635
- Array.from(this.slices.values()).forEach(function (s) {
1636
- s.deleteA(e);
1637
- });
1638
- };
1639
- /**
1640
- * Delete elements by {@link Predicate}.
1641
- * @param p The predicate.
1642
- * @example Put Todo instances.
1643
- ```
1644
- store.delete(todo1, todo2);
1645
- ```
1646
- */
1647
- EStore.prototype.deleteP = function (p) {
1648
- var _this = this;
1649
- var d = [];
1650
- Array.from(this.entries.values()).forEach(function (e) {
1651
- if (p(e)) {
1652
- d.push(e);
1653
- var id = e[_this.GUID_KEY];
1654
- _this.entries.delete(id);
1655
- _this.deleteActive(e);
1656
- _this.deleteIDEntry(e);
1657
- }
1658
- });
1659
- //Create a new array reference to trigger Angular change detection.
1660
- var v = __spreadArray([], __read(Array.from(this.entries.values())));
1661
- var delta = { type: "Delete" /* DELETE */, entries: d };
1662
- this.notifyAll(v, delta);
1663
- Array.from(this.slices.values()).forEach(function (s) {
1664
- s.deleteA(d);
1665
- });
1666
- };
1667
- /**
1668
- * If the entity has the `id` key initialized with a value,
1669
- * then also add the entity to the `idEntries`.
1670
- *
1671
- * @param e The element to be added to the `idEntries`.
1672
- */
1673
- EStore.prototype.updateIDEntry = function (e) {
1674
- if (e[this.ID_KEY]) {
1675
- this.idEntries.set(e[this.ID_KEY], e);
1676
- }
1677
- };
1678
- /**
1679
- * If the entity has the `id` key initialized with a value,
1680
- * then also delete the entity to the `idEntries`.
1681
- *
1682
- * @param e The element to be added to the `idEntries`.
1683
- */
1684
- EStore.prototype.deleteIDEntry = function (e) {
1685
- if (e[this.ID_KEY]) {
1686
- this.idEntries.delete(e[this.ID_KEY]);
1687
- }
1688
- };
1689
- /**
1690
- * Resets the store and all contained slice instances to empty.
1691
- * Also perform delta notification that sends all current store entries.
1692
- * The ActionType.RESET code is sent with the delta notification. Slices
1693
- * send their own delta notification.
1694
- *
1695
- * @example Reset the store.
1696
- ```
1697
- store.reset();
1698
- ```
1699
- */
1700
- EStore.prototype.reset = function () {
1701
- var delta = {
1702
- type: "Reset" /* RESET */,
1703
- entries: Array.from(this.entries.values())
1704
- };
1705
- this.notifyAll([], delta);
1706
- this.entries = new Map();
1707
- Array.from(this.slices.values()).forEach(function (s) {
1708
- s.reset();
1709
- });
1710
- };
1711
- /**
1712
- * Call all the notifiers at once.
1713
- *
1714
- * @param v
1715
- * @param delta
1716
- */
1717
- EStore.prototype.notifyAll = function (v, delta) {
1718
- _super.prototype.notifyAll.call(this, v, delta);
1719
- this.notifyLoading.next(this.loading);
1720
- };
1721
- return EStore;
1722
- }(AbstractStore));
1723
-
1724
- var OStore = /** @class */ (function () {
1725
- function OStore(start) {
1726
- var _this = this;
1727
- /**
1728
- * Map of Key Value pair entries
1729
- * containing values store in this store.
1730
- */
1731
- this.entries = new Map();
1732
- /**
1733
- * Map of replay subject id to `ReplaySubject` instance.
1734
- */
1735
- this.subjects = new Map();
1736
- if (start) {
1737
- this.S = start;
1738
- var keys = Object.keys(start);
1739
- keys.forEach(function (k) {
1740
- var ovr = start[k];
1741
- _this.post(ovr, ovr.value);
1742
- ovr.obs = _this.observe(ovr);
1743
- });
1744
- }
1745
- }
1746
- /**
1747
- * Reset the state of the OStore to the
1748
- * values or reset provided in the constructor
1749
- * {@link OStoreStart} instance.
1750
- */
1751
- OStore.prototype.reset = function () {
1752
- var _this = this;
1753
- if (this.S) {
1754
- var keys = Object.keys(this.S);
1755
- keys.forEach(function (k) {
1756
- var ovr = _this.S[k];
1757
- _this.put(ovr, ovr.reset ? ovr.reset : ovr.value);
1758
- });
1759
- }
1760
- };
1761
- /**
1762
- * Clear all entries
1763
- */
1764
- OStore.prototype.clear = function () {
1765
- this.entries.clear();
1766
- };
1767
- /**
1768
- * Set create a key value pair entry and creates a
1769
- * corresponding replay subject instance that will
1770
- * be used to broadcast updates.
1771
- *
1772
- * @param key The key identifying the value
1773
- * @param value The value
1774
- */
1775
- OStore.prototype.post = function (key, value) {
1776
- this.entries.set(key, value);
1777
- this.subjects.set(key, new rxjs.ReplaySubject(1));
1778
- //Emit immediately so that Observers can receive
1779
- //the value straight away.
1780
- var subject = this.subjects.get(key);
1781
- if (subject) {
1782
- subject.next(value);
1783
- }
1784
- };
1785
- /**
1786
- * Update a value and notify subscribers.
1787
- *
1788
- * @param key
1789
- * @param value
1790
- */
1791
- OStore.prototype.put = function (key, value) {
1792
- this.entries.set(key, value);
1793
- var subject = this.subjects.get(key);
1794
- if (subject) {
1795
- subject.next(value);
1796
- }
1797
- };
1798
- /**
1799
- * Deletes both the value entry and the corresponding {@link ReplaySubject}.
1800
- * Will unsubscribe the {@link ReplaySubject} prior to deleting it,
1801
- * severing communication with corresponding {@link Observable}s.
1802
- *
1803
- * @param key
1804
- */
1805
- OStore.prototype.delete = function (key) {
1806
- this.entries.delete(key);
1807
- this.subjects.delete(key);
1808
- var subject = this.subjects.get(key);
1809
- if (subject) {
1810
- subject.unsubscribe();
1811
- }
1812
- };
1813
- /**
1814
- * Observe changes to the values.
1815
- *
1816
- * @param key
1817
- * @return An {@link Observable} of the value
1818
- */
1819
- OStore.prototype.observe = function (key) {
1820
- return this.subjects.get(key).asObservable();
1821
- };
1822
- /**
1823
- * Check whether a value exists.
1824
- *
1825
- * @param key
1826
- * @return True if the entry exists ( Is not null or undefined ) and false otherwise.
1827
- */
1828
- OStore.prototype.exists = function (key) {
1829
- return this.entries.get(key) != null;
1830
- };
1831
- /**
1832
- * Retrieve a snapshot of the
1833
- * value.
1834
- *
1835
- * @param key
1836
- * @return A snapshot of the value corresponding to the key.
1837
- */
1838
- OStore.prototype.snapshot = function (key) {
1839
- return this.entries.get(key);
1840
- };
1841
- /**
1842
- * Indicates whether the store is empty.
1843
- * @return true if the store is empty, false otherwise.
1844
- */
1845
- OStore.prototype.isEmpty = function () {
1846
- return Array.from(this.entries.values()).length == 0;
1847
- };
1848
- /**
1849
- * Returns the number of key value pairs contained.
1850
- *
1851
- * @return the number of entries in the store.
1852
- */
1853
- OStore.prototype.count = function () {
1854
- return Array.from(this.entries.values()).length;
1855
- };
1856
- return OStore;
1857
- }());
1858
-
1859
- /*
1860
- * Public API Surface of slice
1861
- */
1862
-
1863
- /**
1864
- * Generated bundle index. Do not edit.
1865
- */
1866
-
1867
- exports.AbstractStore = AbstractStore;
1868
- exports.ESTORE_CONFIG_DEFAULT = ESTORE_CONFIG_DEFAULT;
1869
- exports.EStore = EStore;
1870
- exports.Entity = Entity;
1871
- exports.GUID = GUID;
1872
- exports.OStore = OStore;
1873
- exports.SCROLL_UP_DEBOUNCE_TIME_20 = SCROLL_UP_DEBOUNCE_TIME_20;
1874
- exports.SEARCH_DEBOUNCE_TIME_300 = SEARCH_DEBOUNCE_TIME_300;
1875
- exports.Slice = Slice;
1876
- exports.attachGUID = attachGUID;
1877
- exports.attachGUIDs = attachGUIDs;
1878
- exports.deepCopy = deepCopy;
1879
- exports.distinct = distinct;
1880
- exports.excludeKeys = excludeKeys;
1881
- exports.getActiveValue = getActiveValue;
1882
- exports.mapEntity = mapEntity;
1883
- exports.scrollingUp = scrollingUp;
1884
- exports.search = search;
1885
- exports.shallowCopy = shallowCopy;
1886
- exports.unique = unique;
1887
-
1888
- Object.defineProperty(exports, '__esModule', { value: true });
1889
-
1890
- })));
1891
- //# sourceMappingURL=fireflysemantics-slice.umd.js.map