@fireflysemantics/slice 15.0.19 → 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 (29) hide show
  1. package/esm2020/lib/AbstractStore.mjs +296 -0
  2. package/{esm2015/lib/EStore.js → esm2020/lib/EStore.mjs} +10 -10
  3. package/esm2020/lib/Slice.mjs +222 -0
  4. package/esm2020/lib/utilities.mjs +226 -0
  5. package/{esm2015/public-api.js → esm2020/public-api.mjs} +1 -1
  6. package/fesm2015/{fireflysemantics-slice.js → fireflysemantics-slice.mjs} +20 -20
  7. package/fesm2015/fireflysemantics-slice.mjs.map +1 -0
  8. package/fesm2020/fireflysemantics-slice.mjs +1494 -0
  9. package/fesm2020/fireflysemantics-slice.mjs.map +1 -0
  10. package/lib/models/Predicate.d.ts +1 -1
  11. package/lib/models/scrollPosition.d.ts +1 -1
  12. package/package.json +22 -9
  13. package/bundles/fireflysemantics-slice.umd.js +0 -1905
  14. package/bundles/fireflysemantics-slice.umd.js.map +0 -1
  15. package/esm2015/lib/AbstractStore.js +0 -296
  16. package/esm2015/lib/Slice.js +0 -222
  17. package/esm2015/lib/utilities.js +0 -226
  18. package/fesm2015/fireflysemantics-slice.js.map +0 -1
  19. /package/{esm2015/fireflysemantics-slice.js → esm2020/fireflysemantics-slice.mjs} +0 -0
  20. /package/{esm2015/lib/OStore.js → esm2020/lib/OStore.mjs} +0 -0
  21. /package/{esm2015/lib/models/ActionTypes.js → esm2020/lib/models/ActionTypes.mjs} +0 -0
  22. /package/{esm2015/lib/models/Delta.js → esm2020/lib/models/Delta.mjs} +0 -0
  23. /package/{esm2015/lib/models/Entity.js → esm2020/lib/models/Entity.mjs} +0 -0
  24. /package/{esm2015/lib/models/Predicate.js → esm2020/lib/models/Predicate.mjs} +0 -0
  25. /package/{esm2015/lib/models/StoreConfig.js → esm2020/lib/models/StoreConfig.mjs} +0 -0
  26. /package/{esm2015/lib/models/constants.js → esm2020/lib/models/constants.mjs} +0 -0
  27. /package/{esm2015/lib/models/index.js → esm2020/lib/models/index.mjs} +0 -0
  28. /package/{esm2015/lib/models/scrollPosition.js → esm2020/lib/models/scrollPosition.mjs} +0 -0
  29. /package/{fireflysemantics-slice.d.ts → index.d.ts} +0 -0
