@ngxs/form-plugin 3.7.4 → 3.7.5

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.
@@ -223,670 +223,677 @@
223
223
  return value;
224
224
  }
225
225
 
226
- /**
227
- * @fileoverview added by tsickle
228
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
229
- */
230
- var UpdateFormStatus = /** @class */ (function () {
231
- function UpdateFormStatus(payload) {
232
- this.payload = payload;
233
- }
234
- Object.defineProperty(UpdateFormStatus, "type", {
235
- get: /**
236
- * @return {?}
237
- */
238
- function () {
239
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
240
- return '[Forms] Update Form Status';
241
- },
242
- enumerable: true,
243
- configurable: true
244
- });
245
- return UpdateFormStatus;
246
- }());
247
- if (false) {
248
- /** @type {?} */
249
- UpdateFormStatus.prototype.payload;
250
- }
251
- var UpdateFormValue = /** @class */ (function () {
252
- function UpdateFormValue(payload) {
253
- this.payload = payload;
254
- }
255
- Object.defineProperty(UpdateFormValue, "type", {
256
- get: /**
257
- * @return {?}
258
- */
259
- function () {
260
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
261
- return '[Forms] Update Form Value';
262
- },
263
- enumerable: true,
264
- configurable: true
265
- });
266
- return UpdateFormValue;
267
- }());
268
- if (false) {
269
- /** @type {?} */
270
- UpdateFormValue.prototype.payload;
271
- }
272
- var UpdateForm = /** @class */ (function () {
273
- function UpdateForm(payload) {
274
- this.payload = payload;
275
- }
276
- Object.defineProperty(UpdateForm, "type", {
277
- get: /**
278
- * @return {?}
279
- */
280
- function () {
281
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
282
- return '[Forms] Update Form';
283
- },
284
- enumerable: true,
285
- configurable: true
286
- });
287
- return UpdateForm;
288
- }());
289
- if (false) {
290
- /** @type {?} */
291
- UpdateForm.prototype.payload;
292
- }
293
- var UpdateFormDirty = /** @class */ (function () {
294
- function UpdateFormDirty(payload) {
295
- this.payload = payload;
296
- }
297
- Object.defineProperty(UpdateFormDirty, "type", {
298
- get: /**
299
- * @return {?}
300
- */
301
- function () {
302
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
303
- return '[Forms] Update Form Dirty';
304
- },
305
- enumerable: true,
306
- configurable: true
307
- });
308
- return UpdateFormDirty;
309
- }());
310
- if (false) {
311
- /** @type {?} */
312
- UpdateFormDirty.prototype.payload;
313
- }
314
- var SetFormDirty = /** @class */ (function () {
315
- function SetFormDirty(payload) {
316
- this.payload = payload;
317
- }
318
- Object.defineProperty(SetFormDirty, "type", {
319
- get: /**
320
- * @return {?}
321
- */
322
- function () {
323
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
324
- return '[Forms] Set Form Dirty';
325
- },
326
- enumerable: true,
327
- configurable: true
328
- });
329
- return SetFormDirty;
330
- }());
331
- if (false) {
332
- /** @type {?} */
333
- SetFormDirty.prototype.payload;
334
- }
335
- var SetFormPristine = /** @class */ (function () {
336
- function SetFormPristine(payload) {
337
- this.payload = payload;
338
- }
339
- Object.defineProperty(SetFormPristine, "type", {
340
- get: /**
341
- * @return {?}
342
- */
343
- function () {
344
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
345
- return '[Forms] Set Form Pristine';
346
- },
347
- enumerable: true,
348
- configurable: true
349
- });
350
- return SetFormPristine;
351
- }());
352
- if (false) {
353
- /** @type {?} */
354
- SetFormPristine.prototype.payload;
355
- }
356
- var UpdateFormErrors = /** @class */ (function () {
357
- function UpdateFormErrors(payload) {
358
- this.payload = payload;
359
- }
360
- Object.defineProperty(UpdateFormErrors, "type", {
361
- get: /**
362
- * @return {?}
363
- */
364
- function () {
365
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
366
- return '[Forms] Update Form Errors';
367
- },
368
- enumerable: true,
369
- configurable: true
370
- });
371
- return UpdateFormErrors;
372
- }());
373
- if (false) {
374
- /** @type {?} */
375
- UpdateFormErrors.prototype.payload;
376
- }
377
- var SetFormDisabled = /** @class */ (function () {
378
- function SetFormDisabled(payload) {
379
- this.payload = payload;
380
- }
381
- Object.defineProperty(SetFormDisabled, "type", {
382
- get: /**
383
- * @return {?}
384
- */
385
- function () {
386
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
387
- return '[Forms] Set Form Disabled';
388
- },
389
- enumerable: true,
390
- configurable: true
391
- });
392
- return SetFormDisabled;
393
- }());
394
- if (false) {
395
- /** @type {?} */
396
- SetFormDisabled.prototype.payload;
397
- }
398
- var SetFormEnabled = /** @class */ (function () {
399
- function SetFormEnabled(payload) {
400
- this.payload = payload;
401
- }
402
- Object.defineProperty(SetFormEnabled, "type", {
403
- get: /**
404
- * @return {?}
405
- */
406
- function () {
407
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
408
- return '[Forms] Set Form Enabled';
409
- },
410
- enumerable: true,
411
- configurable: true
412
- });
413
- return SetFormEnabled;
414
- }());
415
- if (false) {
416
- /** @type {?} */
417
- SetFormEnabled.prototype.payload;
418
- }
419
- var ResetForm = /** @class */ (function () {
420
- function ResetForm(payload) {
421
- this.payload = payload;
422
- }
423
- Object.defineProperty(ResetForm, "type", {
424
- get: /**
425
- * @return {?}
426
- */
427
- function () {
428
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
429
- return '[Forms] Reset Form';
430
- },
431
- enumerable: true,
432
- configurable: true
433
- });
434
- return ResetForm;
435
- }());
436
- if (false) {
437
- /** @type {?} */
438
- ResetForm.prototype.payload;
226
+ /**
227
+ * @fileoverview added by tsickle
228
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
229
+ */
230
+ var UpdateFormStatus = /** @class */ (function () {
231
+ function UpdateFormStatus(payload) {
232
+ this.payload = payload;
233
+ }
234
+ Object.defineProperty(UpdateFormStatus, "type", {
235
+ get: /**
236
+ * @return {?}
237
+ */
238
+ function () {
239
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
240
+ return '[Forms] Update Form Status';
241
+ },
242
+ enumerable: true,
243
+ configurable: true
244
+ });
245
+ return UpdateFormStatus;
246
+ }());
247
+ if (false) {
248
+ /** @type {?} */
249
+ UpdateFormStatus.prototype.payload;
250
+ }
251
+ var UpdateFormValue = /** @class */ (function () {
252
+ function UpdateFormValue(payload) {
253
+ this.payload = payload;
254
+ }
255
+ Object.defineProperty(UpdateFormValue, "type", {
256
+ get: /**
257
+ * @return {?}
258
+ */
259
+ function () {
260
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
261
+ return '[Forms] Update Form Value';
262
+ },
263
+ enumerable: true,
264
+ configurable: true
265
+ });
266
+ return UpdateFormValue;
267
+ }());
268
+ if (false) {
269
+ /** @type {?} */
270
+ UpdateFormValue.prototype.payload;
271
+ }
272
+ var UpdateForm = /** @class */ (function () {
273
+ function UpdateForm(payload) {
274
+ this.payload = payload;
275
+ }
276
+ Object.defineProperty(UpdateForm, "type", {
277
+ get: /**
278
+ * @return {?}
279
+ */
280
+ function () {
281
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
282
+ return '[Forms] Update Form';
283
+ },
284
+ enumerable: true,
285
+ configurable: true
286
+ });
287
+ return UpdateForm;
288
+ }());
289
+ if (false) {
290
+ /** @type {?} */
291
+ UpdateForm.prototype.payload;
292
+ }
293
+ var UpdateFormDirty = /** @class */ (function () {
294
+ function UpdateFormDirty(payload) {
295
+ this.payload = payload;
296
+ }
297
+ Object.defineProperty(UpdateFormDirty, "type", {
298
+ get: /**
299
+ * @return {?}
300
+ */
301
+ function () {
302
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
303
+ return '[Forms] Update Form Dirty';
304
+ },
305
+ enumerable: true,
306
+ configurable: true
307
+ });
308
+ return UpdateFormDirty;
309
+ }());
310
+ if (false) {
311
+ /** @type {?} */
312
+ UpdateFormDirty.prototype.payload;
313
+ }
314
+ var SetFormDirty = /** @class */ (function () {
315
+ function SetFormDirty(payload) {
316
+ this.payload = payload;
317
+ }
318
+ Object.defineProperty(SetFormDirty, "type", {
319
+ get: /**
320
+ * @return {?}
321
+ */
322
+ function () {
323
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
324
+ return '[Forms] Set Form Dirty';
325
+ },
326
+ enumerable: true,
327
+ configurable: true
328
+ });
329
+ return SetFormDirty;
330
+ }());
331
+ if (false) {
332
+ /** @type {?} */
333
+ SetFormDirty.prototype.payload;
334
+ }
335
+ var SetFormPristine = /** @class */ (function () {
336
+ function SetFormPristine(payload) {
337
+ this.payload = payload;
338
+ }
339
+ Object.defineProperty(SetFormPristine, "type", {
340
+ get: /**
341
+ * @return {?}
342
+ */
343
+ function () {
344
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
345
+ return '[Forms] Set Form Pristine';
346
+ },
347
+ enumerable: true,
348
+ configurable: true
349
+ });
350
+ return SetFormPristine;
351
+ }());
352
+ if (false) {
353
+ /** @type {?} */
354
+ SetFormPristine.prototype.payload;
355
+ }
356
+ var UpdateFormErrors = /** @class */ (function () {
357
+ function UpdateFormErrors(payload) {
358
+ this.payload = payload;
359
+ }
360
+ Object.defineProperty(UpdateFormErrors, "type", {
361
+ get: /**
362
+ * @return {?}
363
+ */
364
+ function () {
365
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
366
+ return '[Forms] Update Form Errors';
367
+ },
368
+ enumerable: true,
369
+ configurable: true
370
+ });
371
+ return UpdateFormErrors;
372
+ }());
373
+ if (false) {
374
+ /** @type {?} */
375
+ UpdateFormErrors.prototype.payload;
376
+ }
377
+ var SetFormDisabled = /** @class */ (function () {
378
+ function SetFormDisabled(payload) {
379
+ this.payload = payload;
380
+ }
381
+ Object.defineProperty(SetFormDisabled, "type", {
382
+ get: /**
383
+ * @return {?}
384
+ */
385
+ function () {
386
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
387
+ return '[Forms] Set Form Disabled';
388
+ },
389
+ enumerable: true,
390
+ configurable: true
391
+ });
392
+ return SetFormDisabled;
393
+ }());
394
+ if (false) {
395
+ /** @type {?} */
396
+ SetFormDisabled.prototype.payload;
397
+ }
398
+ var SetFormEnabled = /** @class */ (function () {
399
+ function SetFormEnabled(payload) {
400
+ this.payload = payload;
401
+ }
402
+ Object.defineProperty(SetFormEnabled, "type", {
403
+ get: /**
404
+ * @return {?}
405
+ */
406
+ function () {
407
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
408
+ return '[Forms] Set Form Enabled';
409
+ },
410
+ enumerable: true,
411
+ configurable: true
412
+ });
413
+ return SetFormEnabled;
414
+ }());
415
+ if (false) {
416
+ /** @type {?} */
417
+ SetFormEnabled.prototype.payload;
418
+ }
419
+ var ResetForm = /** @class */ (function () {
420
+ function ResetForm(payload) {
421
+ this.payload = payload;
422
+ }
423
+ Object.defineProperty(ResetForm, "type", {
424
+ get: /**
425
+ * @return {?}
426
+ */
427
+ function () {
428
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
429
+ return '[Forms] Reset Form';
430
+ },
431
+ enumerable: true,
432
+ configurable: true
433
+ });
434
+ return ResetForm;
435
+ }());
436
+ if (false) {
437
+ /** @type {?} */
438
+ ResetForm.prototype.payload;
439
439
  }
440
440
 
441
- /**
442
- * @fileoverview added by tsickle
443
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
444
- */
445
- var NgxsFormPlugin = /** @class */ (function () {
446
- function NgxsFormPlugin() {
447
- }
448
- /**
449
- * @param {?} state
450
- * @param {?} event
451
- * @param {?} next
452
- * @return {?}
453
- */
454
- NgxsFormPlugin.prototype.handle = /**
455
- * @param {?} state
456
- * @param {?} event
457
- * @param {?} next
458
- * @return {?}
459
- */
460
- function (state, event, next) {
461
- /** @type {?} */
462
- var type = store.getActionTypeFromInstance(event);
463
- /** @type {?} */
464
- var nextState = state;
465
- if (type === UpdateFormValue.type || type === UpdateForm.type || type === ResetForm.type) {
466
- var value = event.payload.value;
467
- /** @type {?} */
468
- var payloadValue = Array.isArray(value)
469
- ? value.slice()
470
- : isObjectLike(value)
471
- ? __assign({}, value) : value;
472
- /** @type {?} */
473
- var path = this.joinPathWithPropertyPath(event);
474
- nextState = store.setValue(nextState, path, payloadValue);
475
- }
476
- if (type === ResetForm.type) {
477
- /** @type {?} */
478
- var model = store.getValue(nextState, event.payload.path + ".model");
479
- nextState = store.setValue(nextState, "" + event.payload.path, { model: model });
480
- }
481
- if (type === UpdateFormStatus.type || type === UpdateForm.type) {
482
- nextState = store.setValue(nextState, event.payload.path + ".status", event.payload.status);
483
- }
484
- if (type === UpdateFormErrors.type || type === UpdateForm.type) {
485
- nextState = store.setValue(nextState, event.payload.path + ".errors", __assign({}, event.payload.errors));
486
- }
487
- if (type === UpdateFormDirty.type || type === UpdateForm.type) {
488
- nextState = store.setValue(nextState, event.payload.path + ".dirty", event.payload.dirty);
489
- }
490
- if (type === SetFormDirty.type) {
491
- nextState = store.setValue(nextState, event.payload + ".dirty", true);
492
- }
493
- if (type === SetFormPristine.type) {
494
- nextState = store.setValue(nextState, event.payload + ".dirty", false);
495
- }
496
- if (type === SetFormDisabled.type) {
497
- nextState = store.setValue(nextState, event.payload + ".disabled", true);
498
- }
499
- if (type === SetFormEnabled.type) {
500
- nextState = store.setValue(nextState, event.payload + ".disabled", false);
501
- }
502
- return next(nextState, event);
503
- };
504
- /**
505
- * @private
506
- * @param {?} __0
507
- * @return {?}
508
- */
509
- NgxsFormPlugin.prototype.joinPathWithPropertyPath = /**
510
- * @private
511
- * @param {?} __0
512
- * @return {?}
513
- */
514
- function (_a) {
515
- var payload = _a.payload;
516
- /** @type {?} */
517
- var path = payload.path + ".model";
518
- if (payload.propertyPath) {
519
- path += "." + payload.propertyPath;
520
- }
521
- return path;
522
- };
523
- NgxsFormPlugin.decorators = [
524
- { type: core.Injectable }
525
- ];
526
- return NgxsFormPlugin;
527
- }());
528
- /**
529
- * @param {?} target
530
- * @return {?}
531
- */
532
- function isObjectLike(target) {
533
- return target !== null && typeof target === 'object';
441
+ /**
442
+ * @fileoverview added by tsickle
443
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
444
+ */
445
+ var NgxsFormPlugin = /** @class */ (function () {
446
+ function NgxsFormPlugin() {
447
+ }
448
+ /**
449
+ * @param {?} state
450
+ * @param {?} event
451
+ * @param {?} next
452
+ * @return {?}
453
+ */
454
+ NgxsFormPlugin.prototype.handle = /**
455
+ * @param {?} state
456
+ * @param {?} event
457
+ * @param {?} next
458
+ * @return {?}
459
+ */
460
+ function (state, event, next) {
461
+ /** @type {?} */
462
+ var type = store.getActionTypeFromInstance(event);
463
+ /** @type {?} */
464
+ var nextState = state;
465
+ if (type === UpdateFormValue.type || type === UpdateForm.type || type === ResetForm.type) {
466
+ var value = event.payload.value;
467
+ /** @type {?} */
468
+ var payloadValue = Array.isArray(value)
469
+ ? value.slice()
470
+ : isObjectLike(value)
471
+ ? __assign({}, value) : value;
472
+ /** @type {?} */
473
+ var path = this.joinPathWithPropertyPath(event);
474
+ nextState = store.setValue(nextState, path, payloadValue);
475
+ }
476
+ if (type === ResetForm.type) {
477
+ /** @type {?} */
478
+ var model = store.getValue(nextState, event.payload.path + ".model");
479
+ nextState = store.setValue(nextState, "" + event.payload.path, { model: model });
480
+ }
481
+ if (type === UpdateFormStatus.type || type === UpdateForm.type) {
482
+ nextState = store.setValue(nextState, event.payload.path + ".status", event.payload.status);
483
+ }
484
+ if (type === UpdateFormErrors.type || type === UpdateForm.type) {
485
+ nextState = store.setValue(nextState, event.payload.path + ".errors", __assign({}, event.payload.errors));
486
+ }
487
+ if (type === UpdateFormDirty.type || type === UpdateForm.type) {
488
+ nextState = store.setValue(nextState, event.payload.path + ".dirty", event.payload.dirty);
489
+ }
490
+ if (type === SetFormDirty.type) {
491
+ nextState = store.setValue(nextState, event.payload + ".dirty", true);
492
+ }
493
+ if (type === SetFormPristine.type) {
494
+ nextState = store.setValue(nextState, event.payload + ".dirty", false);
495
+ }
496
+ if (type === SetFormDisabled.type) {
497
+ nextState = store.setValue(nextState, event.payload + ".disabled", true);
498
+ }
499
+ if (type === SetFormEnabled.type) {
500
+ nextState = store.setValue(nextState, event.payload + ".disabled", false);
501
+ }
502
+ return next(nextState, event);
503
+ };
504
+ /**
505
+ * @private
506
+ * @param {?} __0
507
+ * @return {?}
508
+ */
509
+ NgxsFormPlugin.prototype.joinPathWithPropertyPath = /**
510
+ * @private
511
+ * @param {?} __0
512
+ * @return {?}
513
+ */
514
+ function (_a) {
515
+ var payload = _a.payload;
516
+ /** @type {?} */
517
+ var path = payload.path + ".model";
518
+ if (payload.propertyPath) {
519
+ path += "." + payload.propertyPath;
520
+ }
521
+ return path;
522
+ };
523
+ NgxsFormPlugin.decorators = [
524
+ { type: core.Injectable }
525
+ ];
526
+ return NgxsFormPlugin;
527
+ }());
528
+ /**
529
+ * @param {?} target
530
+ * @return {?}
531
+ */
532
+ function isObjectLike(target) {
533
+ return target !== null && typeof target === 'object';
534
534
  }
535
535
 
536
- /**
537
- * @fileoverview added by tsickle
538
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
539
- */
540
- var FormDirective = /** @class */ (function () {
541
- function FormDirective(_actions$, _store, _formGroupDirective, _cd) {
542
- this._actions$ = _actions$;
543
- this._store = _store;
544
- this._formGroupDirective = _formGroupDirective;
545
- this._cd = _cd;
546
- this.path = (/** @type {?} */ (null));
547
- this.debounce = 100;
548
- this._clearDestroy = false;
549
- this._destroy$ = new rxjs.Subject();
550
- this._updating = false;
551
- }
552
- Object.defineProperty(FormDirective.prototype, "clearDestroy", {
553
- get: /**
554
- * @return {?}
555
- */
556
- function () {
557
- return this._clearDestroy;
558
- },
559
- set: /**
560
- * @param {?} val
561
- * @return {?}
562
- */
563
- function (val) {
564
- this._clearDestroy = val != null && "" + val !== 'false';
565
- },
566
- enumerable: true,
567
- configurable: true
568
- });
569
- /**
570
- * @return {?}
571
- */
572
- FormDirective.prototype.ngOnInit = /**
573
- * @return {?}
574
- */
575
- function () {
576
- var _this = this;
577
- this._actions$
578
- .pipe(store.ofActionDispatched(ResetForm), operators.filter((/**
579
- * @param {?} action
580
- * @return {?}
581
- */
582
- function (action) { return action.payload.path === _this.path; })), operators.takeUntil(this._destroy$))
583
- .subscribe((/**
584
- * @param {?} __0
585
- * @return {?}
586
- */
587
- function (_a) {
588
- var value = _a.payload.value;
589
- _this.form.reset(value);
590
- _this.updateFormStateWithRawValue(true);
591
- _this._cd.markForCheck();
592
- }));
593
- this.getStateStream(this.path + ".model").subscribe((/**
594
- * @param {?} model
595
- * @return {?}
596
- */
597
- function (model) {
598
- if (_this._updating || !model) {
599
- return;
600
- }
601
- _this.form.patchValue(model);
602
- _this._cd.markForCheck();
603
- }));
604
- this.getStateStream(this.path + ".dirty").subscribe((/**
605
- * @param {?} dirty
606
- * @return {?}
607
- */
608
- function (dirty) {
609
- if (_this.form.dirty === dirty || typeof dirty !== 'boolean') {
610
- return;
611
- }
612
- if (dirty) {
613
- _this.form.markAsDirty();
614
- }
615
- else {
616
- _this.form.markAsPristine();
617
- }
618
- _this._cd.markForCheck();
619
- }));
620
- // On first state change, sync form model, status and dirty with state
621
- this._store
622
- .selectOnce((/**
623
- * @param {?} state
624
- * @return {?}
625
- */
626
- function (state) { return store.getValue(state, _this.path); }))
627
- .subscribe((/**
628
- * @return {?}
629
- */
630
- function () {
631
- _this._store.dispatch([
632
- new UpdateFormValue({
633
- path: _this.path,
634
- value: _this.form.getRawValue()
635
- }),
636
- new UpdateFormStatus({
637
- path: _this.path,
638
- status: _this.form.status
639
- }),
640
- new UpdateFormDirty({
641
- path: _this.path,
642
- dirty: _this.form.dirty
643
- })
644
- ]);
645
- }));
646
- this.getStateStream(this.path + ".disabled").subscribe((/**
647
- * @param {?} disabled
648
- * @return {?}
649
- */
650
- function (disabled) {
651
- if (_this.form.disabled === disabled || typeof disabled !== 'boolean') {
652
- return;
653
- }
654
- if (disabled) {
655
- _this.form.disable();
656
- }
657
- else {
658
- _this.form.enable();
659
- }
660
- _this._cd.markForCheck();
661
- }));
662
- (/** @type {?} */ (this._formGroupDirective.valueChanges)).pipe(this.debounceChange()).subscribe((/**
663
- * @return {?}
664
- */
665
- function () {
666
- _this.updateFormStateWithRawValue();
667
- }));
668
- (/** @type {?} */ (this._formGroupDirective
669
- .statusChanges)).pipe(operators.distinctUntilChanged(), this.debounceChange())
670
- .subscribe((/**
671
- * @param {?} status
672
- * @return {?}
673
- */
674
- function (status) {
675
- _this._store.dispatch(new UpdateFormStatus({
676
- status: status,
677
- path: _this.path
678
- }));
679
- }));
680
- };
681
- /**
682
- * @param {?=} withFormStatus
683
- * @return {?}
684
- */
685
- FormDirective.prototype.updateFormStateWithRawValue = /**
686
- * @param {?=} withFormStatus
687
- * @return {?}
688
- */
689
- function (withFormStatus) {
690
- var _this = this;
691
- if (this._updating)
692
- return;
693
- /** @type {?} */
694
- var value = this._formGroupDirective.control.getRawValue();
695
- /** @type {?} */
696
- var actions = [
697
- new UpdateFormValue({
698
- path: this.path,
699
- value: value
700
- }),
701
- new UpdateFormDirty({
702
- path: this.path,
703
- dirty: this._formGroupDirective.dirty
704
- }),
705
- new UpdateFormErrors({
706
- path: this.path,
707
- errors: this._formGroupDirective.errors
708
- })
709
- ];
710
- if (withFormStatus) {
711
- actions.push(new UpdateFormStatus({
712
- path: this.path,
713
- status: this._formGroupDirective.status
714
- }));
715
- }
716
- this._updating = true;
717
- this._store.dispatch(actions).subscribe({
718
- error: (/**
719
- * @return {?}
720
- */
721
- function () { return (_this._updating = false); }),
722
- complete: (/**
723
- * @return {?}
724
- */
725
- function () { return (_this._updating = false); })
726
- });
727
- };
728
- /**
729
- * @return {?}
730
- */
731
- FormDirective.prototype.ngOnDestroy = /**
732
- * @return {?}
733
- */
734
- function () {
735
- this._destroy$.next();
736
- this._destroy$.complete();
737
- if (this.clearDestroy) {
738
- this._store.dispatch(new UpdateForm({
739
- path: this.path,
740
- value: null,
741
- dirty: null,
742
- status: null,
743
- errors: null
744
- }));
745
- }
746
- };
747
- /**
748
- * @private
749
- * @return {?}
750
- */
751
- FormDirective.prototype.debounceChange = /**
752
- * @private
753
- * @return {?}
754
- */
755
- function () {
756
- var _this = this;
757
- /** @type {?} */
758
- var skipDebounceTime = this._formGroupDirective.control.updateOn !== 'change' || this.debounce < 0;
759
- return skipDebounceTime
760
- ? (/**
761
- * @param {?} change
762
- * @return {?}
763
- */
764
- function (change) { return change.pipe(operators.takeUntil(_this._destroy$)); })
765
- : (/**
766
- * @param {?} change
767
- * @return {?}
768
- */
769
- function (change) {
770
- return change.pipe(operators.debounceTime(_this.debounce), operators.takeUntil(_this._destroy$));
771
- });
772
- };
773
- Object.defineProperty(FormDirective.prototype, "form", {
774
- get: /**
775
- * @private
776
- * @return {?}
777
- */
778
- function () {
779
- return this._formGroupDirective.form;
780
- },
781
- enumerable: true,
782
- configurable: true
783
- });
784
- /**
785
- * @private
786
- * @param {?} path
787
- * @return {?}
788
- */
789
- FormDirective.prototype.getStateStream = /**
790
- * @private
791
- * @param {?} path
792
- * @return {?}
793
- */
794
- function (path) {
795
- return this._store.select((/**
796
- * @param {?} state
797
- * @return {?}
798
- */
799
- function (state) { return store.getValue(state, path); })).pipe(operators.takeUntil(this._destroy$));
800
- };
801
- FormDirective.decorators = [
802
- { type: core.Directive, args: [{ selector: '[ngxsForm]' },] }
803
- ];
804
- /** @nocollapse */
805
- FormDirective.ctorParameters = function () { return [
806
- { type: store.Actions },
807
- { type: store.Store },
808
- { type: forms.FormGroupDirective },
809
- { type: core.ChangeDetectorRef }
810
- ]; };
811
- FormDirective.propDecorators = {
812
- path: [{ type: core.Input, args: ['ngxsForm',] }],
813
- debounce: [{ type: core.Input, args: ['ngxsFormDebounce',] }],
814
- clearDestroy: [{ type: core.Input, args: ['ngxsFormClearOnDestroy',] }]
815
- };
816
- return FormDirective;
817
- }());
818
- if (false) {
819
- /** @type {?} */
820
- FormDirective.prototype.path;
821
- /** @type {?} */
822
- FormDirective.prototype.debounce;
823
- /** @type {?} */
824
- FormDirective.prototype._clearDestroy;
825
- /**
826
- * @type {?}
827
- * @private
828
- */
829
- FormDirective.prototype._destroy$;
830
- /**
831
- * @type {?}
832
- * @private
833
- */
834
- FormDirective.prototype._updating;
835
- /**
836
- * @type {?}
837
- * @private
838
- */
839
- FormDirective.prototype._actions$;
840
- /**
841
- * @type {?}
842
- * @private
843
- */
844
- FormDirective.prototype._store;
845
- /**
846
- * @type {?}
847
- * @private
848
- */
849
- FormDirective.prototype._formGroupDirective;
850
- /**
851
- * @type {?}
852
- * @private
853
- */
854
- FormDirective.prototype._cd;
536
+ /**
537
+ * @fileoverview added by tsickle
538
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
539
+ */
540
+ var FormDirective = /** @class */ (function () {
541
+ function FormDirective(_actions$, _store, _formGroupDirective, _cd) {
542
+ this._actions$ = _actions$;
543
+ this._store = _store;
544
+ this._formGroupDirective = _formGroupDirective;
545
+ this._cd = _cd;
546
+ this.path = (/** @type {?} */ (null));
547
+ this.debounce = 100;
548
+ this._clearDestroy = false;
549
+ this._destroy$ = new rxjs.Subject();
550
+ this._updating = false;
551
+ }
552
+ Object.defineProperty(FormDirective.prototype, "clearDestroy", {
553
+ get: /**
554
+ * @return {?}
555
+ */
556
+ function () {
557
+ return this._clearDestroy;
558
+ },
559
+ set: /**
560
+ * @param {?} val
561
+ * @return {?}
562
+ */
563
+ function (val) {
564
+ this._clearDestroy = val != null && "" + val !== 'false';
565
+ },
566
+ enumerable: true,
567
+ configurable: true
568
+ });
569
+ /**
570
+ * @return {?}
571
+ */
572
+ FormDirective.prototype.ngOnInit = /**
573
+ * @return {?}
574
+ */
575
+ function () {
576
+ var _this = this;
577
+ this._actions$
578
+ .pipe(store.ofActionDispatched(ResetForm), operators.filter((/**
579
+ * @param {?} action
580
+ * @return {?}
581
+ */
582
+ function (action) { return action.payload.path === _this.path; })), operators.takeUntil(this._destroy$))
583
+ .subscribe((/**
584
+ * @param {?} __0
585
+ * @return {?}
586
+ */
587
+ function (_a) {
588
+ var value = _a.payload.value;
589
+ _this.form.reset(value);
590
+ _this.updateFormStateWithRawValue(true);
591
+ _this._cd.markForCheck();
592
+ }));
593
+ this.getStateStream(this.path + ".model").subscribe((/**
594
+ * @param {?} model
595
+ * @return {?}
596
+ */
597
+ function (model) {
598
+ if (_this._updating || !model) {
599
+ return;
600
+ }
601
+ _this.form.patchValue(model);
602
+ _this._cd.markForCheck();
603
+ }));
604
+ this.getStateStream(this.path + ".dirty").subscribe((/**
605
+ * @param {?} dirty
606
+ * @return {?}
607
+ */
608
+ function (dirty) {
609
+ if (_this.form.dirty === dirty || typeof dirty !== 'boolean') {
610
+ return;
611
+ }
612
+ if (dirty) {
613
+ _this.form.markAsDirty();
614
+ }
615
+ else {
616
+ _this.form.markAsPristine();
617
+ }
618
+ _this._cd.markForCheck();
619
+ }));
620
+ // On first state change, sync form model, status and dirty with state
621
+ this._store
622
+ .selectOnce((/**
623
+ * @param {?} state
624
+ * @return {?}
625
+ */
626
+ function (state) { return store.getValue(state, _this.path); }))
627
+ .subscribe((/**
628
+ * @return {?}
629
+ */
630
+ function () {
631
+ _this._store.dispatch([
632
+ new UpdateFormValue({
633
+ path: _this.path,
634
+ value: _this.form.getRawValue()
635
+ }),
636
+ new UpdateFormStatus({
637
+ path: _this.path,
638
+ status: _this.form.status
639
+ }),
640
+ new UpdateFormDirty({
641
+ path: _this.path,
642
+ dirty: _this.form.dirty
643
+ })
644
+ ]);
645
+ }));
646
+ this.getStateStream(this.path + ".disabled").subscribe((/**
647
+ * @param {?} disabled
648
+ * @return {?}
649
+ */
650
+ function (disabled) {
651
+ if (_this.form.disabled === disabled || typeof disabled !== 'boolean') {
652
+ return;
653
+ }
654
+ if (disabled) {
655
+ _this.form.disable();
656
+ }
657
+ else {
658
+ _this.form.enable();
659
+ }
660
+ _this._cd.markForCheck();
661
+ }));
662
+ (/** @type {?} */ (this._formGroupDirective
663
+ .valueChanges)).pipe(operators.distinctUntilChanged((/**
664
+ * @param {?} a
665
+ * @param {?} b
666
+ * @return {?}
667
+ */
668
+ function (a, b) { return JSON.stringify(a) === JSON.stringify(b); })), this.debounceChange())
669
+ .subscribe((/**
670
+ * @return {?}
671
+ */
672
+ function () {
673
+ _this.updateFormStateWithRawValue();
674
+ }));
675
+ (/** @type {?} */ (this._formGroupDirective
676
+ .statusChanges)).pipe(operators.distinctUntilChanged(), this.debounceChange())
677
+ .subscribe((/**
678
+ * @param {?} status
679
+ * @return {?}
680
+ */
681
+ function (status) {
682
+ _this._store.dispatch(new UpdateFormStatus({
683
+ status: status,
684
+ path: _this.path
685
+ }));
686
+ }));
687
+ };
688
+ /**
689
+ * @param {?=} withFormStatus
690
+ * @return {?}
691
+ */
692
+ FormDirective.prototype.updateFormStateWithRawValue = /**
693
+ * @param {?=} withFormStatus
694
+ * @return {?}
695
+ */
696
+ function (withFormStatus) {
697
+ var _this = this;
698
+ if (this._updating)
699
+ return;
700
+ /** @type {?} */
701
+ var value = this._formGroupDirective.control.getRawValue();
702
+ /** @type {?} */
703
+ var actions = [
704
+ new UpdateFormValue({
705
+ path: this.path,
706
+ value: value
707
+ }),
708
+ new UpdateFormDirty({
709
+ path: this.path,
710
+ dirty: this._formGroupDirective.dirty
711
+ }),
712
+ new UpdateFormErrors({
713
+ path: this.path,
714
+ errors: this._formGroupDirective.errors
715
+ })
716
+ ];
717
+ if (withFormStatus) {
718
+ actions.push(new UpdateFormStatus({
719
+ path: this.path,
720
+ status: this._formGroupDirective.status
721
+ }));
722
+ }
723
+ this._updating = true;
724
+ this._store.dispatch(actions).subscribe({
725
+ error: (/**
726
+ * @return {?}
727
+ */
728
+ function () { return (_this._updating = false); }),
729
+ complete: (/**
730
+ * @return {?}
731
+ */
732
+ function () { return (_this._updating = false); })
733
+ });
734
+ };
735
+ /**
736
+ * @return {?}
737
+ */
738
+ FormDirective.prototype.ngOnDestroy = /**
739
+ * @return {?}
740
+ */
741
+ function () {
742
+ this._destroy$.next();
743
+ this._destroy$.complete();
744
+ if (this.clearDestroy) {
745
+ this._store.dispatch(new UpdateForm({
746
+ path: this.path,
747
+ value: null,
748
+ dirty: null,
749
+ status: null,
750
+ errors: null
751
+ }));
752
+ }
753
+ };
754
+ /**
755
+ * @private
756
+ * @return {?}
757
+ */
758
+ FormDirective.prototype.debounceChange = /**
759
+ * @private
760
+ * @return {?}
761
+ */
762
+ function () {
763
+ var _this = this;
764
+ /** @type {?} */
765
+ var skipDebounceTime = this._formGroupDirective.control.updateOn !== 'change' || this.debounce < 0;
766
+ return skipDebounceTime
767
+ ? (/**
768
+ * @param {?} change
769
+ * @return {?}
770
+ */
771
+ function (change) { return change.pipe(operators.takeUntil(_this._destroy$)); })
772
+ : (/**
773
+ * @param {?} change
774
+ * @return {?}
775
+ */
776
+ function (change) {
777
+ return change.pipe(operators.debounceTime(_this.debounce), operators.takeUntil(_this._destroy$));
778
+ });
779
+ };
780
+ Object.defineProperty(FormDirective.prototype, "form", {
781
+ get: /**
782
+ * @private
783
+ * @return {?}
784
+ */
785
+ function () {
786
+ return this._formGroupDirective.form;
787
+ },
788
+ enumerable: true,
789
+ configurable: true
790
+ });
791
+ /**
792
+ * @private
793
+ * @param {?} path
794
+ * @return {?}
795
+ */
796
+ FormDirective.prototype.getStateStream = /**
797
+ * @private
798
+ * @param {?} path
799
+ * @return {?}
800
+ */
801
+ function (path) {
802
+ return this._store.select((/**
803
+ * @param {?} state
804
+ * @return {?}
805
+ */
806
+ function (state) { return store.getValue(state, path); })).pipe(operators.takeUntil(this._destroy$));
807
+ };
808
+ FormDirective.decorators = [
809
+ { type: core.Directive, args: [{ selector: '[ngxsForm]' },] }
810
+ ];
811
+ /** @nocollapse */
812
+ FormDirective.ctorParameters = function () { return [
813
+ { type: store.Actions },
814
+ { type: store.Store },
815
+ { type: forms.FormGroupDirective },
816
+ { type: core.ChangeDetectorRef }
817
+ ]; };
818
+ FormDirective.propDecorators = {
819
+ path: [{ type: core.Input, args: ['ngxsForm',] }],
820
+ debounce: [{ type: core.Input, args: ['ngxsFormDebounce',] }],
821
+ clearDestroy: [{ type: core.Input, args: ['ngxsFormClearOnDestroy',] }]
822
+ };
823
+ return FormDirective;
824
+ }());
825
+ if (false) {
826
+ /** @type {?} */
827
+ FormDirective.prototype.path;
828
+ /** @type {?} */
829
+ FormDirective.prototype.debounce;
830
+ /** @type {?} */
831
+ FormDirective.prototype._clearDestroy;
832
+ /**
833
+ * @type {?}
834
+ * @private
835
+ */
836
+ FormDirective.prototype._destroy$;
837
+ /**
838
+ * @type {?}
839
+ * @private
840
+ */
841
+ FormDirective.prototype._updating;
842
+ /**
843
+ * @type {?}
844
+ * @private
845
+ */
846
+ FormDirective.prototype._actions$;
847
+ /**
848
+ * @type {?}
849
+ * @private
850
+ */
851
+ FormDirective.prototype._store;
852
+ /**
853
+ * @type {?}
854
+ * @private
855
+ */
856
+ FormDirective.prototype._formGroupDirective;
857
+ /**
858
+ * @type {?}
859
+ * @private
860
+ */
861
+ FormDirective.prototype._cd;
855
862
  }
856
863
 
857
- /**
858
- * @fileoverview added by tsickle
859
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
860
- */
861
- var NgxsFormPluginModule = /** @class */ (function () {
862
- function NgxsFormPluginModule() {
863
- }
864
- /**
865
- * @return {?}
866
- */
867
- NgxsFormPluginModule.forRoot = /**
868
- * @return {?}
869
- */
870
- function () {
871
- return {
872
- ngModule: NgxsFormPluginModule,
873
- providers: [
874
- {
875
- provide: store.NGXS_PLUGINS,
876
- useClass: NgxsFormPlugin,
877
- multi: true
878
- }
879
- ]
880
- };
881
- };
882
- NgxsFormPluginModule.decorators = [
883
- { type: core.NgModule, args: [{
884
- imports: [forms.ReactiveFormsModule],
885
- declarations: [FormDirective],
886
- exports: [FormDirective]
887
- },] }
888
- ];
889
- return NgxsFormPluginModule;
864
+ /**
865
+ * @fileoverview added by tsickle
866
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
867
+ */
868
+ var NgxsFormPluginModule = /** @class */ (function () {
869
+ function NgxsFormPluginModule() {
870
+ }
871
+ /**
872
+ * @return {?}
873
+ */
874
+ NgxsFormPluginModule.forRoot = /**
875
+ * @return {?}
876
+ */
877
+ function () {
878
+ return {
879
+ ngModule: NgxsFormPluginModule,
880
+ providers: [
881
+ {
882
+ provide: store.NGXS_PLUGINS,
883
+ useClass: NgxsFormPlugin,
884
+ multi: true
885
+ }
886
+ ]
887
+ };
888
+ };
889
+ NgxsFormPluginModule.decorators = [
890
+ { type: core.NgModule, args: [{
891
+ imports: [forms.ReactiveFormsModule],
892
+ declarations: [FormDirective],
893
+ exports: [FormDirective]
894
+ },] }
895
+ ];
896
+ return NgxsFormPluginModule;
890
897
  }());
891
898
 
892
899
  exports.NgxsFormPlugin = NgxsFormPlugin;