ngxs-synchronizers 1.0.2 → 2.1.0

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 (32) hide show
  1. package/{esm2015/decorators/sync-state.js → esm2020/decorators/sync-state.mjs} +1 -1
  2. package/esm2020/module.mjs +19 -0
  3. package/esm2020/ngxs-synchronizers.mjs +5 -0
  4. package/esm2020/state-selector.mjs +221 -0
  5. package/esm2020/sync-store.mjs +32 -0
  6. package/esm2020/synchronizer/state-synchronizer.mjs +36 -0
  7. package/esm2020/synchronizer/synchronizer-dictionary.mjs +26 -0
  8. package/fesm2015/ngxs-synchronizers.mjs +428 -0
  9. package/fesm2015/ngxs-synchronizers.mjs.map +1 -0
  10. package/{fesm2015/ngxs-synchronizers.js → fesm2020/ngxs-synchronizers.mjs} +40 -32
  11. package/fesm2020/ngxs-synchronizers.mjs.map +1 -0
  12. package/module.d.ts +4 -0
  13. package/package.json +23 -11
  14. package/state-selector.d.ts +2 -2
  15. package/sync-store.d.ts +3 -0
  16. package/synchronizer/synchronizer-dictionary.d.ts +1 -1
  17. package/bundles/ngxs-synchronizers.umd.js +0 -797
  18. package/bundles/ngxs-synchronizers.umd.js.map +0 -1
  19. package/esm2015/module.js +0 -12
  20. package/esm2015/ngxs-synchronizers.js +0 -6
  21. package/esm2015/state-selector.js +0 -221
  22. package/esm2015/sync-store.js +0 -32
  23. package/esm2015/synchronizer/state-synchronizer.js +0 -33
  24. package/esm2015/synchronizer/synchronizer-dictionary.js +0 -27
  25. package/fesm2015/ngxs-synchronizers.js.map +0 -1
  26. package/ngxs-synchronizers.d.ts +0 -5
  27. package/ngxs-synchronizers.metadata.json +0 -1
  28. /package/{esm2015/decorators/sync-class.js → esm2020/decorators/sync-class.mjs} +0 -0
  29. /package/{esm2015/index.js → esm2020/index.mjs} +0 -0
  30. /package/{esm2015/synchronizer/collection-synchronizer.js → esm2020/synchronizer/collection-synchronizer.mjs} +0 -0
  31. /package/{esm2015/synchronizer/property-synchronizer.js → esm2020/synchronizer/property-synchronizer.mjs} +0 -0
  32. /package/{esm2015/synchronizer/synchronizer.js → esm2020/synchronizer/synchronizer.mjs} +0 -0
