@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.
@@ -4,616 +4,623 @@ import { FormGroupDirective, ReactiveFormsModule } from '@angular/forms';
4
4
  import { Subject } from 'rxjs';
5
5
  import { filter, takeUntil, distinctUntilChanged, debounceTime } from 'rxjs/operators';
6
6
 
7
- /**
8
- * @fileoverview added by tsickle
9
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
10
- */
11
- class UpdateFormStatus {
12
- /**
13
- * @param {?} payload
14
- */
15
- constructor(payload) {
16
- this.payload = payload;
17
- }
18
- /**
19
- * @return {?}
20
- */
21
- static get type() {
22
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
23
- return '[Forms] Update Form Status';
24
- }
25
- }
26
- if (false) {
27
- /** @type {?} */
28
- UpdateFormStatus.prototype.payload;
29
- }
30
- class UpdateFormValue {
31
- /**
32
- * @param {?} payload
33
- */
34
- constructor(payload) {
35
- this.payload = payload;
36
- }
37
- /**
38
- * @return {?}
39
- */
40
- static get type() {
41
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
42
- return '[Forms] Update Form Value';
43
- }
44
- }
45
- if (false) {
46
- /** @type {?} */
47
- UpdateFormValue.prototype.payload;
48
- }
49
- class UpdateForm {
50
- /**
51
- * @param {?} payload
52
- */
53
- constructor(payload) {
54
- this.payload = payload;
55
- }
56
- /**
57
- * @return {?}
58
- */
59
- static get type() {
60
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
61
- return '[Forms] Update Form';
62
- }
63
- }
64
- if (false) {
65
- /** @type {?} */
66
- UpdateForm.prototype.payload;
67
- }
68
- class UpdateFormDirty {
69
- /**
70
- * @param {?} payload
71
- */
72
- constructor(payload) {
73
- this.payload = payload;
74
- }
75
- /**
76
- * @return {?}
77
- */
78
- static get type() {
79
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
80
- return '[Forms] Update Form Dirty';
81
- }
82
- }
83
- if (false) {
84
- /** @type {?} */
85
- UpdateFormDirty.prototype.payload;
86
- }
87
- class SetFormDirty {
88
- /**
89
- * @param {?} payload
90
- */
91
- constructor(payload) {
92
- this.payload = payload;
93
- }
94
- /**
95
- * @return {?}
96
- */
97
- static get type() {
98
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
99
- return '[Forms] Set Form Dirty';
100
- }
101
- }
102
- if (false) {
103
- /** @type {?} */
104
- SetFormDirty.prototype.payload;
105
- }
106
- class SetFormPristine {
107
- /**
108
- * @param {?} payload
109
- */
110
- constructor(payload) {
111
- this.payload = payload;
112
- }
113
- /**
114
- * @return {?}
115
- */
116
- static get type() {
117
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
118
- return '[Forms] Set Form Pristine';
119
- }
120
- }
121
- if (false) {
122
- /** @type {?} */
123
- SetFormPristine.prototype.payload;
124
- }
125
- class UpdateFormErrors {
126
- /**
127
- * @param {?} payload
128
- */
129
- constructor(payload) {
130
- this.payload = payload;
131
- }
132
- /**
133
- * @return {?}
134
- */
135
- static get type() {
136
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
137
- return '[Forms] Update Form Errors';
138
- }
139
- }
140
- if (false) {
141
- /** @type {?} */
142
- UpdateFormErrors.prototype.payload;
143
- }
144
- class SetFormDisabled {
145
- /**
146
- * @param {?} payload
147
- */
148
- constructor(payload) {
149
- this.payload = payload;
150
- }
151
- /**
152
- * @return {?}
153
- */
154
- static get type() {
155
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
156
- return '[Forms] Set Form Disabled';
157
- }
158
- }
159
- if (false) {
160
- /** @type {?} */
161
- SetFormDisabled.prototype.payload;
162
- }
163
- class SetFormEnabled {
164
- /**
165
- * @param {?} payload
166
- */
167
- constructor(payload) {
168
- this.payload = payload;
169
- }
170
- /**
171
- * @return {?}
172
- */
173
- static get type() {
174
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
175
- return '[Forms] Set Form Enabled';
176
- }
177
- }
178
- if (false) {
179
- /** @type {?} */
180
- SetFormEnabled.prototype.payload;
181
- }
182
- class ResetForm {
183
- /**
184
- * @param {?} payload
185
- */
186
- constructor(payload) {
187
- this.payload = payload;
188
- }
189
- /**
190
- * @return {?}
191
- */
192
- static get type() {
193
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
194
- return '[Forms] Reset Form';
195
- }
196
- }
197
- if (false) {
198
- /** @type {?} */
199
- ResetForm.prototype.payload;
7
+ /**
8
+ * @fileoverview added by tsickle
9
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
10
+ */
11
+ class UpdateFormStatus {
12
+ /**
13
+ * @param {?} payload
14
+ */
15
+ constructor(payload) {
16
+ this.payload = payload;
17
+ }
18
+ /**
19
+ * @return {?}
20
+ */
21
+ static get type() {
22
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
23
+ return '[Forms] Update Form Status';
24
+ }
25
+ }
26
+ if (false) {
27
+ /** @type {?} */
28
+ UpdateFormStatus.prototype.payload;
29
+ }
30
+ class UpdateFormValue {
31
+ /**
32
+ * @param {?} payload
33
+ */
34
+ constructor(payload) {
35
+ this.payload = payload;
36
+ }
37
+ /**
38
+ * @return {?}
39
+ */
40
+ static get type() {
41
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
42
+ return '[Forms] Update Form Value';
43
+ }
44
+ }
45
+ if (false) {
46
+ /** @type {?} */
47
+ UpdateFormValue.prototype.payload;
48
+ }
49
+ class UpdateForm {
50
+ /**
51
+ * @param {?} payload
52
+ */
53
+ constructor(payload) {
54
+ this.payload = payload;
55
+ }
56
+ /**
57
+ * @return {?}
58
+ */
59
+ static get type() {
60
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
61
+ return '[Forms] Update Form';
62
+ }
63
+ }
64
+ if (false) {
65
+ /** @type {?} */
66
+ UpdateForm.prototype.payload;
67
+ }
68
+ class UpdateFormDirty {
69
+ /**
70
+ * @param {?} payload
71
+ */
72
+ constructor(payload) {
73
+ this.payload = payload;
74
+ }
75
+ /**
76
+ * @return {?}
77
+ */
78
+ static get type() {
79
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
80
+ return '[Forms] Update Form Dirty';
81
+ }
82
+ }
83
+ if (false) {
84
+ /** @type {?} */
85
+ UpdateFormDirty.prototype.payload;
86
+ }
87
+ class SetFormDirty {
88
+ /**
89
+ * @param {?} payload
90
+ */
91
+ constructor(payload) {
92
+ this.payload = payload;
93
+ }
94
+ /**
95
+ * @return {?}
96
+ */
97
+ static get type() {
98
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
99
+ return '[Forms] Set Form Dirty';
100
+ }
101
+ }
102
+ if (false) {
103
+ /** @type {?} */
104
+ SetFormDirty.prototype.payload;
105
+ }
106
+ class SetFormPristine {
107
+ /**
108
+ * @param {?} payload
109
+ */
110
+ constructor(payload) {
111
+ this.payload = payload;
112
+ }
113
+ /**
114
+ * @return {?}
115
+ */
116
+ static get type() {
117
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
118
+ return '[Forms] Set Form Pristine';
119
+ }
120
+ }
121
+ if (false) {
122
+ /** @type {?} */
123
+ SetFormPristine.prototype.payload;
124
+ }
125
+ class UpdateFormErrors {
126
+ /**
127
+ * @param {?} payload
128
+ */
129
+ constructor(payload) {
130
+ this.payload = payload;
131
+ }
132
+ /**
133
+ * @return {?}
134
+ */
135
+ static get type() {
136
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
137
+ return '[Forms] Update Form Errors';
138
+ }
139
+ }
140
+ if (false) {
141
+ /** @type {?} */
142
+ UpdateFormErrors.prototype.payload;
143
+ }
144
+ class SetFormDisabled {
145
+ /**
146
+ * @param {?} payload
147
+ */
148
+ constructor(payload) {
149
+ this.payload = payload;
150
+ }
151
+ /**
152
+ * @return {?}
153
+ */
154
+ static get type() {
155
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
156
+ return '[Forms] Set Form Disabled';
157
+ }
158
+ }
159
+ if (false) {
160
+ /** @type {?} */
161
+ SetFormDisabled.prototype.payload;
162
+ }
163
+ class SetFormEnabled {
164
+ /**
165
+ * @param {?} payload
166
+ */
167
+ constructor(payload) {
168
+ this.payload = payload;
169
+ }
170
+ /**
171
+ * @return {?}
172
+ */
173
+ static get type() {
174
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
175
+ return '[Forms] Set Form Enabled';
176
+ }
177
+ }
178
+ if (false) {
179
+ /** @type {?} */
180
+ SetFormEnabled.prototype.payload;
181
+ }
182
+ class ResetForm {
183
+ /**
184
+ * @param {?} payload
185
+ */
186
+ constructor(payload) {
187
+ this.payload = payload;
188
+ }
189
+ /**
190
+ * @return {?}
191
+ */
192
+ static get type() {
193
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
194
+ return '[Forms] Reset Form';
195
+ }
196
+ }
197
+ if (false) {
198
+ /** @type {?} */
199
+ ResetForm.prototype.payload;
200
200
  }
201
201
 
202
- /**
203
- * @fileoverview added by tsickle
204
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
205
- */
206
- class NgxsFormPlugin {
207
- /**
208
- * @param {?} state
209
- * @param {?} event
210
- * @param {?} next
211
- * @return {?}
212
- */
213
- handle(state, event, next) {
214
- /** @type {?} */
215
- const type = getActionTypeFromInstance(event);
216
- /** @type {?} */
217
- let nextState = state;
218
- if (type === UpdateFormValue.type || type === UpdateForm.type || type === ResetForm.type) {
219
- const { value } = event.payload;
220
- /** @type {?} */
221
- const payloadValue = Array.isArray(value)
222
- ? value.slice()
223
- : isObjectLike(value)
224
- ? Object.assign({}, value) : value;
225
- /** @type {?} */
226
- const path = this.joinPathWithPropertyPath(event);
227
- nextState = setValue(nextState, path, payloadValue);
228
- }
229
- if (type === ResetForm.type) {
230
- /** @type {?} */
231
- const model = getValue(nextState, `${event.payload.path}.model`);
232
- nextState = setValue(nextState, `${event.payload.path}`, { model: model });
233
- }
234
- if (type === UpdateFormStatus.type || type === UpdateForm.type) {
235
- nextState = setValue(nextState, `${event.payload.path}.status`, event.payload.status);
236
- }
237
- if (type === UpdateFormErrors.type || type === UpdateForm.type) {
238
- nextState = setValue(nextState, `${event.payload.path}.errors`, Object.assign({}, event.payload.errors));
239
- }
240
- if (type === UpdateFormDirty.type || type === UpdateForm.type) {
241
- nextState = setValue(nextState, `${event.payload.path}.dirty`, event.payload.dirty);
242
- }
243
- if (type === SetFormDirty.type) {
244
- nextState = setValue(nextState, `${event.payload}.dirty`, true);
245
- }
246
- if (type === SetFormPristine.type) {
247
- nextState = setValue(nextState, `${event.payload}.dirty`, false);
248
- }
249
- if (type === SetFormDisabled.type) {
250
- nextState = setValue(nextState, `${event.payload}.disabled`, true);
251
- }
252
- if (type === SetFormEnabled.type) {
253
- nextState = setValue(nextState, `${event.payload}.disabled`, false);
254
- }
255
- return next(nextState, event);
256
- }
257
- /**
258
- * @private
259
- * @param {?} __0
260
- * @return {?}
261
- */
262
- joinPathWithPropertyPath({ payload }) {
263
- /** @type {?} */
264
- let path = `${payload.path}.model`;
265
- if (payload.propertyPath) {
266
- path += `.${payload.propertyPath}`;
267
- }
268
- return path;
269
- }
270
- }
271
- NgxsFormPlugin.decorators = [
272
- { type: Injectable }
273
- ];
274
- /**
275
- * @param {?} target
276
- * @return {?}
277
- */
278
- function isObjectLike(target) {
279
- return target !== null && typeof target === 'object';
202
+ /**
203
+ * @fileoverview added by tsickle
204
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
205
+ */
206
+ class NgxsFormPlugin {
207
+ /**
208
+ * @param {?} state
209
+ * @param {?} event
210
+ * @param {?} next
211
+ * @return {?}
212
+ */
213
+ handle(state, event, next) {
214
+ /** @type {?} */
215
+ const type = getActionTypeFromInstance(event);
216
+ /** @type {?} */
217
+ let nextState = state;
218
+ if (type === UpdateFormValue.type || type === UpdateForm.type || type === ResetForm.type) {
219
+ const { value } = event.payload;
220
+ /** @type {?} */
221
+ const payloadValue = Array.isArray(value)
222
+ ? value.slice()
223
+ : isObjectLike(value)
224
+ ? Object.assign({}, value) : value;
225
+ /** @type {?} */
226
+ const path = this.joinPathWithPropertyPath(event);
227
+ nextState = setValue(nextState, path, payloadValue);
228
+ }
229
+ if (type === ResetForm.type) {
230
+ /** @type {?} */
231
+ const model = getValue(nextState, `${event.payload.path}.model`);
232
+ nextState = setValue(nextState, `${event.payload.path}`, { model: model });
233
+ }
234
+ if (type === UpdateFormStatus.type || type === UpdateForm.type) {
235
+ nextState = setValue(nextState, `${event.payload.path}.status`, event.payload.status);
236
+ }
237
+ if (type === UpdateFormErrors.type || type === UpdateForm.type) {
238
+ nextState = setValue(nextState, `${event.payload.path}.errors`, Object.assign({}, event.payload.errors));
239
+ }
240
+ if (type === UpdateFormDirty.type || type === UpdateForm.type) {
241
+ nextState = setValue(nextState, `${event.payload.path}.dirty`, event.payload.dirty);
242
+ }
243
+ if (type === SetFormDirty.type) {
244
+ nextState = setValue(nextState, `${event.payload}.dirty`, true);
245
+ }
246
+ if (type === SetFormPristine.type) {
247
+ nextState = setValue(nextState, `${event.payload}.dirty`, false);
248
+ }
249
+ if (type === SetFormDisabled.type) {
250
+ nextState = setValue(nextState, `${event.payload}.disabled`, true);
251
+ }
252
+ if (type === SetFormEnabled.type) {
253
+ nextState = setValue(nextState, `${event.payload}.disabled`, false);
254
+ }
255
+ return next(nextState, event);
256
+ }
257
+ /**
258
+ * @private
259
+ * @param {?} __0
260
+ * @return {?}
261
+ */
262
+ joinPathWithPropertyPath({ payload }) {
263
+ /** @type {?} */
264
+ let path = `${payload.path}.model`;
265
+ if (payload.propertyPath) {
266
+ path += `.${payload.propertyPath}`;
267
+ }
268
+ return path;
269
+ }
270
+ }
271
+ NgxsFormPlugin.decorators = [
272
+ { type: Injectable }
273
+ ];
274
+ /**
275
+ * @param {?} target
276
+ * @return {?}
277
+ */
278
+ function isObjectLike(target) {
279
+ return target !== null && typeof target === 'object';
280
280
  }
281
281
 
282
- /**
283
- * @fileoverview added by tsickle
284
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
285
- */
286
- class FormDirective {
287
- /**
288
- * @param {?} _actions$
289
- * @param {?} _store
290
- * @param {?} _formGroupDirective
291
- * @param {?} _cd
292
- */
293
- constructor(_actions$, _store, _formGroupDirective, _cd) {
294
- this._actions$ = _actions$;
295
- this._store = _store;
296
- this._formGroupDirective = _formGroupDirective;
297
- this._cd = _cd;
298
- this.path = (/** @type {?} */ (null));
299
- this.debounce = 100;
300
- this._clearDestroy = false;
301
- this._destroy$ = new Subject();
302
- this._updating = false;
303
- }
304
- /**
305
- * @param {?} val
306
- * @return {?}
307
- */
308
- set clearDestroy(val) {
309
- this._clearDestroy = val != null && `${val}` !== 'false';
310
- }
311
- /**
312
- * @return {?}
313
- */
314
- get clearDestroy() {
315
- return this._clearDestroy;
316
- }
317
- /**
318
- * @return {?}
319
- */
320
- ngOnInit() {
321
- this._actions$
322
- .pipe(ofActionDispatched(ResetForm), filter((/**
323
- * @param {?} action
324
- * @return {?}
325
- */
326
- (action) => action.payload.path === this.path)), takeUntil(this._destroy$))
327
- .subscribe((/**
328
- * @param {?} __0
329
- * @return {?}
330
- */
331
- ({ payload: { value } }) => {
332
- this.form.reset(value);
333
- this.updateFormStateWithRawValue(true);
334
- this._cd.markForCheck();
335
- }));
336
- this.getStateStream(`${this.path}.model`).subscribe((/**
337
- * @param {?} model
338
- * @return {?}
339
- */
340
- model => {
341
- if (this._updating || !model) {
342
- return;
343
- }
344
- this.form.patchValue(model);
345
- this._cd.markForCheck();
346
- }));
347
- this.getStateStream(`${this.path}.dirty`).subscribe((/**
348
- * @param {?} dirty
349
- * @return {?}
350
- */
351
- dirty => {
352
- if (this.form.dirty === dirty || typeof dirty !== 'boolean') {
353
- return;
354
- }
355
- if (dirty) {
356
- this.form.markAsDirty();
357
- }
358
- else {
359
- this.form.markAsPristine();
360
- }
361
- this._cd.markForCheck();
362
- }));
363
- // On first state change, sync form model, status and dirty with state
364
- this._store
365
- .selectOnce((/**
366
- * @param {?} state
367
- * @return {?}
368
- */
369
- state => getValue(state, this.path)))
370
- .subscribe((/**
371
- * @return {?}
372
- */
373
- () => {
374
- this._store.dispatch([
375
- new UpdateFormValue({
376
- path: this.path,
377
- value: this.form.getRawValue()
378
- }),
379
- new UpdateFormStatus({
380
- path: this.path,
381
- status: this.form.status
382
- }),
383
- new UpdateFormDirty({
384
- path: this.path,
385
- dirty: this.form.dirty
386
- })
387
- ]);
388
- }));
389
- this.getStateStream(`${this.path}.disabled`).subscribe((/**
390
- * @param {?} disabled
391
- * @return {?}
392
- */
393
- disabled => {
394
- if (this.form.disabled === disabled || typeof disabled !== 'boolean') {
395
- return;
396
- }
397
- if (disabled) {
398
- this.form.disable();
399
- }
400
- else {
401
- this.form.enable();
402
- }
403
- this._cd.markForCheck();
404
- }));
405
- (/** @type {?} */ (this._formGroupDirective.valueChanges)).pipe(this.debounceChange()).subscribe((/**
406
- * @return {?}
407
- */
408
- () => {
409
- this.updateFormStateWithRawValue();
410
- }));
411
- (/** @type {?} */ (this._formGroupDirective
412
- .statusChanges)).pipe(distinctUntilChanged(), this.debounceChange())
413
- .subscribe((/**
414
- * @param {?} status
415
- * @return {?}
416
- */
417
- (status) => {
418
- this._store.dispatch(new UpdateFormStatus({
419
- status,
420
- path: this.path
421
- }));
422
- }));
423
- }
424
- /**
425
- * @param {?=} withFormStatus
426
- * @return {?}
427
- */
428
- updateFormStateWithRawValue(withFormStatus) {
429
- if (this._updating)
430
- return;
431
- /** @type {?} */
432
- const value = this._formGroupDirective.control.getRawValue();
433
- /** @type {?} */
434
- const actions = [
435
- new UpdateFormValue({
436
- path: this.path,
437
- value
438
- }),
439
- new UpdateFormDirty({
440
- path: this.path,
441
- dirty: this._formGroupDirective.dirty
442
- }),
443
- new UpdateFormErrors({
444
- path: this.path,
445
- errors: this._formGroupDirective.errors
446
- })
447
- ];
448
- if (withFormStatus) {
449
- actions.push(new UpdateFormStatus({
450
- path: this.path,
451
- status: this._formGroupDirective.status
452
- }));
453
- }
454
- this._updating = true;
455
- this._store.dispatch(actions).subscribe({
456
- error: (/**
457
- * @return {?}
458
- */
459
- () => (this._updating = false)),
460
- complete: (/**
461
- * @return {?}
462
- */
463
- () => (this._updating = false))
464
- });
465
- }
466
- /**
467
- * @return {?}
468
- */
469
- ngOnDestroy() {
470
- this._destroy$.next();
471
- this._destroy$.complete();
472
- if (this.clearDestroy) {
473
- this._store.dispatch(new UpdateForm({
474
- path: this.path,
475
- value: null,
476
- dirty: null,
477
- status: null,
478
- errors: null
479
- }));
480
- }
481
- }
482
- /**
483
- * @private
484
- * @return {?}
485
- */
486
- debounceChange() {
487
- /** @type {?} */
488
- const skipDebounceTime = this._formGroupDirective.control.updateOn !== 'change' || this.debounce < 0;
489
- return skipDebounceTime
490
- ? (/**
491
- * @param {?} change
492
- * @return {?}
493
- */
494
- (change) => change.pipe(takeUntil(this._destroy$)))
495
- : (/**
496
- * @param {?} change
497
- * @return {?}
498
- */
499
- (change) => change.pipe(debounceTime(this.debounce), takeUntil(this._destroy$)));
500
- }
501
- /**
502
- * @private
503
- * @return {?}
504
- */
505
- get form() {
506
- return this._formGroupDirective.form;
507
- }
508
- /**
509
- * @private
510
- * @param {?} path
511
- * @return {?}
512
- */
513
- getStateStream(path) {
514
- return this._store.select((/**
515
- * @param {?} state
516
- * @return {?}
517
- */
518
- state => getValue(state, path))).pipe(takeUntil(this._destroy$));
519
- }
520
- }
521
- FormDirective.decorators = [
522
- { type: Directive, args: [{ selector: '[ngxsForm]' },] }
523
- ];
524
- /** @nocollapse */
525
- FormDirective.ctorParameters = () => [
526
- { type: Actions },
527
- { type: Store },
528
- { type: FormGroupDirective },
529
- { type: ChangeDetectorRef }
530
- ];
531
- FormDirective.propDecorators = {
532
- path: [{ type: Input, args: ['ngxsForm',] }],
533
- debounce: [{ type: Input, args: ['ngxsFormDebounce',] }],
534
- clearDestroy: [{ type: Input, args: ['ngxsFormClearOnDestroy',] }]
535
- };
536
- if (false) {
537
- /** @type {?} */
538
- FormDirective.prototype.path;
539
- /** @type {?} */
540
- FormDirective.prototype.debounce;
541
- /** @type {?} */
542
- FormDirective.prototype._clearDestroy;
543
- /**
544
- * @type {?}
545
- * @private
546
- */
547
- FormDirective.prototype._destroy$;
548
- /**
549
- * @type {?}
550
- * @private
551
- */
552
- FormDirective.prototype._updating;
553
- /**
554
- * @type {?}
555
- * @private
556
- */
557
- FormDirective.prototype._actions$;
558
- /**
559
- * @type {?}
560
- * @private
561
- */
562
- FormDirective.prototype._store;
563
- /**
564
- * @type {?}
565
- * @private
566
- */
567
- FormDirective.prototype._formGroupDirective;
568
- /**
569
- * @type {?}
570
- * @private
571
- */
572
- FormDirective.prototype._cd;
282
+ /**
283
+ * @fileoverview added by tsickle
284
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
285
+ */
286
+ class FormDirective {
287
+ /**
288
+ * @param {?} _actions$
289
+ * @param {?} _store
290
+ * @param {?} _formGroupDirective
291
+ * @param {?} _cd
292
+ */
293
+ constructor(_actions$, _store, _formGroupDirective, _cd) {
294
+ this._actions$ = _actions$;
295
+ this._store = _store;
296
+ this._formGroupDirective = _formGroupDirective;
297
+ this._cd = _cd;
298
+ this.path = (/** @type {?} */ (null));
299
+ this.debounce = 100;
300
+ this._clearDestroy = false;
301
+ this._destroy$ = new Subject();
302
+ this._updating = false;
303
+ }
304
+ /**
305
+ * @param {?} val
306
+ * @return {?}
307
+ */
308
+ set clearDestroy(val) {
309
+ this._clearDestroy = val != null && `${val}` !== 'false';
310
+ }
311
+ /**
312
+ * @return {?}
313
+ */
314
+ get clearDestroy() {
315
+ return this._clearDestroy;
316
+ }
317
+ /**
318
+ * @return {?}
319
+ */
320
+ ngOnInit() {
321
+ this._actions$
322
+ .pipe(ofActionDispatched(ResetForm), filter((/**
323
+ * @param {?} action
324
+ * @return {?}
325
+ */
326
+ (action) => action.payload.path === this.path)), takeUntil(this._destroy$))
327
+ .subscribe((/**
328
+ * @param {?} __0
329
+ * @return {?}
330
+ */
331
+ ({ payload: { value } }) => {
332
+ this.form.reset(value);
333
+ this.updateFormStateWithRawValue(true);
334
+ this._cd.markForCheck();
335
+ }));
336
+ this.getStateStream(`${this.path}.model`).subscribe((/**
337
+ * @param {?} model
338
+ * @return {?}
339
+ */
340
+ model => {
341
+ if (this._updating || !model) {
342
+ return;
343
+ }
344
+ this.form.patchValue(model);
345
+ this._cd.markForCheck();
346
+ }));
347
+ this.getStateStream(`${this.path}.dirty`).subscribe((/**
348
+ * @param {?} dirty
349
+ * @return {?}
350
+ */
351
+ dirty => {
352
+ if (this.form.dirty === dirty || typeof dirty !== 'boolean') {
353
+ return;
354
+ }
355
+ if (dirty) {
356
+ this.form.markAsDirty();
357
+ }
358
+ else {
359
+ this.form.markAsPristine();
360
+ }
361
+ this._cd.markForCheck();
362
+ }));
363
+ // On first state change, sync form model, status and dirty with state
364
+ this._store
365
+ .selectOnce((/**
366
+ * @param {?} state
367
+ * @return {?}
368
+ */
369
+ state => getValue(state, this.path)))
370
+ .subscribe((/**
371
+ * @return {?}
372
+ */
373
+ () => {
374
+ this._store.dispatch([
375
+ new UpdateFormValue({
376
+ path: this.path,
377
+ value: this.form.getRawValue()
378
+ }),
379
+ new UpdateFormStatus({
380
+ path: this.path,
381
+ status: this.form.status
382
+ }),
383
+ new UpdateFormDirty({
384
+ path: this.path,
385
+ dirty: this.form.dirty
386
+ })
387
+ ]);
388
+ }));
389
+ this.getStateStream(`${this.path}.disabled`).subscribe((/**
390
+ * @param {?} disabled
391
+ * @return {?}
392
+ */
393
+ disabled => {
394
+ if (this.form.disabled === disabled || typeof disabled !== 'boolean') {
395
+ return;
396
+ }
397
+ if (disabled) {
398
+ this.form.disable();
399
+ }
400
+ else {
401
+ this.form.enable();
402
+ }
403
+ this._cd.markForCheck();
404
+ }));
405
+ (/** @type {?} */ (this._formGroupDirective
406
+ .valueChanges)).pipe(distinctUntilChanged((/**
407
+ * @param {?} a
408
+ * @param {?} b
409
+ * @return {?}
410
+ */
411
+ (a, b) => JSON.stringify(a) === JSON.stringify(b))), this.debounceChange())
412
+ .subscribe((/**
413
+ * @return {?}
414
+ */
415
+ () => {
416
+ this.updateFormStateWithRawValue();
417
+ }));
418
+ (/** @type {?} */ (this._formGroupDirective
419
+ .statusChanges)).pipe(distinctUntilChanged(), this.debounceChange())
420
+ .subscribe((/**
421
+ * @param {?} status
422
+ * @return {?}
423
+ */
424
+ (status) => {
425
+ this._store.dispatch(new UpdateFormStatus({
426
+ status,
427
+ path: this.path
428
+ }));
429
+ }));
430
+ }
431
+ /**
432
+ * @param {?=} withFormStatus
433
+ * @return {?}
434
+ */
435
+ updateFormStateWithRawValue(withFormStatus) {
436
+ if (this._updating)
437
+ return;
438
+ /** @type {?} */
439
+ const value = this._formGroupDirective.control.getRawValue();
440
+ /** @type {?} */
441
+ const actions = [
442
+ new UpdateFormValue({
443
+ path: this.path,
444
+ value
445
+ }),
446
+ new UpdateFormDirty({
447
+ path: this.path,
448
+ dirty: this._formGroupDirective.dirty
449
+ }),
450
+ new UpdateFormErrors({
451
+ path: this.path,
452
+ errors: this._formGroupDirective.errors
453
+ })
454
+ ];
455
+ if (withFormStatus) {
456
+ actions.push(new UpdateFormStatus({
457
+ path: this.path,
458
+ status: this._formGroupDirective.status
459
+ }));
460
+ }
461
+ this._updating = true;
462
+ this._store.dispatch(actions).subscribe({
463
+ error: (/**
464
+ * @return {?}
465
+ */
466
+ () => (this._updating = false)),
467
+ complete: (/**
468
+ * @return {?}
469
+ */
470
+ () => (this._updating = false))
471
+ });
472
+ }
473
+ /**
474
+ * @return {?}
475
+ */
476
+ ngOnDestroy() {
477
+ this._destroy$.next();
478
+ this._destroy$.complete();
479
+ if (this.clearDestroy) {
480
+ this._store.dispatch(new UpdateForm({
481
+ path: this.path,
482
+ value: null,
483
+ dirty: null,
484
+ status: null,
485
+ errors: null
486
+ }));
487
+ }
488
+ }
489
+ /**
490
+ * @private
491
+ * @return {?}
492
+ */
493
+ debounceChange() {
494
+ /** @type {?} */
495
+ const skipDebounceTime = this._formGroupDirective.control.updateOn !== 'change' || this.debounce < 0;
496
+ return skipDebounceTime
497
+ ? (/**
498
+ * @param {?} change
499
+ * @return {?}
500
+ */
501
+ (change) => change.pipe(takeUntil(this._destroy$)))
502
+ : (/**
503
+ * @param {?} change
504
+ * @return {?}
505
+ */
506
+ (change) => change.pipe(debounceTime(this.debounce), takeUntil(this._destroy$)));
507
+ }
508
+ /**
509
+ * @private
510
+ * @return {?}
511
+ */
512
+ get form() {
513
+ return this._formGroupDirective.form;
514
+ }
515
+ /**
516
+ * @private
517
+ * @param {?} path
518
+ * @return {?}
519
+ */
520
+ getStateStream(path) {
521
+ return this._store.select((/**
522
+ * @param {?} state
523
+ * @return {?}
524
+ */
525
+ state => getValue(state, path))).pipe(takeUntil(this._destroy$));
526
+ }
527
+ }
528
+ FormDirective.decorators = [
529
+ { type: Directive, args: [{ selector: '[ngxsForm]' },] }
530
+ ];
531
+ /** @nocollapse */
532
+ FormDirective.ctorParameters = () => [
533
+ { type: Actions },
534
+ { type: Store },
535
+ { type: FormGroupDirective },
536
+ { type: ChangeDetectorRef }
537
+ ];
538
+ FormDirective.propDecorators = {
539
+ path: [{ type: Input, args: ['ngxsForm',] }],
540
+ debounce: [{ type: Input, args: ['ngxsFormDebounce',] }],
541
+ clearDestroy: [{ type: Input, args: ['ngxsFormClearOnDestroy',] }]
542
+ };
543
+ if (false) {
544
+ /** @type {?} */
545
+ FormDirective.prototype.path;
546
+ /** @type {?} */
547
+ FormDirective.prototype.debounce;
548
+ /** @type {?} */
549
+ FormDirective.prototype._clearDestroy;
550
+ /**
551
+ * @type {?}
552
+ * @private
553
+ */
554
+ FormDirective.prototype._destroy$;
555
+ /**
556
+ * @type {?}
557
+ * @private
558
+ */
559
+ FormDirective.prototype._updating;
560
+ /**
561
+ * @type {?}
562
+ * @private
563
+ */
564
+ FormDirective.prototype._actions$;
565
+ /**
566
+ * @type {?}
567
+ * @private
568
+ */
569
+ FormDirective.prototype._store;
570
+ /**
571
+ * @type {?}
572
+ * @private
573
+ */
574
+ FormDirective.prototype._formGroupDirective;
575
+ /**
576
+ * @type {?}
577
+ * @private
578
+ */
579
+ FormDirective.prototype._cd;
573
580
  }
574
581
 
575
- /**
576
- * @fileoverview added by tsickle
577
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
578
- */
579
- class NgxsFormPluginModule {
580
- /**
581
- * @return {?}
582
- */
583
- static forRoot() {
584
- return {
585
- ngModule: NgxsFormPluginModule,
586
- providers: [
587
- {
588
- provide: NGXS_PLUGINS,
589
- useClass: NgxsFormPlugin,
590
- multi: true
591
- }
592
- ]
593
- };
594
- }
595
- }
596
- NgxsFormPluginModule.decorators = [
597
- { type: NgModule, args: [{
598
- imports: [ReactiveFormsModule],
599
- declarations: [FormDirective],
600
- exports: [FormDirective]
601
- },] }
582
+ /**
583
+ * @fileoverview added by tsickle
584
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
585
+ */
586
+ class NgxsFormPluginModule {
587
+ /**
588
+ * @return {?}
589
+ */
590
+ static forRoot() {
591
+ return {
592
+ ngModule: NgxsFormPluginModule,
593
+ providers: [
594
+ {
595
+ provide: NGXS_PLUGINS,
596
+ useClass: NgxsFormPlugin,
597
+ multi: true
598
+ }
599
+ ]
600
+ };
601
+ }
602
+ }
603
+ NgxsFormPluginModule.decorators = [
604
+ { type: NgModule, args: [{
605
+ imports: [ReactiveFormsModule],
606
+ declarations: [FormDirective],
607
+ exports: [FormDirective]
608
+ },] }
602
609
  ];
603
610
 
604
- /**
605
- * @fileoverview added by tsickle
606
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
611
+ /**
612
+ * @fileoverview added by tsickle
613
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
607
614
  */
608
615
 
609
- /**
610
- * @fileoverview added by tsickle
611
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
616
+ /**
617
+ * @fileoverview added by tsickle
618
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
612
619
  */
613
620
 
614
- /**
615
- * @fileoverview added by tsickle
616
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
621
+ /**
622
+ * @fileoverview added by tsickle
623
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
617
624
  */
618
625
 
619
626
  export { NgxsFormPlugin, NgxsFormPluginModule, ResetForm, SetFormDirty, SetFormDisabled, SetFormEnabled, SetFormPristine, UpdateForm, UpdateFormDirty, UpdateFormErrors, UpdateFormStatus, UpdateFormValue, FormDirective as ɵa };