@ngxs/form-plugin 3.7.3-dev.master-10b0883 → 3.7.4

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,670 @@
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;
524
- }());
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
+ }
525
535
 
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;
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;
845
855
  }
846
856
 
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;
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;
880
890
  }());
881
891
 
882
892
  exports.NgxsFormPlugin = NgxsFormPlugin;