@ngxs/form-plugin 3.7.3-dev.master-8834f50 → 3.7.3

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,660 +223,660 @@
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) ? value.slice() : __assign({}, value);
469
- /** @type {?} */
470
- var path = this.joinPathWithPropertyPath(event);
471
- nextState = store.setValue(nextState, path, payloadValue);
472
- }
473
- if (type === ResetForm.type) {
474
- /** @type {?} */
475
- var model = store.getValue(nextState, event.payload.path + ".model");
476
- nextState = store.setValue(nextState, "" + event.payload.path, { model: model });
477
- }
478
- if (type === UpdateFormStatus.type || type === UpdateForm.type) {
479
- nextState = store.setValue(nextState, event.payload.path + ".status", event.payload.status);
480
- }
481
- if (type === UpdateFormErrors.type || type === UpdateForm.type) {
482
- nextState = store.setValue(nextState, event.payload.path + ".errors", __assign({}, event.payload.errors));
483
- }
484
- if (type === UpdateFormDirty.type || type === UpdateForm.type) {
485
- nextState = store.setValue(nextState, event.payload.path + ".dirty", event.payload.dirty);
486
- }
487
- if (type === SetFormDirty.type) {
488
- nextState = store.setValue(nextState, event.payload + ".dirty", true);
489
- }
490
- if (type === SetFormPristine.type) {
491
- nextState = store.setValue(nextState, event.payload + ".dirty", false);
492
- }
493
- if (type === SetFormDisabled.type) {
494
- nextState = store.setValue(nextState, event.payload + ".disabled", true);
495
- }
496
- if (type === SetFormEnabled.type) {
497
- nextState = store.setValue(nextState, event.payload + ".disabled", false);
498
- }
499
- return next(nextState, event);
500
- };
501
- /**
502
- * @private
503
- * @param {?} __0
504
- * @return {?}
505
- */
506
- NgxsFormPlugin.prototype.joinPathWithPropertyPath = /**
507
- * @private
508
- * @param {?} __0
509
- * @return {?}
510
- */
511
- function (_a) {
512
- var payload = _a.payload;
513
- /** @type {?} */
514
- var path = payload.path + ".model";
515
- if (payload.propertyPath) {
516
- path += "." + payload.propertyPath;
517
- }
518
- return path;
519
- };
520
- NgxsFormPlugin.decorators = [
521
- { type: core.Injectable }
522
- ];
523
- return NgxsFormPlugin;
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) ? value.slice() : __assign({}, value);
469
+ /** @type {?} */
470
+ var path = this.joinPathWithPropertyPath(event);
471
+ nextState = store.setValue(nextState, path, payloadValue);
472
+ }
473
+ if (type === ResetForm.type) {
474
+ /** @type {?} */
475
+ var model = store.getValue(nextState, event.payload.path + ".model");
476
+ nextState = store.setValue(nextState, "" + event.payload.path, { model: model });
477
+ }
478
+ if (type === UpdateFormStatus.type || type === UpdateForm.type) {
479
+ nextState = store.setValue(nextState, event.payload.path + ".status", event.payload.status);
480
+ }
481
+ if (type === UpdateFormErrors.type || type === UpdateForm.type) {
482
+ nextState = store.setValue(nextState, event.payload.path + ".errors", __assign({}, event.payload.errors));
483
+ }
484
+ if (type === UpdateFormDirty.type || type === UpdateForm.type) {
485
+ nextState = store.setValue(nextState, event.payload.path + ".dirty", event.payload.dirty);
486
+ }
487
+ if (type === SetFormDirty.type) {
488
+ nextState = store.setValue(nextState, event.payload + ".dirty", true);
489
+ }
490
+ if (type === SetFormPristine.type) {
491
+ nextState = store.setValue(nextState, event.payload + ".dirty", false);
492
+ }
493
+ if (type === SetFormDisabled.type) {
494
+ nextState = store.setValue(nextState, event.payload + ".disabled", true);
495
+ }
496
+ if (type === SetFormEnabled.type) {
497
+ nextState = store.setValue(nextState, event.payload + ".disabled", false);
498
+ }
499
+ return next(nextState, event);
500
+ };
501
+ /**
502
+ * @private
503
+ * @param {?} __0
504
+ * @return {?}
505
+ */
506
+ NgxsFormPlugin.prototype.joinPathWithPropertyPath = /**
507
+ * @private
508
+ * @param {?} __0
509
+ * @return {?}
510
+ */
511
+ function (_a) {
512
+ var payload = _a.payload;
513
+ /** @type {?} */
514
+ var path = payload.path + ".model";
515
+ if (payload.propertyPath) {
516
+ path += "." + payload.propertyPath;
517
+ }
518
+ return path;
519
+ };
520
+ NgxsFormPlugin.decorators = [
521
+ { type: core.Injectable }
522
+ ];
523
+ return NgxsFormPlugin;
524
524
  }());