@@ -1,797 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@ngxs/store'), require('rxjs'), require('rxjs/operators')) :
3
- typeof define === 'function' && define.amd ? define('ngxs-synchronizers', ['exports', '@angular/core', '@ngxs/store', 'rxjs', 'rxjs/operators'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['ngxs-synchronizers'] = {}, global.ng.core, global['ngxs-store'], global.rxjs, global.rxjs.operators));
5
- }(this, (function (exports, core, store, rxjs, operators) { 'use strict';
6
-
7
- /*! *****************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
- /* global Reflect, Promise */
22
- var extendStatics = function (d, b) {
23
- extendStatics = Object.setPrototypeOf ||
24
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
25
- function (d, b) { for (var p in b)
26
- if (Object.prototype.hasOwnProperty.call(b, p))
27
- d[p] = b[p]; };
28
- return extendStatics(d, b);
29
- };
30
- function __extends(d, b) {
31
- if (typeof b !== "function" && b !== null)
32
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
33
- extendStatics(d, b);
34
- function __() { this.constructor = d; }
35
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
36
- }
37
- var __assign = function () {
38
- __assign = Object.assign || function __assign(t) {
39
- for (var s, i = 1, n = arguments.length; i < n; i++) {
40
- s = arguments[i];
41
- for (var p in s)
42
- if (Object.prototype.hasOwnProperty.call(s, p))
43
- t[p] = s[p];
44
- }
45
- return t;
46
- };
47
- return __assign.apply(this, arguments);
48
- };
49
- function __rest(s, e) {
50
- var t = {};
51
- for (var p in s)
52
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
53
- t[p] = s[p];
54
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
55
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
56
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
57
- t[p[i]] = s[p[i]];
58
- }
59
- return t;
60
- }
61
- function __decorate(decorators, target, key, desc) {
62
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
63
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
64
- r = Reflect.decorate(decorators, target, key, desc);
65
- else
66
- for (var i = decorators.length - 1; i >= 0; i--)
67
- if (d = decorators[i])
68
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
69
- return c > 3 && r && Object.defineProperty(target, key, r), r;
70
- }
71
- function __param(paramIndex, decorator) {
72
- return function (target, key) { decorator(target, key, paramIndex); };
73
- }
74
- function __metadata(metadataKey, metadataValue) {
75
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
76
- return Reflect.metadata(metadataKey, metadataValue);
77
- }
78
- function __awaiter(thisArg, _arguments, P, generator) {
79
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
80
- return new (P || (P = Promise))(function (resolve, reject) {
81
- function fulfilled(value) { try {
82
- step(generator.next(value));
83
- }
84
- catch (e) {
85
- reject(e);
86
- } }
87
- function rejected(value) { try {
88
- step(generator["throw"](value));
89
- }
90
- catch (e) {
91
- reject(e);
92
- } }
93
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
94
- step((generator = generator.apply(thisArg, _arguments || [])).next());
95
- });
96
- }
97
- function __generator(thisArg, body) {
98
- var _ = { label: 0, sent: function () { if (t[0] & 1)
99
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
100
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
101
- function verb(n) { return function (v) { return step([n, v]); }; }
102
- function step(op) {
103
- if (f)
104
- throw new TypeError("Generator is already executing.");
105
- while (_)
106
- try {
107
- 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)
108
- return t;
109
- if (y = 0, t)
110
- op = [op[0] & 2, t.value];
111
- switch (op[0]) {
112
- case 0:
113
- case 1:
114
- t = op;
115
- break;
116
- case 4:
117
- _.label++;
118
- return { value: op[1], done: false };
119
- case 5:
120
- _.label++;
121
- y = op[1];
122
- op = [0];
123
- continue;
124
- case 7:
125
- op = _.ops.pop();
126
- _.trys.pop();
127
- continue;
128
- default:
129
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
130
- _ = 0;
131
- continue;
132
- }
133
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
134
- _.label = op[1];
135
- break;
136
- }
137
- if (op[0] === 6 && _.label < t[1]) {
138
- _.label = t[1];
139
- t = op;
140
- break;
141
- }
142
- if (t && _.label < t[2]) {
143
- _.label = t[2];
144
- _.ops.push(op);
145
- break;
146
- }
147
- if (t[2])
148
- _.ops.pop();
149
- _.trys.pop();
150
- continue;
151
- }
152
- op = body.call(thisArg, _);
153
- }
154
- catch (e) {
155
- op = [6, e];
156
- y = 0;
157
- }
158
- finally {
159
- f = t = 0;
160
- }
161
- if (op[0] & 5)
162
- throw op[1];
163
- return { value: op[0] ? op[1] : void 0, done: true };
164
- }
165
- }
166
- var __createBinding = Object.create ? (function (o, m, k, k2) {
167
- if (k2 === undefined)
168
- k2 = k;
169
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
170
- }) : (function (o, m, k, k2) {
171
- if (k2 === undefined)
172
- k2 = k;
173
- o[k2] = m[k];
174
- });
175
- function __exportStar(m, o) {
176
- for (var p in m)
177
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
178
- __createBinding(o, m, p);
179
- }
180
- function __values(o) {
181
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
182
- if (m)
183
- return m.call(o);
184
- if (o && typeof o.length === "number")
185
- return {
186
- next: function () {
187
- if (o && i >= o.length)
188
- o = void 0;
189
- return { value: o && o[i++], done: !o };
190
- }
191
- };
192
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
193
- }
194
- function __read(o, n) {
195
- var m = typeof Symbol === "function" && o[Symbol.iterator];
196
- if (!m)
197
- return o;
198
- var i = m.call(o), r, ar = [], e;
199
- try {
200
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
201
- ar.push(r.value);
202
- }
203
- catch (error) {
204
- e = { error: error };
205
- }
206
- finally {
207
- try {
208
- if (r && !r.done && (m = i["return"]))
209
- m.call(i);
210
- }
211
- finally {
212
- if (e)
213
- throw e.error;
214
- }
215
- }
216
- return ar;
217
- }
218
- /** @deprecated */
219
- function __spread() {
220
- for (var ar = [], i = 0; i < arguments.length; i++)
221
- ar = ar.concat(__read(arguments[i]));
222
- return ar;
223
- }
224
- /** @deprecated */
225
- function __spreadArrays() {
226
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
227
- s += arguments[i].length;
228
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
229
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
230
- r[k] = a[j];
231
- return r;
232
- }
233
- function __spreadArray(to, from, pack) {
234
- if (pack || arguments.length === 2)
235
- for (var i = 0, l = from.length, ar; i < l; i++) {
236
- if (ar || !(i in from)) {
237
- if (!ar)
238
- ar = Array.prototype.slice.call(from, 0, i);
239
- ar[i] = from[i];
240
- }
241
- }
242
- return to.concat(ar || from);
243
- }
244
- function __await(v) {
245
- return this instanceof __await ? (this.v = v, this) : new __await(v);
246
- }
247
- function __asyncGenerator(thisArg, _arguments, generator) {
248
- if (!Symbol.asyncIterator)
249
- throw new TypeError("Symbol.asyncIterator is not defined.");
250
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
251
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
252
- function verb(n) { if (g[n])
253
- i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
254
- function resume(n, v) { try {
255
- step(g[n](v));
256
- }
257
- catch (e) {
258
- settle(q[0][3], e);
259
- } }
260
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
261
- function fulfill(value) { resume("next", value); }
262
- function reject(value) { resume("throw", value); }
263
- function settle(f, v) { if (f(v), q.shift(), q.length)
264
- resume(q[0][0], q[0][1]); }
265
- }
266
- function __asyncDelegator(o) {
267
- var i, p;
268
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
269
- 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; }
270
- }
271
- function __asyncValues(o) {
272
- if (!Symbol.asyncIterator)
273
- throw new TypeError("Symbol.asyncIterator is not defined.");
274
- var m = o[Symbol.asyncIterator], i;
275
- 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);
276
- 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); }); }; }
277
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
278
- }
279
- function __makeTemplateObject(cooked, raw) {
280
- if (Object.defineProperty) {
281
- Object.defineProperty(cooked, "raw", { value: raw });
282
- }
283
- else {
284
- cooked.raw = raw;
285
- }
286
- return cooked;
287
- }
288
- ;
289
- var __setModuleDefault = Object.create ? (function (o, v) {
290
- Object.defineProperty(o, "default", { enumerable: true, value: v });
291
- }) : function (o, v) {
292
- o["default"] = v;
293
- };
294
- function __importStar(mod) {
295
- if (mod && mod.__esModule)
296
- return mod;
297
- var result = {};
298
- if (mod != null)
299
- for (var k in mod)
300
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
301
- __createBinding(result, mod, k);
302
- __setModuleDefault(result, mod);
303
- return result;
304
- }
305
- function __importDefault(mod) {
306
- return (mod && mod.__esModule) ? mod : { default: mod };
307
- }
308
- function __classPrivateFieldGet(receiver, state, kind, f) {
309
- if (kind === "a" && !f)
310
- throw new TypeError("Private accessor was defined without a getter");
311
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
312
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
313
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
314
- }
315
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
316
- if (kind === "m")
317
- throw new TypeError("Private method is not writable");
318
- if (kind === "a" && !f)
319
- throw new TypeError("Private accessor was defined without a setter");
320
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
321
- throw new TypeError("Cannot write private member to an object whose class did not declare it");
322
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
323
- }
324
-
325
- var NGXS_SYNCHRONIZERS_METADATA_KEY = Symbol("$NGXS_SYNCHRONIZERS_METADATA");
326
- var PARENT_REF_KEY = Symbol("$PARENT_REF");
327
- var SYNC_STORE_OPTIONS_KEY = Symbol("$SYNC_STORE_OPTIONS");
328
- exports.ɵa = void 0;
329
- (function (SyncClass) {
330
- function getStoreOptions($class) {
331
- return metadata($class)[SYNC_STORE_OPTIONS_KEY];
332
- }
333
- SyncClass.getStoreOptions = getStoreOptions;
334
- function setStoreOptions($class, options) {
335
- metadata($class)[SYNC_STORE_OPTIONS_KEY] = options;
336
- }
337
- SyncClass.setStoreOptions = setStoreOptions;
338
- function resolveParent($class) {
339
- return metadata($class)[PARENT_REF_KEY];
340
- }
341
- SyncClass.resolveParent = resolveParent;
342
- function resolveParents($class) {
343
- var parent = resolveParent($class);
344
- return parent ? __spreadArray([parent], __read(resolveParents(parent))) : [];
345
- }
346
- SyncClass.resolveParents = resolveParents;
347
- function setParent($childClass, $parentClass) {
348
- metadata($childClass)[PARENT_REF_KEY] = $parentClass;
349
- }
350
- SyncClass.setParent = setParent;
351
- function metadata(stateRef) {
352
- var descriptor = Object.getOwnPropertyDescriptor(stateRef, NGXS_SYNCHRONIZERS_METADATA_KEY);
353
- if (!descriptor) {
354
- Object.defineProperty(stateRef, NGXS_SYNCHRONIZERS_METADATA_KEY, {
355
- configurable: false,
356
- enumerable: false,
357
- value: {}
358
- });
359
- return metadata(stateRef);
360
- }
361
- return descriptor.value;
362
- }
363
- })(exports.ɵa || (exports.ɵa = {}));
364
-
365
- function SyncState(options) {
366
- return function (constructor) {
367
- // Record the store options
368
- exports.ɵa.setStoreOptions(constructor, options);
369
- // Bootstrap the actions for the store
370
- SyncState.UpdateAction.bootstrapClass(constructor);
371
- // Record the parent store class for any child stores
372
- if (options.children) {
373
- options.children.forEach(function (child) { return exports.ɵa.setParent(child, constructor); });
374
- }
375
- // Apply the @State() decorator to the class
376
- store.State(options)(constructor);
377
- };
378
- }
379
- (function (SyncState) {
380
- var UpdateAction = /** @class */ (function () {
381
- function UpdateAction(property, payload) {
382
- this.property = property;
383
- this.payload = payload;
384
- }
385
- return UpdateAction;
386
- }());
387
- SyncState.UpdateAction = UpdateAction;
388
- (function (UpdateAction) {
389
- var UPDATE_ACTION_FN_KEY = Symbol("$UPDATE_ACTION_FN");
390
- var updateActions = new Map();
391
- function bootstrapClass($class) {
392
- // Add the update action function to the class
393
- Object.defineProperty($class.prototype, UPDATE_ACTION_FN_KEY, {
394
- configurable: false,
395
- enumerable: true,
396
- value: function (context, _b) {
397
- var _c, _d;
398
- var property = _b.property, payload = _b.payload;
399
- if (context.getState() === undefined || context.getState() === null) {
400
- context.setState((_c = {}, _c[property] = payload, _c));
401
- }
402
- else {
403
- context.patchState((_d = {}, _d[property] = payload, _d));
404
- }
405
- }
406
- });
407
- // Apply the @Action() decorator to the new function
408
- store.Action(Type($class))($class.prototype, UPDATE_ACTION_FN_KEY, Object.getOwnPropertyDescriptor($class.prototype, UPDATE_ACTION_FN_KEY));
409
- }
410
- UpdateAction.bootstrapClass = bootstrapClass;
411
- function Type($class) {
412
- var _a;
413
- if (!updateActions.has($class)) {
414
- var opts = exports.ɵa.getStoreOptions($class);
415
- updateActions.set($class, (_a = /** @class */ (function (_super) {
416
- __extends(_a, _super);
417
- function _a() {
418
- return _super !== null && _super.apply(this, arguments) || this;
419
- }
420
- return _a;
421
- }(UpdateAction)),
422
- _a.type = "[" + opts.name + " sync] Update field",
423
- _a));
424
- }
425
- return updateActions.get($class);
426
- }
427
- UpdateAction.Type = Type;
428
- })(UpdateAction = SyncState.UpdateAction || (SyncState.UpdateAction = {}));
429
- })(SyncState || (SyncState = {}));
430
-
431
- exports.SynchronizerDictionary = void 0;
432
- (function (SynchronizerDictionary) {
433
- function keys(dict) {
434
- return isCollectionSynchronizer(dict) ? [] : Object.keys(dict || {});
435
- }
436
- SynchronizerDictionary.keys = keys;
437
- function isCollectionSynchronizer(dict) {
438
- var _a, _b;
439
- return typeof ((_b = (_a = dict) === null || _a === void 0 ? void 0 : _a.prototype) === null || _b === void 0 ? void 0 : _b.read) === "function";
440
- }
441
- SynchronizerDictionary.isCollectionSynchronizer = isCollectionSynchronizer;
442
- function resolveSynchronizer(dict, propKey) {
443
- return isCollectionSynchronizer(dict) ? dict : dict[propKey];
444
- }
445
- SynchronizerDictionary.resolveSynchronizer = resolveSynchronizer;
446
- function resolveSynchronizerInstance(injector, dict, propKey) {
447
- var synchronizerDef = resolveSynchronizer(dict, propKey);
448
- if (!!synchronizerDef) {
449
- return injector.get(synchronizerDef);
450
- }
451
- else {
452
- throw new Error("A Synchronizer has not been defined for property '" + propKey + ".");
453
- }
454
- }
455
- SynchronizerDictionary.resolveSynchronizerInstance = resolveSynchronizerInstance;
456
- })(exports.SynchronizerDictionary || (exports.SynchronizerDictionary = {}));
457
-
458
- var StateSelector = /** @class */ (function () {
459
- function StateSelector(store, stateClass, state$) {
460
- this.store = store;
461
- this.stateClass = stateClass;
462
- this.state$ = state$;
463
- this.synchronizers = exports.ɵa.getStoreOptions(this.stateClass).synchronizers;
464
- this.injector = this.store.injector;
465
- this.pendingRequests$ = new rxjs.BehaviorSubject({});
466
- }
467
- StateSelector.prototype.dispatch = function (propertyName, value) {
468
- var PropUpdateAction = SyncState.UpdateAction.Type(this.stateClass);
469
- return this.store.dispatch(new PropUpdateAction(propertyName, value));
470
- };
471
- StateSelector.prototype.property = function (propertyName) {
472
- return this.state$.pipe(operators.map(function (state) { return state === null || state === void 0 ? void 0 : state[propertyName]; }));
473
- };
474
- StateSelector.prototype.properties = function () {
475
- return this.state$;
476
- };
477
- StateSelector.prototype.definedProperty = function (propertyName) {
478
- return this.property(propertyName).pipe(operators.filter(function (value) { return value !== null && value !== undefined; }));
479
- };
480
- StateSelector.prototype.isSyncingProperty = function (propertyName) {
481
- return this.getPropertyUpdater(propertyName).pipe(operators.map(Boolean), operators.distinctUntilChanged());
482
- };
483
- StateSelector.prototype.onPropertySyncing = function (propertyName) {
484
- return this.isSyncingProperty(propertyName).pipe(operators.filter(Boolean), operators.map(function () { return propertyName; }));
485
- };
486
- StateSelector.prototype.onPropertySynced = function (propertyName) {
487
- return this.isSyncingProperty(propertyName).pipe(operators.filter(function (updating) { return !updating; }), operators.map(function () { return propertyName; }));
488
- };
489
- StateSelector.prototype.onEveryPropertySyncing = function () {
490
- var _this = this;
491
- var propertyNames = [];
492
- for (var _i = 0; _i < arguments.length; _i++) {
493
- propertyNames[_i] = arguments[_i];
494
- }
495
- return rxjs.zip.apply(void 0, __spreadArray([], __read(propertyNames.map(function (propertyName) { return _this.onPropertySyncing(propertyName); }))));
496
- };
497
- StateSelector.prototype.onEveryPropertySynced = function () {
498
- var _this = this;
499
- var propertyNames = [];
500
- for (var _i = 0; _i < arguments.length; _i++) {
501
- propertyNames[_i] = arguments[_i];
502
- }
503
- return rxjs.zip.apply(void 0, __spreadArray([], __read(propertyNames.map(function (propertyName) { return _this.onPropertySynced(propertyName); }))));
504
- };
505
- StateSelector.prototype.onSomePropertySyncing = function () {
506
- var _this = this;
507
- var propertyNames = [];
508
- for (var _i = 0; _i < arguments.length; _i++) {
509
- propertyNames[_i] = arguments[_i];
510
- }
511
- return rxjs.merge.apply(void 0, __spreadArray([], __read(propertyNames.map(function (propertyName) { return _this.onPropertySyncing(propertyName); }))));
512
- };
513
- StateSelector.prototype.onSomePropertySynced = function () {
514
- var _this = this;
515
- var propertyNames = [];
516
- for (var _i = 0; _i < arguments.length; _i++) {
517
- propertyNames[_i] = arguments[_i];
518
- }
519
- return rxjs.merge.apply(void 0, __spreadArray([], __read(propertyNames.map(function (propertyName) { return _this.onPropertySynced(propertyName); }))));
520
- };
521
- StateSelector.prototype.require = function (propertyNames, options) {
522
- if (Array.isArray(propertyNames)) {
523
- return this.requireAll(propertyNames, options);
524
- }
525
- else {
526
- return this.requireOne(propertyNames, options);
527
- }
528
- };
529
- StateSelector.prototype.requireProperty = function (propertyName, options) {
530
- return this.requireOne(propertyName, options).pipe(operators.map(function (session) { return session[propertyName]; }));
531
- };
532
- StateSelector.prototype.sync = function (propertyNames, options) {
533
- if (Array.isArray(propertyNames)) {
534
- return this.syncAll(propertyNames, options);
535
- }
536
- else {
537
- return this.syncOne(propertyNames, options);
538
- }
539
- };
540
- StateSelector.prototype.syncProperty = function (propertyName, options) {
541
- return this.syncOne(propertyName, options).pipe(operators.map(function (session) { return session[propertyName]; }));
542
- };
543
- StateSelector.prototype.export = function (propertyNames, options) {
544
- if (Array.isArray(propertyNames)) {
545
- return this.exportAll(propertyNames, options);
546
- }
547
- else {
548
- return this.exportOne(propertyNames, options);
549
- }
550
- };
551
- StateSelector.prototype.requireOne = function (propertyName, options) {
552
- var _this = this;
553
- return this.state$.pipe(operators.take(1), operators.mergeMap(function (state) {
554
- if ((state === null || state === void 0 ? void 0 : state[propertyName]) !== undefined && (state === null || state === void 0 ? void 0 : state[propertyName]) !== null) {
555
- return rxjs.of(state);
556
- }
557
- else {
558
- return _this.sync(propertyName, options);
559
- }
560
- }));
561
- };
562
- StateSelector.prototype.requireAll = function (propertyNames, options) {
563
- var _this = this;
564
- if (propertyNames.length === 0) {
565
- return this.state$.pipe(operators.take(1));
566
- }
567
- else {
568
- var errors_1 = [];
569
- return rxjs.forkJoin(propertyNames.map(function (propertyName) {
570
- return _this.requireOne(propertyName, options).pipe(operators.catchError(function (error) {
571
- errors_1.push(error);
572
- return rxjs.of(undefined);
573
- }));
574
- })).pipe(operators.mergeMap(function () {
575
- if (errors_1.length === 0) {
576
- return _this.state$.pipe(operators.take(1));
577
- }
578
- else {
579
- return rxjs.throwError(errors_1);
580
- }
581
- }));
582
- }
583
- };
584
- StateSelector.prototype.syncOne = function (propertyName, options) {
585
- var _this = this;
586
- options = options || {};
587
- var errorPrefix = "[NGXS-Synchronizers] Cannot sync state:";
588
- var synchronizer;
589
- try {
590
- synchronizer = this.resolveSynchronizer(propertyName);
591
- }
592
- catch (error) {
593
- return rxjs.throwError(error);
594
- }
595
- // Check for cached values/pending requests only if this isn't a dependent requestor
596
- if (!synchronizer.proxy) {
597
- if (options.clearStore) {
598
- // TODO-Synchronize on this?
599
- this.dispatch(propertyName, undefined).subscribe();
600
- }
601
- if (synchronizer.requiredProperties && synchronizer.requiredProperties.some(function (requiredPropertyName) { return requiredPropertyName === propertyName; })) {
602
- return rxjs.throwError(errorPrefix + " Synchronizer for \"" + propertyName + "\" requires a reference to itself.");
603
- }
604
- }
605
- return this.pendingRequests$.pipe(operators.take(1), operators.mergeMap(function (pendingRequests) {
606
- var _a;
607
- var pendingRequest$ = pendingRequests[propertyName];
608
- if (pendingRequest$ && !options.clearStore) {
609
- // Use the existing request if this value is currently being requested
610
- return pendingRequest$;
611
- }
612
- else {
613
- // First request any required fields needed to fetch the propertyName
614
- if (synchronizer.proxy) {
615
- pendingRequest$ = _this.syncAll(synchronizer.requiredProperties, options);
616
- }
617
- else {
618
- pendingRequest$ = _this.requireAll(synchronizer.requiredProperties || []);
619
- }
620
- // Then fetch the propertyName
621
- pendingRequest$ = pendingRequest$.pipe(operators.mergeMap(function (requiredDetails) { return synchronizer.read(requiredDetails, Object.assign({ propertyName: propertyName }, options)); }), operators.mergeMap(function (value) { return _this.dispatch(propertyName, value); }), // Update the store value
622
- operators.catchError(function (error) {
623
- _this.clearPropertyUpdater(propertyName, pendingRequest$);
624
- return rxjs.throwError(error);
625
- }), operators.tap(function () { return _this.clearPropertyUpdater(propertyName, pendingRequest$); }), // Remove the pending request
626
- operators.mergeMap(function () { return _this.state$.pipe(operators.take(1)); }), // Get the newly updated state
627
- operators.publishReplay(1), operators.refCount());
628
- _this.pendingRequests$.next(Object.assign(pendingRequests, (_a = {}, _a[propertyName] = pendingRequest$, _a)));
629
- return pendingRequest$;
630
- }
631
- }));
632
- };
633
- StateSelector.prototype.syncAll = function (propertyNames, options) {
634
- var _this = this;
635
- options = options || {};
636
- if (propertyNames.length === 0) {
637
- return this.state$.pipe(operators.take(1));
638
- }
639
- // Update each required propertyName
640
- var errors = [];
641
- return rxjs.forkJoin(propertyNames.map(function (name) { return _this.sync(name, options).pipe(operators.catchError(function (error) {
642
- errors.push(error);
643
- return rxjs.of(undefined);
644
- })); })).pipe(operators.mergeMap(function () {
645
- if (errors.length === 0) {
646
- return _this.state$.pipe(operators.take(1));
647
- }
648
- else {
649
- return rxjs.throwError("Error syncing properties: " + errors.join(", "));
650
- }
651
- }));
652
- };
653
- StateSelector.prototype.exportOne = function (propertyName, options) {
654
- options = options || {};
655
- var errorPrefix = "[NGXS-Synchronizers] Cannot export state:";
656
- var synchronizer;
657
- try {
658
- synchronizer = this.resolveSynchronizer(propertyName);
659
- }
660
- catch (error) {
661
- return rxjs.throwError(error);
662
- }
663
- if (!synchronizer.write) {
664
- return rxjs.throwError(errorPrefix + " Synchronizer for \"" + propertyName + "\" doesn't have a write method defined.");
665
- }
666
- // Write the latest data in the store
667
- return this.property(propertyName).pipe(operators.take(1), operators.mergeMap(function (data) { return synchronizer.write(data, Object.assign({ propertyName: propertyName }, options)); }), operators.publishReplay(1), operators.refCount());
668
- };
669
- StateSelector.prototype.exportAll = function (propertyNames, options) {
670
- var _this = this;
671
- options = options || {};
672
- if (propertyNames.length === 0) {
673
- return rxjs.EMPTY;
674
- }
675
- // Update each required propertyName
676
- var errors = [];
677
- return rxjs.forkJoin(propertyNames.map(function (name) { return _this.export(name, options).pipe(operators.catchError(function (error) {
678
- errors.push(error);
679
- return rxjs.of(undefined);
680
- })); })).pipe(operators.mergeMap(function (results) {
681
- if (errors.length === 0) {
682
- return rxjs.of(results);
683
- }
684
- else {
685
- return rxjs.throwError("Error exporting properties: " + errors.join(", "));
686
- }
687
- }));
688
- };
689
- StateSelector.prototype.getPropertyUpdater = function (propertyName) {
690
- return this.pendingRequests$.pipe(operators.map(function (pendingRequests) { return pendingRequests[propertyName]; }));
691
- };
692
- StateSelector.prototype.clearPropertyUpdater = function (propertyName, request) {
693
- var _this = this;
694
- this.pendingRequests$.pipe(operators.take(1), operators.filter(function (pendingRequests) { return pendingRequests[propertyName] === request; })).subscribe(function (pendingRequests) {
695
- var _a;
696
- return _this.pendingRequests$.next(Object.assign(pendingRequests, (_a = {}, _a[propertyName] = undefined, _a)));
697
- });
698
- };
699
- StateSelector.prototype.resolveSynchronizer = function (propertyName) {
700
- return exports.SynchronizerDictionary.resolveSynchronizerInstance(this.injector, this.synchronizers, propertyName);
701
- };
702
- return StateSelector;
703
- }());
704
-
705
- var SyncStore = /** @class */ (function (_super) {
706
- __extends(SyncStore, _super);
707
- function SyncStore(injector, store) {
708
- var _this = this;
709
- var internalStore = store;
710
- _this = _super.call(this, internalStore._stateStream, internalStore._internalStateOperations, internalStore._config, internalStore._internalExecutionStrategy, internalStore._stateFactory, undefined) || this;
711
- _this.injector = injector;
712
- _this._selectorMap = new Map();
713
- return _this;
714
- }
715
- SyncStore.prototype.state = function (syncState) {
716
- // If the selector hasn't been created for this state class yet, create it
717
- if (!this._selectorMap.has(syncState)) {
718
- var statePath_1 = __spreadArray(__spreadArray([], __read(exports.ɵa.resolveParents(syncState).reverse())), [syncState]);
719
- var state$ = this.select(function (state) { return statePath_1.reduce(function (parentState, childState) {
720
- return parentState[exports.ɵa.getStoreOptions(childState).name];
721
- }, state); });
722
- // Record each state selector to keep pending requests in sync between state() calls
723
- this._selectorMap.set(syncState, new StateSelector(this, syncState, state$));
724
- }
725
- return this._selectorMap.get(syncState);
726
- };
727
- return SyncStore;
728
- }(store.Store));
729
- SyncStore.decorators = [
730
- { type: core.Injectable }
731
- ];
732
- SyncStore.ctorParameters = function () { return [
733
- { type: core.Injector },
734
- { type: store.Store }
735
- ]; };
736
-
737
- var NgxsSyncModule = /** @class */ (function () {
738
- function NgxsSyncModule() {
739
- }
740
- return NgxsSyncModule;
741
- }());
742
- NgxsSyncModule.decorators = [
743
- { type: core.NgModule, args: [{
744
- providers: [
745
- SyncStore
746
- ]
747
- },] }
748
- ];
749
-
750
- var StateSynchronizer = /** @class */ (function () {
751
- function StateSynchronizer(injector, propertyState) {
752
- this.injector = injector;
753
- this.propertyState = propertyState;
754
- }
755
- StateSynchronizer.prototype.read = function (_requiredDetails, _options) {
756
- var syncStore = this.injector.get(SyncStore);
757
- var stateSelector = syncStore.state(this.propertyState);
758
- // Sync each property in the sub-store that has a synchronizer
759
- return this.readSubset(exports.SynchronizerDictionary.keys(stateSelector.synchronizers));
760
- };
761
- StateSynchronizer.prototype.readSubset = function (properties) {
762
- var syncStore = this.injector.get(SyncStore);
763
- var stateSelector = syncStore.state(this.propertyState);
764
- // Sync each property in the sub-store that has a synchronizer and combine with the current store's data
765
- return this.readProperties(stateSelector, properties).pipe(operators.map(function (results) { return Object.assign.apply(Object, __spreadArray([{}], __read(results))); }), operators.switchMap(function (newProperties) { return stateSelector.properties().pipe(operators.take(1), operators.map(function (originalProperties) { return (Object.assign(Object.assign({}, originalProperties), newProperties)); })); }));
766
- };
767
- StateSynchronizer.prototype.readProperties = function (stateSelector, keys) {
768
- var _this = this;
769
- // Sync each property in the dictionary
770
- return keys.length > 0
771
- ? rxjs.forkJoin(keys.map(function (propKey) { return _this.readProperty(stateSelector, propKey); }))
772
- : rxjs.of([]);
773
- };
774
- StateSynchronizer.prototype.readProperty = function (stateSelector, propKey) {
775
- // Use `syncProperty` to invoke the synchronizer for this property
776
- return stateSelector.syncProperty(propKey).pipe(operators.map(function (result) {
777
- var _a;
778
- return (_a = {}, _a[propKey] = result, _a);
779
- }));
780
- };
781
- return StateSynchronizer;
782
- }());
783
-
784
- /**
785
- * Generated bundle index. Do not edit.
786
- */
787
-
788
- exports.NgxsSyncModule = NgxsSyncModule;
789
- exports.StateSelector = StateSelector;
790
- exports.StateSynchronizer = StateSynchronizer;
791
- exports.SyncState = SyncState;
792
- exports.SyncStore = SyncStore;
793
-
794
- Object.defineProperty(exports, '__esModule', { value: true });
795
-
796
- })));
797
- //# sourceMappingURL=ngxs-synchronizers.umd.js.map