@@ -1,1905 +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
- * Returns an `Observable<E>` instance that
859
- * filters for arguments where the property
860
- * value matches the provided value.
861
- *
862
- * @param value The value targeted
863
- * @param propertyName The name of the property to contain the value
864
- * @param obs The Slice Object Store Observable
865
- * @returns Observable<E>
866
- */
867
- function onFilteredEvent(value, propertyName, obs) {
868
- return obs.pipe(operators.filter(function (e) { return !!(e && e[propertyName] === value); }));
869
- }
870
-
871
- var isArray = Array.isArray;
872
- var Slice = /** @class */ (function (_super) {
873
- __extends(Slice, _super);
874
- /**
875
- * perform initial notification to all observers,
876
- * such that operations like {@link combineLatest}{}
877
- * will execute at least once.
878
- *
879
- * @param label The slice label
880
- * @param predicate The slice predicate
881
- * @param eStore The EStore instance containing the elements considered for slicing
882
- *
883
- * @example
884
- <pre>
885
- //Empty slice
886
- new Slice<Todo>(Todo.COMPLETE, todo=>!todo.complete);
887
-
888
- //Initialized slice
889
- let todos = [new Todo(false, "You complete me!"),
890
- new Todo(true, "You completed me!")];
891
- new Slice<Todo>(Todo.COMPLETE, todo=>!todo.complete, todos);
892
- </pre>
893
- */
894
- function Slice(label, predicate, eStore) {
895
- var _this = _super.call(this) || this;
896
- _this.label = label;
897
- _this.predicate = predicate;
898
- _this.eStore = eStore;
899
- /* The slice element entries */
900
- _this.entries = new Map();
901
- var entities = eStore.allSnapshot();
902
- _this.config = eStore.config;
903
- var passed = _this.test(predicate, entities);
904
- var delta = { type: "Initialize" /* INTIALIZE */, entries: passed };
905
- _this.post(passed);
906
- _this.notifyDelta.next(delta);
907
- return _this;
908
- }
909
- /**
910
- * Add the element if it satisfies the predicate
911
- * and notify subscribers that an element was added.
912
- *
913
- * @param e The element to be considered for slicing
914
- */
915
- Slice.prototype.post = function (e) {
916
- if (isArray(e)) {
917
- this.postA(e);
918
- }
919
- else {
920
- if (this.predicate(e)) {
921
- var id = e[this.config.guidKey];
922
- this.entries.set(id, e);
923
- var delta = { type: "Post" /* POST */, entries: [e] };
924
- this.notifyAll(__spreadArray([], __read(Array.from(this.entries.values()))), delta);
925
- }
926
- }
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.postN = function () {
935
- var e = [];
936
- for (var _i = 0; _i < arguments.length; _i++) {
937
- e[_i] = arguments[_i];
938
- }
939
- this.postA(e);
940
- };
941
- /**
942
- * Add the elements if they satisfy the predicate
943
- * and notify subscribers that elements were added.
944
- *
945
- * @param e The element to be considered for slicing
946
- */
947
- Slice.prototype.postA = function (e) {
948
- var _this = this;
949
- var d = [];
950
- e.forEach(function (e) {
951
- if (_this.predicate(e)) {
952
- var id = e[_this.config.guidKey];
953
- _this.entries.set(id, e);
954
- d.push(e);
955
- }
956
- });
957
- var delta = { type: "Post" /* POST */, entries: d };
958
- this.notifyAll(__spreadArray([], __read(Array.from(this.entries.values()))), delta);
959
- };
960
- /**
961
- * Delete an element from the slice.
962
- *
963
- * @param e The element to be deleted if it satisfies the predicate
964
- */
965
- Slice.prototype.delete = function (e) {
966
- if (isArray(e)) {
967
- this.deleteA(e);
968
- }
969
- else {
970
- if (this.predicate(e)) {
971
- var id = e[this.config.guidKey];
972
- this.entries.delete(id);
973
- var delta = { type: "Delete" /* DELETE */, entries: [e] };
974
- this.notifyAll(Array.from(this.entries.values()), delta);
975
- }
976
- }
977
- };
978
- /**
979
- * @param e The elements to be deleted if it satisfies the predicate
980
- */
981
- Slice.prototype.deleteN = function () {
982
- var e = [];
983
- for (var _i = 0; _i < arguments.length; _i++) {
984
- e[_i] = arguments[_i];
985
- }
986
- this.deleteA(e);
987
- };
988
- /**
989
- * @param e The elements to be deleted if they satisfy the predicate
990
- */
991
- Slice.prototype.deleteA = function (e) {
992
- var _this = this;
993
- var d = [];
994
- e.forEach(function (e) {
995
- if (_this.predicate(e)) {
996
- var id = e[_this.config.guidKey];
997
- d.push(_this.entries.get(id));
998
- _this.entries.delete(id);
999
- }
1000
- });
1001
- var delta = { type: "Delete" /* DELETE */, entries: d };
1002
- this.notifyAll(__spreadArray([], __read(Array.from(this.entries.values()))), delta);
1003
- };
1004
- /**
1005
- * Update the slice when an Entity instance mutates.
1006
- *
1007
- * @param e The element to be added or deleted depending on predicate reevaluation
1008
- */
1009
- Slice.prototype.put = function (e) {
1010
- if (isArray(e)) {
1011
- this.putA(e);
1012
- }
1013
- else {
1014
- var id = e[this.config.guidKey];
1015
- if (this.entries.get(id)) {
1016
- if (!this.predicate(e)) {
1017
- //Note that this is a ActionTypes.DELETE because we are removing the
1018
- //entity from the slice.
1019
- var delta = { type: "Delete" /* DELETE */, entries: [e] };
1020
- this.entries.delete(id);
1021
- this.notifyAll(__spreadArray([], __read(Array.from(this.entries.values()))), delta);
1022
- }
1023
- }
1024
- else if (this.predicate(e)) {
1025
- this.entries.set(id, e);
1026
- var delta = { type: "Put" /* PUT */, entries: [e] };
1027
- this.notifyAll(__spreadArray([], __read(Array.from(this.entries.values()))), delta);
1028
- }
1029
- }
1030
- };
1031
- /**
1032
- * Update the slice with mutated Entity instances.
1033
- *
1034
- * @param e The elements to be deleted if it satisfies the predicate
1035
- */
1036
- Slice.prototype.putN = function () {
1037
- var e = [];
1038
- for (var _i = 0; _i < arguments.length; _i++) {
1039
- e[_i] = arguments[_i];
1040
- }
1041
- this.putA(e);
1042
- };
1043
- /**
1044
- * @param e The elements to be put
1045
- */
1046
- Slice.prototype.putA = function (e) {
1047
- var _this = this;
1048
- var d = []; //instances to delete
1049
- var u = []; //instances to update
1050
- e.forEach(function (e) {
1051
- var id = e[_this.config.guidKey];
1052
- if (_this.entries.get(id)) {
1053
- if (!_this.predicate(e)) {
1054
- d.push(_this.entries.get(id));
1055
- }
1056
- }
1057
- else if (_this.predicate(e)) {
1058
- u.push(e);
1059
- }
1060
- });
1061
- if (d.length > 0) {
1062
- d.forEach(function (e) {
1063
- _this.entries.delete(e[_this.config.guidKey]);
1064
- });
1065
- var delta = { type: "Delete" /* DELETE */, entries: d };
1066
- this.notifyAll(__spreadArray([], __read(Array.from(this.entries.values()))), delta);
1067
- }
1068
- if (u.length > 0) {
1069
- u.forEach(function (e) {
1070
- _this.entries.set(e[_this.config.guidKey], e);
1071
- });
1072
- var delta = { type: "Put" /* PUT */, entries: u };
1073
- this.notifyAll(__spreadArray([], __read(Array.from(this.entries.values()))), delta);
1074
- }
1075
- };
1076
- /**
1077
- * Resets the slice to empty.
1078
- */
1079
- Slice.prototype.reset = function () {
1080
- var delta = {
1081
- type: "Reset" /* RESET */,
1082
- entries: __spreadArray([], __read(Array.from(this.entries.values())))
1083
- };
1084
- this.notifyAll([], delta);
1085
- this.entries = new Map();
1086
- };
1087
- /**
1088
- * Utility method that applies the predicate to an array
1089
- * of entities and return the ones that pass the test.
1090
- *
1091
- * Used to create an initial set of values
1092
- * that should be part of the `Slice`.
1093
- *
1094
- * @param p
1095
- * @param e
1096
- * @return The the array of entities that pass the predicate test.
1097
- */
1098
- Slice.prototype.test = function (p, e) {
1099
- var v = [];
1100
- e.forEach(function (e) {
1101
- if (p(e)) {
1102
- v.push(e);
1103
- }
1104
- });
1105
- return v;
1106
- };
1107
- return Slice;
1108
- }(AbstractStore));
1109
-
1110
- /**
1111
- * This `todoFactory` code will be used to illustrate the API examples. The following
1112
- * utilities are used in the tests and the API Typedoc examples contained here.
1113
- * @example Utilities for API Examples
1114
- ```
1115
- export const enum TodoSliceEnum {
1116
- COMPLETE = "Complete",
1117
- INCOMPLETE = "Incomplete"
1118
- }
1119
-
1120
- export class Todo {
1121
- constructor(public complete: boolean, public title: string,public gid?:string, public id?:string) {}
1122
- }
1123
-
1124
- export let todos = [new Todo(false, "You complete me!"), new Todo(true, "You completed me!")];
1125
-
1126
- export function todosFactory():Todo[] {
1127
- return [new Todo(false, "You complete me!"), new Todo(true, "You completed me!")];
1128
- }
1129
- ```
1130
- */
1131
- var EStore = /** @class */ (function (_super) {
1132
- __extends(EStore, _super);
1133
- /**
1134
- * Store constructor (Initialization with element is optional)
1135
- *
1136
- * perform initial notification to all observers,
1137
- * such that function like {@link combineLatest}{}
1138
- * will execute at least once.
1139
- * @param entities
1140
- * @example Dynamic `EStore<Todo>` Creation
1141
- ```
1142
- // Initialize the Store
1143
- let store: EStore<Todo> = new EStore<Todo>(todosFactory());
1144
- ```*/
1145
- function EStore(entities, config) {
1146
- if (entities === void 0) { entities = []; }
1147
- var _this = _super.call(this, config) || this;
1148
- /**
1149
- * Notifies observers when the store is empty.
1150
- */
1151
- _this.notifyActive = new rxjs.ReplaySubject(1);
1152
- /**
1153
- * `Map` of active entties. The instance is public and can be used
1154
- * directly to add and remove active entities, however we recommend
1155
- * using the {@link addActive} and {@link deleteActive} methods.
1156
- */
1157
- _this.active = new Map();
1158
- /**
1159
- * Notifies observers when the store is loading.
1160
- *
1161
- * This is a common pattern found when implementing
1162
- * `Observable` data sources.
1163
- */
1164
- _this.notifyLoading = new rxjs.ReplaySubject(1);
1165
- /**
1166
- * The current loading state. Use loading when fetching new
1167
- * data for the store. The default loading state is `true`.
1168
- *
1169
- * This is such that if data is fetched asynchronously
1170
- * in a service, components can wait on loading notification
1171
- * before attempting to retrieve data from the service.
1172
- *
1173
- * Loading could be based on a composite response. For example
1174
- * when the stock and mutual funds have loaded, set loading to `false`.
1175
- */
1176
- _this._loading = true;
1177
- /**
1178
- * Notifies observers that a search is in progress.
1179
- *
1180
- * This is a common pattern found when implementing
1181
- * `Observable` data sources.
1182
- */
1183
- _this.notifySearching = new rxjs.ReplaySubject(1);
1184
- /**
1185
- * The current `searching` state. Use `searching`
1186
- * for example to display a spinnner
1187
- * when performing a search.
1188
- * The default `searching` state is `false`.
1189
- */
1190
- _this._searching = false;
1191
- /**
1192
- * Store slices
1193
- */
1194
- _this.slices = new Map();
1195
- var delta = { type: "Initialize" /* INTIALIZE */, entries: entities };
1196
- _this.post(entities);
1197
- _this.notifyDelta.next(delta);
1198
- return _this;
1199
- }
1200
- /**
1201
- * Calls complete on all {@link BehaviorSubject} instances.
1202
- *
1203
- * Call destroy when disposing of the store.
1204
- */
1205
- EStore.prototype.destroy = function () {
1206
- _super.prototype.destroy.call(this);
1207
- this.notifyLoading.complete();
1208
- this.notifyActive.complete();
1209
- this.slices.forEach(function (slice) { return slice.destroy(); });
1210
- };
1211
- /**
1212
- * Toggles the entity:
1213
- *
1214
- * If the store contains the entity
1215
- * it will be deleted. If the store
1216
- * does not contains the entity,
1217
- * it is added.
1218
- * @param e
1219
- * @example Toggle the `Todo` instance
1220
- ```
1221
- estore.post(todo);
1222
- // Remove todo
1223
- estore.toggle(todo);
1224
- // Add it back
1225
- estore.toggle(todo);
1226
-
1227
- ```
1228
- */
1229
- EStore.prototype.toggle = function (e) {
1230
- if (this.contains(e)) {
1231
- this.delete(e);
1232
- }
1233
- else {
1234
- this.post(e);
1235
- }
1236
- };
1237
- /**
1238
- * Add multiple entity entities to active.
1239
- *
1240
- * If the entity is not contained in the store it is added
1241
- * to the store before it is added to `active`.
1242
- *
1243
- * Also we clone the map prior to broadcasting it with
1244
- * `notifyActive` to make sure we will trigger Angular
1245
- * change detection in the event that it maintains
1246
- * a reference to the `active` state `Map` instance.
1247
- *
1248
- * @example Add a `todo1` and `todo2` as active
1249
- ```
1250
- addActive(todo1);
1251
- addActive(todo2);
1252
- ```
1253
- */
1254
- EStore.prototype.addActive = function (e) {
1255
- if (this.contains(e)) {
1256
- this.active.set(e.gid, e);
1257
- this.notifyActive.next(new Map(this.active));
1258
- }
1259
- else {
1260
- this.post(e);
1261
- this.active.set(e.gid, e);
1262
- this.notifyActive.next(new Map(this.active));
1263
- }
1264
- };
1265
- /**
1266
- * Delete an entity as active.
1267
- *
1268
- * Also we clone the map prior to broadcasting it with
1269
- * `notifyActive` to make sure we will trigger Angular
1270
- * change detection in the event that it maintains
1271
- * a reference to the `active` state `Map` instance.
1272
- *
1273
- * @example Mark a `todo` instance as active
1274
- ```
1275
- deleteActive(todo1);
1276
- deleteActive(todo2);
1277
- ```
1278
- */
1279
- EStore.prototype.deleteActive = function (e) {
1280
- this.active.delete(e.gid);
1281
- this.notifyActive.next(new Map(this.active));
1282
- };
1283
- /**
1284
- * Clear / reset the active entity map.
1285
- *
1286
- * Also we clone the map prior to broadcasting it with
1287
- * `notifyActive` to make sure we will trigger Angular
1288
- * change detection in the event that it maintains
1289
- * a reference to the `active` state `Map` instance.
1290
- *
1291
- * @example Mark a `todo` instance as active
1292
- ```
1293
- deleteActive(todo1);
1294
- deleteActive(todo2);
1295
- ```
1296
- */
1297
- EStore.prototype.clearActive = function () {
1298
- this.active.clear();
1299
- this.notifyActive.next(new Map(this.active));
1300
- };
1301
- /**
1302
- * Observe the active entity.
1303
- * @example
1304
- <pre>
1305
- let active$ = source.observeActive();
1306
- </pre>
1307
- */
1308
- EStore.prototype.observeActive = function () {
1309
- return this.notifyActive.asObservable();
1310
- };
1311
- /**
1312
- * Observe the active entity.
1313
- * @example
1314
- <pre>
1315
- let active$ = source.activeSnapshot();
1316
- </pre>
1317
- */
1318
- EStore.prototype.activeSnapshot = function () {
1319
- return Array.from(this.active.values());
1320
- };
1321
- Object.defineProperty(EStore.prototype, "loading", {
1322
- /**
1323
- * @return A snapshot of the loading state.
1324
- */
1325
- get: function () {
1326
- return this._loading;
1327
- },
1328
- /**
1329
- * Sets the current loading state and notifies observers.
1330
- */
1331
- set: function (loading) {
1332
- this._loading = loading;
1333
- this.notifyLoading.next(this._loading);
1334
- },
1335
- enumerable: false,
1336
- configurable: true
1337
- });
1338
- /**
1339
- * Observe loading.
1340
- * @example
1341
- <pre>
1342
- let loading$ = source.observeLoading();
1343
- </pre>
1344
-
1345
- Note that this obverable piped through
1346
- `takeWhile(v->v, true), such that it will
1347
- complete after each emission.
1348
-
1349
- See:
1350
- https://medium.com/@ole.ersoy/waiting-on-estore-to-load-8dcbe161613c
1351
-
1352
- For more details.
1353
- */
1354
- EStore.prototype.observeLoading = function () {
1355
- return this.notifyLoading.asObservable().
1356
- pipe(operators.takeWhile(function (v) { return v; }, true));
1357
- };
1358
- /**
1359
- * Notfiies when loading has completed.
1360
- */
1361
- EStore.prototype.observeLoadingComplete = function () {
1362
- return this.observeLoading().pipe(operators.filter(function (loading) { return loading == false; }), operators.switchMap(function () { return rxjs.of(true); }));
1363
- };
1364
- Object.defineProperty(EStore.prototype, "searching", {
1365
- /**
1366
- * @return A snapshot of the searching state.
1367
- */
1368
- get: function () {
1369
- return this._searching;
1370
- },
1371
- /**
1372
- * Sets the current searching state and notifies observers.
1373
- */
1374
- set: function (searching) {
1375
- this._searching = searching;
1376
- this.notifySearching.next(this._searching);
1377
- },
1378
- enumerable: false,
1379
- configurable: true
1380
- });
1381
- /**
1382
- * Observe searching.
1383
- * @example
1384
- <pre>
1385
- let searching$ = source.observeSearching();
1386
- </pre>
1387
-
1388
- Note that this obverable piped through
1389
- `takeWhile(v->v, true), such that it will
1390
- complete after each emission.
1391
-
1392
- See:
1393
- https://medium.com/@ole.ersoy/waiting-on-estore-to-load-8dcbe161613c
1394
-
1395
- For more details.
1396
- */
1397
- EStore.prototype.observeSearching = function () {
1398
- return this.notifySearching.asObservable().
1399
- pipe(operators.takeWhile(function (v) { return v; }, true));
1400
- };
1401
- /**
1402
- * Notfiies when searching has completed.
1403
- */
1404
- EStore.prototype.observeSearchingComplete = function () {
1405
- return this.observeSearching().pipe(operators.filter(function (searching) { return searching == false; }), operators.switchMap(function () { return rxjs.of(true); }));
1406
- };
1407
- /**
1408
- * Adds a slice to the store and keys it by the slices label.
1409
- *
1410
- * @param p
1411
- * @param label
1412
- *
1413
- * @example Setup a Todo Slice for COMPLETE Todos
1414
- ```
1415
- source.addSlice(todo => todo.complete, TodoSlices.COMPLETE);
1416
- ```
1417
- */
1418
- EStore.prototype.addSlice = function (p, label) {
1419
- var slice = new Slice(label, p, this);
1420
- this.slices.set(slice.label, slice);
1421
- };
1422
- /**
1423
- * Remove a slice
1424
- * @param label The label identifying the slice
1425
- *
1426
- * @example Remove the TodoSlices.COMPLETE Slice
1427
- ```
1428
- source.removeSlice(TodoSlices.COMPLETE);
1429
- ```
1430
- */
1431
- EStore.prototype.removeSlice = function (label) {
1432
- this.slices.delete(label);
1433
- };
1434
- /**
1435
- * Get a slice
1436
- * @param label The label identifying the slice
1437
- * @return The Slice instance or undefined
1438
- *
1439
- * @example Get the TodoSlices.COMPLETE slice
1440
- ```
1441
- source.getSlice(TodoSlices.COMPLETE);
1442
- ```
1443
- */
1444
- EStore.prototype.getSlice = function (label) {
1445
- return this.slices.get(label);
1446
- };
1447
- /**
1448
- * Post (Add a new) element(s) to the store.
1449
- * @param e An indiidual entity or an array of entities
1450
- * @example Post a `todo`.
1451
- ```
1452
- store.post(todo);
1453
- ```
1454
- */
1455
- EStore.prototype.post = function (e) {
1456
- if (!Array.isArray(e)) {
1457
- var guid = e[this.GUID_KEY]
1458
- ? e[this.GUID_KEY]
1459
- : GUID();
1460
- e[this.GUID_KEY] = guid;
1461
- this.entries.set(guid, e);
1462
- this.updateIDEntry(e);
1463
- Array.from(this.slices.values()).forEach(function (s) {
1464
- s.post(e);
1465
- });
1466
- //Create a new array reference to trigger Angular change detection.
1467
- var v = __spreadArray([], __read(Array.from(this.entries.values())));
1468
- var delta = { type: "Post" /* POST */, entries: [e] };
1469
- this.notifyAll(v, delta);
1470
- }
1471
- else {
1472
- this.postA(e);
1473
- }
1474
- };
1475
- /**
1476
- * Post elements to the store.
1477
- * @param ...e
1478
- * @example Post two `Todo` instances.
1479
- ```
1480
- store.post(todo1, todo2);
1481
- ```
1482
- */
1483
- EStore.prototype.postN = function () {
1484
- var _this = this;
1485
- var e = [];
1486
- for (var _i = 0; _i < arguments.length; _i++) {
1487
- e[_i] = arguments[_i];
1488
- }
1489
- e.forEach(function (e) {
1490
- var guid = e[_this.GUID_KEY]
1491
- ? e[_this.GUID_KEY]
1492
- : GUID();
1493
- e[_this.GUID_KEY] = guid;
1494
- _this.entries.set(guid, e);
1495
- _this.updateIDEntry(e);
1496
- });
1497
- Array.from(this.slices.values()).forEach(function (s) {
1498
- s.postA(e);
1499
- });
1500
- //Create a new array reference to trigger Angular change detection.
1501
- var v = __spreadArray([], __read(Array.from(this.entries.values())));
1502
- var delta = { type: "Post" /* POST */, entries: e };
1503
- this.notifyAll(v, delta);
1504
- };
1505
- /**
1506
- * Post (Add) an array of elements to the store.
1507
- * @param e
1508
- * @example Post a `Todo` array.
1509
- ```
1510
- store.post([todo1, todo2]);
1511
- ```
1512
- */
1513
- EStore.prototype.postA = function (e) {
1514
- this.postN.apply(this, __spreadArray([], __read(e)));
1515
- };
1516
- /**
1517
- * Put (Update) an element.
1518
- * @param e
1519
- * @example Put a Todo instance.
1520
- ```
1521
- store.put(todo1);
1522
- ```
1523
- */
1524
- EStore.prototype.put = function (e) {
1525
- if (!Array.isArray(e)) {
1526
- var id = e[this.GUID_KEY];
1527
- this.entries.set(id, e);
1528
- this.updateIDEntry(e);
1529
- var v = __spreadArray([], __read(Array.from(this.entries.values())));
1530
- this.notify.next(v);
1531
- var delta = { type: "Put" /* PUT */, entries: [e] };
1532
- this.notifyDelta.next(delta);
1533
- Array.from(this.slices.values()).forEach(function (s) {
1534
- s.put(e);
1535
- });
1536
- }
1537
- else {
1538
- this.putA(e);
1539
- }
1540
- };
1541
- /**
1542
- * Put (Update) an element or add an element that was read from a persistence source
1543
- * and thus already has an assigned global id`.
1544
- * @param e
1545
- * @example Put Todo instances.
1546
- ```
1547
- store.put(todo1, todo2);
1548
- ```
1549
- */
1550
- EStore.prototype.putN = function () {
1551
- var e = [];
1552
- for (var _i = 0; _i < arguments.length; _i++) {
1553
- e[_i] = arguments[_i];
1554
- }
1555
- this.putA(e);
1556
- };
1557
- /**
1558
- * Put (Update) the array of elements.
1559
- * @param e
1560
- * @example Put Todo instances.
1561
- ```
1562
- store.put([todo1, todo2]);
1563
- ```
1564
- */
1565
- EStore.prototype.putA = function (e) {
1566
- var _this = this;
1567
- e.forEach(function (e) {
1568
- var guid = e[_this.GUID_KEY];
1569
- _this.entries.set(guid, e);
1570
- _this.updateIDEntry(e);
1571
- });
1572
- //Create a new array reference to trigger Angular change detection.
1573
- var v = __spreadArray([], __read(Array.from(this.entries.values())));
1574
- this.notify.next(v);
1575
- var delta = { type: "Put" /* PUT */, entries: e };
1576
- this.notifyDelta.next(delta);
1577
- Array.from(this.slices.values()).forEach(function (s) {
1578
- s.putA(e);
1579
- });
1580
- };
1581
- /**
1582
- * Delete (Update) the array of elements.
1583
- * @param e
1584
- * @example Delete todo1.
1585
- ```
1586
- store.delete(todo1]);
1587
- ```
1588
- */
1589
- EStore.prototype.delete = function (e) {
1590
- if (!Array.isArray(e)) {
1591
- this.deleteActive(e);
1592
- var guid_1 = e[this.GUID_KEY];
1593
- this.entries.delete(guid_1);
1594
- this.deleteIDEntry(e);
1595
- Array.from(this.slices.values()).forEach(function (s) {
1596
- s.entries.delete(guid_1);
1597
- });
1598
- //Create a new array reference to trigger Angular change detection.
1599
- var v = __spreadArray([], __read(Array.from(this.entries.values())));
1600
- var delta = { type: "Delete" /* DELETE */, entries: [e] };
1601
- this.notifyAll(v, delta);
1602
- Array.from(this.slices.values()).forEach(function (s) {
1603
- s.delete(e);
1604
- });
1605
- }
1606
- else {
1607
- this.deleteA(e);
1608
- }
1609
- };
1610
- /**
1611
- * Delete N elements.
1612
- * @param ...e
1613
- * @example Put Todo instances.
1614
- ```
1615
- store.delete(todo1, todo2);
1616
- ```
1617
- */
1618
- EStore.prototype.deleteN = function () {
1619
- var e = [];
1620
- for (var _i = 0; _i < arguments.length; _i++) {
1621
- e[_i] = arguments[_i];
1622
- }
1623
- this.deleteA(e);
1624
- };
1625
- /**
1626
- * Delete N elements.
1627
- * @param ...e
1628
- * @example Put Todo instances.
1629
- ```
1630
- store.delete(todo1, todo2);
1631
- ```
1632
- */
1633
- EStore.prototype.deleteA = function (e) {
1634
- var _this = this;
1635
- e.forEach(function (e) {
1636
- _this.deleteActive(e);
1637
- var guid = e[_this.GUID_KEY];
1638
- _this.entries.delete(guid);
1639
- _this.deleteIDEntry(e);
1640
- Array.from(_this.slices.values()).forEach(function (s) {
1641
- s.entries.delete(guid);
1642
- });
1643
- });
1644
- //Create a new array reference to trigger Angular change detection.
1645
- var v = __spreadArray([], __read(Array.from(this.entries.values())));
1646
- var delta = { type: "Delete" /* DELETE */, entries: e };
1647
- this.notifyAll(v, delta);
1648
- Array.from(this.slices.values()).forEach(function (s) {
1649
- s.deleteA(e);
1650
- });
1651
- };
1652
- /**
1653
- * Delete elements by {@link Predicate}.
1654
- * @param p The predicate.
1655
- * @example Put Todo instances.
1656
- ```
1657
- store.delete(todo1, todo2);
1658
- ```
1659
- */
1660
- EStore.prototype.deleteP = function (p) {
1661
- var _this = this;
1662
- var d = [];
1663
- Array.from(this.entries.values()).forEach(function (e) {
1664
- if (p(e)) {
1665
- d.push(e);
1666
- var id = e[_this.GUID_KEY];
1667
- _this.entries.delete(id);
1668
- _this.deleteActive(e);
1669
- _this.deleteIDEntry(e);
1670
- }
1671
- });
1672
- //Create a new array reference to trigger Angular change detection.
1673
- var v = __spreadArray([], __read(Array.from(this.entries.values())));
1674
- var delta = { type: "Delete" /* DELETE */, entries: d };
1675
- this.notifyAll(v, delta);
1676
- Array.from(this.slices.values()).forEach(function (s) {
1677
- s.deleteA(d);
1678
- });
1679
- };
1680
- /**
1681
- * If the entity has the `id` key initialized with a value,
1682
- * then also add the entity to the `idEntries`.
1683
- *
1684
- * @param e The element to be added to the `idEntries`.
1685
- */
1686
- EStore.prototype.updateIDEntry = function (e) {
1687
- if (e[this.ID_KEY]) {
1688
- this.idEntries.set(e[this.ID_KEY], e);
1689
- }
1690
- };
1691
- /**
1692
- * If the entity has the `id` key initialized with a value,
1693
- * then also delete the entity to the `idEntries`.
1694
- *
1695
- * @param e The element to be added to the `idEntries`.
1696
- */
1697
- EStore.prototype.deleteIDEntry = function (e) {
1698
- if (e[this.ID_KEY]) {
1699
- this.idEntries.delete(e[this.ID_KEY]);
1700
- }
1701
- };
1702
- /**
1703
- * Resets the store and all contained slice instances to empty.
1704
- * Also perform delta notification that sends all current store entries.
1705
- * The ActionType.RESET code is sent with the delta notification. Slices
1706
- * send their own delta notification.
1707
- *
1708
- * @example Reset the store.
1709
- ```
1710
- store.reset();
1711
- ```
1712
- */
1713
- EStore.prototype.reset = function () {
1714
- var delta = {
1715
- type: "Reset" /* RESET */,
1716
- entries: Array.from(this.entries.values())
1717
- };
1718
- this.notifyAll([], delta);
1719
- this.entries = new Map();
1720
- Array.from(this.slices.values()).forEach(function (s) {
1721
- s.reset();
1722
- });
1723
- };
1724
- /**
1725
- * Call all the notifiers at once.
1726
- *
1727
- * @param v
1728
- * @param delta
1729
- */
1730
- EStore.prototype.notifyAll = function (v, delta) {
1731
- _super.prototype.notifyAll.call(this, v, delta);
1732
- this.notifyLoading.next(this.loading);
1733
- };
1734
- return EStore;
1735
- }(AbstractStore));
1736
-
1737
- var OStore = /** @class */ (function () {
1738
- function OStore(start) {
1739
- var _this = this;
1740
- /**
1741
- * Map of Key Value pair entries
1742
- * containing values store in this store.
1743
- */
1744
- this.entries = new Map();
1745
- /**
1746
- * Map of replay subject id to `ReplaySubject` instance.
1747
- */
1748
- this.subjects = new Map();
1749
- if (start) {
1750
- this.S = start;
1751
- var keys = Object.keys(start);
1752
- keys.forEach(function (k) {
1753
- var ovr = start[k];
1754
- _this.post(ovr, ovr.value);
1755
- ovr.obs = _this.observe(ovr);
1756
- });
1757
- }
1758
- }
1759
- /**
1760
- * Reset the state of the OStore to the
1761
- * values or reset provided in the constructor
1762
- * {@link OStoreStart} instance.
1763
- */
1764
- OStore.prototype.reset = function () {
1765
- var _this = this;
1766
- if (this.S) {
1767
- var keys = Object.keys(this.S);
1768
- keys.forEach(function (k) {
1769
- var ovr = _this.S[k];
1770
- _this.put(ovr, ovr.reset ? ovr.reset : ovr.value);
1771
- });
1772
- }
1773
- };
1774
- /**
1775
- * Clear all entries
1776
- */
1777
- OStore.prototype.clear = function () {
1778
- this.entries.clear();
1779
- };
1780
- /**
1781
- * Set create a key value pair entry and creates a
1782
- * corresponding replay subject instance that will
1783
- * be used to broadcast updates.
1784
- *
1785
- * @param key The key identifying the value
1786
- * @param value The value
1787
- */
1788
- OStore.prototype.post = function (key, value) {
1789
- this.entries.set(key, value);
1790
- this.subjects.set(key, new rxjs.ReplaySubject(1));
1791
- //Emit immediately so that Observers can receive
1792
- //the value straight away.
1793
- var subject = this.subjects.get(key);
1794
- if (subject) {
1795
- subject.next(value);
1796
- }
1797
- };
1798
- /**
1799
- * Update a value and notify subscribers.
1800
- *
1801
- * @param key
1802
- * @param value
1803
- */
1804
- OStore.prototype.put = function (key, value) {
1805
- this.entries.set(key, value);
1806
- var subject = this.subjects.get(key);
1807
- if (subject) {
1808
- subject.next(value);
1809
- }
1810
- };
1811
- /**
1812
- * Deletes both the value entry and the corresponding {@link ReplaySubject}.
1813
- * Will unsubscribe the {@link ReplaySubject} prior to deleting it,
1814
- * severing communication with corresponding {@link Observable}s.
1815
- *
1816
- * @param key
1817
- */
1818
- OStore.prototype.delete = function (key) {
1819
- this.entries.delete(key);
1820
- this.subjects.delete(key);
1821
- var subject = this.subjects.get(key);
1822
- if (subject) {
1823
- subject.unsubscribe();
1824
- }
1825
- };
1826
- /**
1827
- * Observe changes to the values.
1828
- *
1829
- * @param key
1830
- * @return An {@link Observable} of the value
1831
- */
1832
- OStore.prototype.observe = function (key) {
1833
- return this.subjects.get(key).asObservable();
1834
- };
1835
- /**
1836
- * Check whether a value exists.
1837
- *
1838
- * @param key
1839
- * @return True if the entry exists ( Is not null or undefined ) and false otherwise.
1840
- */
1841
- OStore.prototype.exists = function (key) {
1842
- return this.entries.get(key) != null;
1843
- };
1844
- /**
1845
- * Retrieve a snapshot of the
1846
- * value.
1847
- *
1848
- * @param key
1849
- * @return A snapshot of the value corresponding to the key.
1850
- */
1851
- OStore.prototype.snapshot = function (key) {
1852
- return this.entries.get(key);
1853
- };
1854
- /**
1855
- * Indicates whether the store is empty.
1856
- * @return true if the store is empty, false otherwise.
1857
- */
1858
- OStore.prototype.isEmpty = function () {
1859
- return Array.from(this.entries.values()).length == 0;
1860
- };
1861
- /**
1862
- * Returns the number of key value pairs contained.
1863
- *
1864
- * @return the number of entries in the store.
1865
- */
1866
- OStore.prototype.count = function () {
1867
- return Array.from(this.entries.values()).length;
1868
- };
1869
- return OStore;
1870
- }());
1871
-
1872
- /*
1873
- * Public API Surface of slice
1874
- */
1875
-
1876
- /**
1877
- * Generated bundle index. Do not edit.
1878
- */
1879
-
1880
- exports.AbstractStore = AbstractStore;
1881
- exports.ESTORE_CONFIG_DEFAULT = ESTORE_CONFIG_DEFAULT;
1882
- exports.EStore = EStore;
1883
- exports.Entity = Entity;
1884
- exports.GUID = GUID;
1885
- exports.OStore = OStore;
1886
- exports.SCROLL_UP_DEBOUNCE_TIME_20 = SCROLL_UP_DEBOUNCE_TIME_20;
1887
- exports.SEARCH_DEBOUNCE_TIME_300 = SEARCH_DEBOUNCE_TIME_300;
1888
- exports.Slice = Slice;
1889
- exports.attachGUID = attachGUID;
1890
- exports.attachGUIDs = attachGUIDs;
1891
- exports.deepCopy = deepCopy;
1892
- exports.distinct = distinct;
1893
- exports.excludeKeys = excludeKeys;
1894
- exports.getActiveValue = getActiveValue;
1895
- exports.mapEntity = mapEntity;
1896
- exports.onFilteredEvent = onFilteredEvent;
1897
- exports.scrollingUp = scrollingUp;
1898
- exports.search = search;
1899
- exports.shallowCopy = shallowCopy;
1900
- exports.unique = unique;
1901
-
1902
- Object.defineProperty(exports, '__esModule', { value: true });
1903
-
1904
- })));
1905
- //# sourceMappingURL=fireflysemantics-slice.umd.js.map