525
525
 
526
- /**
527
- * @fileoverview added by tsickle
528
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
529
- */
530
- var FormDirective = /** @class */ (function () {
531
- function FormDirective(_actions$, _store, _formGroupDirective, _cd) {
532
- this._actions$ = _actions$;
533
- this._store = _store;
534
- this._formGroupDirective = _formGroupDirective;
535
- this._cd = _cd;
536
- this.path = (/** @type {?} */ (null));
537
- this.debounce = 100;
538
- this._clearDestroy = false;
539
- this._destroy$ = new rxjs.Subject();
540
- this._updating = false;
541
- }
542
- Object.defineProperty(FormDirective.prototype, "clearDestroy", {
543
- get: /**
544
- * @return {?}
545
- */
546
- function () {
547
- return this._clearDestroy;
548
- },
549
- set: /**
550
- * @param {?} val
551
- * @return {?}
552
- */
553
- function (val) {
554
- this._clearDestroy = val != null && "" + val !== 'false';
555
- },
556
- enumerable: true,
557
- configurable: true
558
- });
559
- /**
560
- * @return {?}
561
- */
562
- FormDirective.prototype.ngOnInit = /**
563
- * @return {?}
564
- */
565
- function () {
566
- var _this = this;
567
- this._actions$
568
- .pipe(store.ofActionDispatched(ResetForm), operators.filter((/**
569
- * @param {?} action
570
- * @return {?}
571
- */
572
- function (action) { return action.payload.path === _this.path; })), operators.takeUntil(this._destroy$))
573
- .subscribe((/**
574
- * @param {?} __0
575
- * @return {?}
576
- */
577
- function (_a) {
578
- var value = _a.payload.value;
579
- _this.form.reset(value);
580
- _this.updateFormStateWithRawValue(true);
581
- _this._cd.markForCheck();
582
- }));
583
- this.getStateStream(this.path + ".model").subscribe((/**
584
- * @param {?} model
585
- * @return {?}
586
- */
587
- function (model) {
588
- if (_this._updating || !model) {
589
- return;
590
- }
591
- _this.form.patchValue(model);
592
- _this._cd.markForCheck();
593
- }));
594
- this.getStateStream(this.path + ".dirty").subscribe((/**
595
- * @param {?} dirty
596
- * @return {?}
597
- */
598
- function (dirty) {
599
- if (_this.form.dirty === dirty || typeof dirty !== 'boolean') {
600
- return;
601
- }
602
- if (dirty) {
603
- _this.form.markAsDirty();
604
- }
605
- else {
606
- _this.form.markAsPristine();
607
- }
608
- _this._cd.markForCheck();
609
- }));
610
- // On first state change, sync form model, status and dirty with state
611
- this._store
612
- .selectOnce((/**
613
- * @param {?} state
614
- * @return {?}
615
- */
616
- function (state) { return store.getValue(state, _this.path); }))
617
- .subscribe((/**
618
- * @return {?}
619
- */
620
- function () {
621
- _this._store.dispatch([
622
- new UpdateFormValue({
623
- path: _this.path,
624
- value: _this.form.getRawValue()
625
- }),
626
- new UpdateFormStatus({
627
- path: _this.path,
628
- status: _this.form.status
629
- }),
630
- new UpdateFormDirty({
631
- path: _this.path,
632
- dirty: _this.form.dirty
633
- })
634
- ]);
635
- }));
636
- this.getStateStream(this.path + ".disabled").subscribe((/**
637
- * @param {?} disabled
638
- * @return {?}
639
- */
640
- function (disabled) {
641
- if (_this.form.disabled === disabled || typeof disabled !== 'boolean') {
642
- return;
643
- }
644
- if (disabled) {
645
- _this.form.disable();
646
- }
647
- else {
648
- _this.form.enable();
649
- }
650
- _this._cd.markForCheck();
651
- }));
652
- (/** @type {?} */ (this._formGroupDirective.valueChanges)).pipe(this.debounceChange()).subscribe((/**
653
- * @return {?}
654
- */
655
- function () {
656
- _this.updateFormStateWithRawValue();
657
- }));
658
- (/** @type {?} */ (this._formGroupDirective
659
- .statusChanges)).pipe(operators.distinctUntilChanged(), this.debounceChange())
660
- .subscribe((/**
661
- * @param {?} status
662
- * @return {?}
663
- */
664
- function (status) {
665
- _this._store.dispatch(new UpdateFormStatus({
666
- status: status,
667
- path: _this.path
668
- }));
669
- }));
670
- };
671
- /**
672
- * @param {?=} withFormStatus
673
- * @return {?}
674
- */
675
- FormDirective.prototype.updateFormStateWithRawValue = /**
676
- * @param {?=} withFormStatus
677
- * @return {?}
678
- */
679
- function (withFormStatus) {
680
- var _this = this;
681
- if (this._updating)
682
- return;
683
- /** @type {?} */
684
- var value = this._formGroupDirective.control.getRawValue();
685
- /** @type {?} */
686
- var actions = [
687
- new UpdateFormValue({
688
- path: this.path,
689
- value: value
690
- }),
691
- new UpdateFormDirty({
692
- path: this.path,
693
- dirty: this._formGroupDirective.dirty
694
- }),
695
- new UpdateFormErrors({
696
- path: this.path,
697
- errors: this._formGroupDirective.errors
698
- })
699
- ];
700
- if (withFormStatus) {
701
- actions.push(new UpdateFormStatus({
702
- path: this.path,
703
- status: this._formGroupDirective.status
704
- }));
705
- }
706
- this._updating = true;
707
- this._store.dispatch(actions).subscribe({
708
- error: (/**
709
- * @return {?}
710
- */
711
- function () { return (_this._updating = false); }),
712
- complete: (/**
713
- * @return {?}
714
- */
715
- function () { return (_this._updating = false); })
716
- });
717
- };
718
- /**
719
- * @return {?}
720
- */
721
- FormDirective.prototype.ngOnDestroy = /**
722
- * @return {?}
723
- */
724
- function () {
725
- this._destroy$.next();
726
- this._destroy$.complete();
727
- if (this.clearDestroy) {
728
- this._store.dispatch(new UpdateForm({
729
- path: this.path,
730
- value: null,
731
- dirty: null,
732
- status: null,
733
- errors: null
734
- }));
735
- }
736
- };
737
- /**
738
- * @private
739
- * @return {?}
740
- */
741
- FormDirective.prototype.debounceChange = /**
742
- * @private
743
- * @return {?}
744
- */
745
- function () {
746
- var _this = this;
747
- /** @type {?} */
748
- var skipDebounceTime = this._formGroupDirective.control.updateOn !== 'change' || this.debounce < 0;
749
- return skipDebounceTime
750
- ? (/**
751
- * @param {?} change
752
- * @return {?}
753
- */
754
- function (change) { return change.pipe(operators.takeUntil(_this._destroy$)); })
755
- : (/**
756
- * @param {?} change
757
- * @return {?}
758
- */
759
- function (change) {
760
- return change.pipe(operators.debounceTime(_this.debounce), operators.takeUntil(_this._destroy$));
761
- });
762
- };
763
- Object.defineProperty(FormDirective.prototype, "form", {
764
- get: /**
765
- * @private
766
- * @return {?}
767
- */
768
- function () {
769
- return this._formGroupDirective.form;
770
- },
771
- enumerable: true,
772
- configurable: true
773
- });
774
- /**
775
- * @private
776
- * @param {?} path
777
- * @return {?}
778
- */
779
- FormDirective.prototype.getStateStream = /**
780
- * @private
781
- * @param {?} path
782
- * @return {?}
783
- */
784
- function (path) {
785
- return this._store.select((/**
786
- * @param {?} state
787
- * @return {?}
788
- */
789
- function (state) { return store.getValue(state, path); })).pipe(operators.takeUntil(this._destroy$));
790
- };
791
- FormDirective.decorators = [
792
- { type: core.Directive, args: [{ selector: '[ngxsForm]' },] }
793
- ];
794
- /** @nocollapse */
795
- FormDirective.ctorParameters = function () { return [
796
- { type: store.Actions },
797
- { type: store.Store },
798
- { type: forms.FormGroupDirective },
799
- { type: core.ChangeDetectorRef }
800
- ]; };
801
- FormDirective.propDecorators = {
802
- path: [{ type: core.Input, args: ['ngxsForm',] }],
803
- debounce: [{ type: core.Input, args: ['ngxsFormDebounce',] }],
804
- clearDestroy: [{ type: core.Input, args: ['ngxsFormClearOnDestroy',] }]
805
- };
806
- return FormDirective;
807
- }());
808
- if (false) {
809
- /** @type {?} */
810
- FormDirective.prototype.path;
811
- /** @type {?} */
812
- FormDirective.prototype.debounce;
813
- /** @type {?} */
814
- FormDirective.prototype._clearDestroy;
815
- /**
816
- * @type {?}
817
- * @private
818
- */
819
- FormDirective.prototype._destroy$;
820
- /**
821
- * @type {?}
822
- * @private
823
- */
824
- FormDirective.prototype._updating;
825
- /**
826
- * @type {?}
827
- * @private
828
- */
829
- FormDirective.prototype._actions$;
830
- /**
831
- * @type {?}
832
- * @private
833
- */
834
- FormDirective.prototype._store;
835
- /**
836
- * @type {?}
837
- * @private
838
- */
839
- FormDirective.prototype._formGroupDirective;
840
- /**
841
- * @type {?}
842
- * @private
843
- */
844
- FormDirective.prototype._cd;
526
+ /**
527
+ * @fileoverview added by tsickle
528
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
529
+ */
530
+ var FormDirective = /** @class */ (function () {
531
+ function FormDirective(_actions$, _store, _formGroupDirective, _cd) {
532
+ this._actions$ = _actions$;
533
+ this._store = _store;
534
+ this._formGroupDirective = _formGroupDirective;
535
+ this._cd = _cd;
536
+ this.path = (/** @type {?} */ (null));
537
+ this.debounce = 100;
538
+ this._clearDestroy = false;
539
+ this._destroy$ = new rxjs.Subject();
540
+ this._updating = false;
541
+ }
542
+ Object.defineProperty(FormDirective.prototype, "clearDestroy", {
543
+ get: /**
544
+ * @return {?}
545
+ */
546
+ function () {
547
+ return this._clearDestroy;
548
+ },
549
+ set: /**
550
+ * @param {?} val
551
+ * @return {?}
552
+ */
553
+ function (val) {
554
+ this._clearDestroy = val != null && "" + val !== 'false';
555
+ },
556
+ enumerable: true,
557
+ configurable: true
558
+ });
559
+ /**
560
+ * @return {?}
561
+ */
562
+ FormDirective.prototype.ngOnInit = /**
563
+ * @return {?}
564
+ */
565
+ function () {
566
+ var _this = this;
567
+ this._actions$
568
+ .pipe(store.ofActionDispatched(ResetForm), operators.filter((/**
569
+ * @param {?} action
570
+ * @return {?}
571
+ */
572
+ function (action) { return action.payload.path === _this.path; })), operators.takeUntil(this._destroy$))
573
+ .subscribe((/**
574
+ * @param {?} __0
575
+ * @return {?}
576
+ */
577
+ function (_a) {
578
+ var value = _a.payload.value;
579
+ _this.form.reset(value);
580
+ _this.updateFormStateWithRawValue(true);
581
+ _this._cd.markForCheck();
582
+ }));
583
+ this.getStateStream(this.path + ".model").subscribe((/**
584
+ * @param {?} model
585
+ * @return {?}
586
+ */
587
+ function (model) {
588
+ if (_this._updating || !model) {
589
+ return;
590
+ }
591
+ _this.form.patchValue(model);
592
+ _this._cd.markForCheck();
593
+ }));
594
+ this.getStateStream(this.path + ".dirty").subscribe((/**
595
+ * @param {?} dirty
596
+ * @return {?}
597
+ */
598
+ function (dirty) {
599
+ if (_this.form.dirty === dirty || typeof dirty !== 'boolean') {
600
+ return;
601
+ }
602
+ if (dirty) {
603
+ _this.form.markAsDirty();
604
+ }
605
+ else {
606
+ _this.form.markAsPristine();
607
+ }
608
+ _this._cd.markForCheck();
609
+ }));
610
+ // On first state change, sync form model, status and dirty with state
611
+ this._store
612
+ .selectOnce((/**
613
+ * @param {?} state
614
+ * @return {?}
615
+ */
616
+ function (state) { return store.getValue(state, _this.path); }))
617
+ .subscribe((/**
618
+ * @return {?}
619
+ */
620
+ function () {
621
+ _this._store.dispatch([
622
+ new UpdateFormValue({
623
+ path: _this.path,
624
+ value: _this.form.getRawValue()
625
+ }),
626
+ new UpdateFormStatus({
627
+ path: _this.path,
628
+ status: _this.form.status
629
+ }),
630
+ new UpdateFormDirty({
631
+ path: _this.path,
632
+ dirty: _this.form.dirty
633
+ })
634
+ ]);
635
+ }));
636
+ this.getStateStream(this.path + ".disabled").subscribe((/**
637
+ * @param {?} disabled
638
+ * @return {?}
639
+ */
640
+ function (disabled) {
641
+ if (_this.form.disabled === disabled || typeof disabled !== 'boolean') {
642
+ return;
643
+ }
644
+ if (disabled) {
645
+ _this.form.disable();
646
+ }
647
+ else {
648
+ _this.form.enable();
649
+ }
650
+ _this._cd.markForCheck();
651
+ }));
652
+ (/** @type {?} */ (this._formGroupDirective.valueChanges)).pipe(this.debounceChange()).subscribe((/**
653
+ * @return {?}
654
+ */
655
+ function () {
656
+ _this.updateFormStateWithRawValue();
657
+ }));
658
+ (/** @type {?} */ (this._formGroupDirective
659
+ .statusChanges)).pipe(operators.distinctUntilChanged(), this.debounceChange())
660
+ .subscribe((/**
661
+ * @param {?} status
662
+ * @return {?}
663
+ */
664
+ function (status) {
665
+ _this._store.dispatch(new UpdateFormStatus({
666
+ status: status,
667
+ path: _this.path
668
+ }));
669
+ }));
670
+ };
671
+ /**
672
+ * @param {?=} withFormStatus
673
+ * @return {?}
674
+ */
675
+ FormDirective.prototype.updateFormStateWithRawValue = /**
676
+ * @param {?=} withFormStatus
677
+ * @return {?}
678
+ */
679
+ function (withFormStatus) {
680
+ var _this = this;
681
+ if (this._updating)
682
+ return;
683
+ /** @type {?} */
684
+ var value = this._formGroupDirective.control.getRawValue();
685
+ /** @type {?} */
686
+ var actions = [
687
+ new UpdateFormValue({
688
+ path: this.path,
689
+ value: value
690
+ }),
691
+ new UpdateFormDirty({
692
+ path: this.path,
693
+ dirty: this._formGroupDirective.dirty
694
+ }),
695
+ new UpdateFormErrors({
696
+ path: this.path,
697
+ errors: this._formGroupDirective.errors
698
+ })
699
+ ];
700
+ if (withFormStatus) {
701
+ actions.push(new UpdateFormStatus({
702
+ path: this.path,
703
+ status: this._formGroupDirective.status
704
+ }));
705
+ }
706
+ this._updating = true;
707
+ this._store.dispatch(actions).subscribe({
708
+ error: (/**
709
+ * @return {?}
710
+ */
711
+ function () { return (_this._updating = false); }),
712
+ complete: (/**
713
+ * @return {?}
714
+ */
715
+ function () { return (_this._updating = false); })
716
+ });
717
+ };
718
+ /**
719
+ * @return {?}
720
+ */
721
+ FormDirective.prototype.ngOnDestroy = /**
722
+ * @return {?}
723
+ */
724
+ function () {
725
+ this._destroy$.next();
726
+ this._destroy$.complete();
727
+ if (this.clearDestroy) {
728
+ this._store.dispatch(new UpdateForm({
729
+ path: this.path,
730
+ value: null,
731
+ dirty: null,
732
+ status: null,
733
+ errors: null
734
+ }));
735
+ }
736
+ };
737
+ /**
738
+ * @private
739
+ * @return {?}
740
+ */
741
+ FormDirective.prototype.debounceChange = /**
742
+ * @private
743
+ * @return {?}
744
+ */
745
+ function () {
746
+ var _this = this;
747
+ /** @type {?} */
748
+ var skipDebounceTime = this._formGroupDirective.control.updateOn !== 'change' || this.debounce < 0;
749
+ return skipDebounceTime
750
+ ? (/**
751
+ * @param {?} change
752
+ * @return {?}
753
+ */
754
+ function (change) { return change.pipe(operators.takeUntil(_this._destroy$)); })
755
+ : (/**
756
+ * @param {?} change
757
+ * @return {?}
758
+ */
759
+ function (change) {
760
+ return change.pipe(operators.debounceTime(_this.debounce), operators.takeUntil(_this._destroy$));
761
+ });
762
+ };
763
+ Object.defineProperty(FormDirective.prototype, "form", {
764
+ get: /**
765
+ * @private
766
+ * @return {?}
767
+ */
768
+ function () {
769
+ return this._formGroupDirective.form;
770
+ },
771
+ enumerable: true,
772
+ configurable: true
773
+ });
774
+ /**
775
+ * @private
776
+ * @param {?} path
777
+ * @return {?}
778
+ */
779
+ FormDirective.prototype.getStateStream = /**
780
+ * @private
781
+ * @param {?} path
782
+ * @return {?}
783
+ */
784
+ function (path) {
785
+ return this._store.select((/**
786
+ * @param {?} state
787
+ * @return {?}
788
+ */
789
+ function (state) { return store.getValue(state, path); })).pipe(operators.takeUntil(this._destroy$));
790
+ };
791
+ FormDirective.decorators = [
792
+ { type: core.Directive, args: [{ selector: '[ngxsForm]' },] }
793
+ ];
794
+ /** @nocollapse */
795
+ FormDirective.ctorParameters = function () { return [
796
+ { type: store.Actions },
797
+ { type: store.Store },
798
+ { type: forms.FormGroupDirective },
799
+ { type: core.ChangeDetectorRef }
800
+ ]; };
801
+ FormDirective.propDecorators = {
802
+ path: [{ type: core.Input, args: ['ngxsForm',] }],
803
+ debounce: [{ type: core.Input, args: ['ngxsFormDebounce',] }],
804
+ clearDestroy: [{ type: core.Input, args: ['ngxsFormClearOnDestroy',] }]
805
+ };
806
+ return FormDirective;
807
+ }());
808
+ if (false) {
809
+ /** @type {?} */
810
+ FormDirective.prototype.path;
811
+ /** @type {?} */
812
+ FormDirective.prototype.debounce;
813
+ /** @type {?} */
814
+ FormDirective.prototype._clearDestroy;
815
+ /**
816
+ * @type {?}
817
+ * @private
818
+ */
819
+ FormDirective.prototype._destroy$;
820
+ /**
821
+ * @type {?}
822
+ * @private
823
+ */
824
+ FormDirective.prototype._updating;
825
+ /**
826
+ * @type {?}
827
+ * @private
828
+ */
829
+ FormDirective.prototype._actions$;
830
+ /**
831
+ * @type {?}
832
+ * @private
833
+ */
834
+ FormDirective.prototype._store;
835
+ /**
836
+ * @type {?}
837
+ * @private
838
+ */
839
+ FormDirective.prototype._formGroupDirective;
840
+ /**
841
+ * @type {?}
842
+ * @private
843
+ */
844
+ FormDirective.prototype._cd;
845
845
  }
846
846
 
847
- /**
848
- * @fileoverview added by tsickle
849
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
850
- */
851
- var NgxsFormPluginModule = /** @class */ (function () {
852
- function NgxsFormPluginModule() {
853
- }
854
- /**
855
- * @return {?}
856
- */
857
- NgxsFormPluginModule.forRoot = /**
858
- * @return {?}
859
- */
860
- function () {
861
- return {
862
- ngModule: NgxsFormPluginModule,
863
- providers: [
864
- {
865
- provide: store.NGXS_PLUGINS,
866
- useClass: NgxsFormPlugin,
867
- multi: true
868
- }
869
- ]
870
- };
871
- };
872
- NgxsFormPluginModule.decorators = [
873
- { type: core.NgModule, args: [{
874
- imports: [forms.ReactiveFormsModule],
875
- declarations: [FormDirective],
876
- exports: [FormDirective]
877
- },] }
878
- ];
879
- return NgxsFormPluginModule;
847
+ /**
848
+ * @fileoverview added by tsickle
849
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
850
+ */
851
+ var NgxsFormPluginModule = /** @class */ (function () {
852
+ function NgxsFormPluginModule() {
853
+ }
854
+ /**
855
+ * @return {?}
856
+ */
857
+ NgxsFormPluginModule.forRoot = /**
858
+ * @return {?}
859
+ */
860
+ function () {
861
+ return {
862
+ ngModule: NgxsFormPluginModule,
863
+ providers: [
864
+ {
865
+ provide: store.NGXS_PLUGINS,
866
+ useClass: NgxsFormPlugin,
867
+ multi: true
868
+ }
869
+ ]
870
+ };
871
+ };
872
+ NgxsFormPluginModule.decorators = [
873
+ { type: core.NgModule, args: [{
874
+ imports: [forms.ReactiveFormsModule],
875
+ declarations: [FormDirective],
876
+ exports: [FormDirective]
877
+ },] }
878
+ ];
879
+ return NgxsFormPluginModule;
880
880
  }());
881
881
 
882
882
  exports.NgxsFormPlugin = NgxsFormPlugin;