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