@ngxs/form-plugin 3.7.3 → 3.7.4-dev.master-43177a9

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,685 @@ 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)
251
+ ? value.slice()
252
+ : isObjectLike(value)
253
+ ? __assign({}, value) : value;
254
+ /** @type {?} */
255
+ var path = this.joinPathWithPropertyPath(event);
256
+ nextState = setValue(nextState, path, payloadValue);
257
+ }
258
+ if (type === ResetForm.type) {
259
+ /** @type {?} */
260
+ var model = getValue(nextState, event.payload.path + ".model");
261
+ nextState = setValue(nextState, "" + event.payload.path, { model: model });
262
+ }
263
+ if (type === UpdateFormStatus.type || type === UpdateForm.type) {
264
+ nextState = setValue(nextState, event.payload.path + ".status", event.payload.status);
265
+ }
266
+ if (type === UpdateFormErrors.type || type === UpdateForm.type) {
267
+ nextState = setValue(nextState, event.payload.path + ".errors", __assign({}, event.payload.errors));
268
+ }
269
+ if (type === UpdateFormDirty.type || type === UpdateForm.type) {
270
+ nextState = setValue(nextState, event.payload.path + ".dirty", event.payload.dirty);
271
+ }
272
+ if (type === SetFormDirty.type) {
273
+ nextState = setValue(nextState, event.payload + ".dirty", true);
274
+ }
275
+ if (type === SetFormPristine.type) {
276
+ nextState = setValue(nextState, event.payload + ".dirty", false);
277
+ }
278
+ if (type === SetFormDisabled.type) {
279
+ nextState = setValue(nextState, event.payload + ".disabled", true);
280
+ }
281
+ if (type === SetFormEnabled.type) {
282
+ nextState = setValue(nextState, event.payload + ".disabled", false);
283
+ }
284
+ return next(nextState, event);
285
+ };
286
+ /**
287
+ * @private
288
+ * @param {?} __0
289
+ * @return {?}
290
+ */
291
+ NgxsFormPlugin.prototype.joinPathWithPropertyPath = /**
292
+ * @private
293
+ * @param {?} __0
294
+ * @return {?}
295
+ */
296
+ function (_a) {
297
+ var payload = _a.payload;
298
+ /** @type {?} */
299
+ var path = payload.path + ".model";
300
+ if (payload.propertyPath) {
301
+ path += "." + payload.propertyPath;
302
+ }
303
+ return path;
304
+ };
305
+ NgxsFormPlugin.decorators = [
306
+ { type: Injectable }
307
+ ];
308
+ return NgxsFormPlugin;
306
309
  }());
310
+ /**
311
+ * @param {?} target
312
+ * @return {?}
313
+ */
314
+ function isObjectLike(target) {
315
+ return target !== null && typeof target === 'object';
316
+ }
307
317
 
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;
318
+ /**
319
+ * @fileoverview added by tsickle
320
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
321
+ */
322
+ var FormDirective = /** @class */ (function () {
323
+ function FormDirective(_actions$, _store, _formGroupDirective, _cd) {
324
+ this._actions$ = _actions$;
325
+ this._store = _store;
326
+ this._formGroupDirective = _formGroupDirective;
327
+ this._cd = _cd;
328
+ this.path = (/** @type {?} */ (null));
329
+ this.debounce = 100;
330
+ this._clearDestroy = false;
331
+ this._destroy$ = new Subject();
332
+ this._updating = false;
333
+ }
334
+ Object.defineProperty(FormDirective.prototype, "clearDestroy", {
335
+ get: /**
336
+ * @return {?}
337
+ */
338
+ function () {
339
+ return this._clearDestroy;
340
+ },
341
+ set: /**
342
+ * @param {?} val
343
+ * @return {?}
344
+ */
345
+ function (val) {
346
+ this._clearDestroy = val != null && "" + val !== 'false';
347
+ },
348
+ enumerable: true,
349
+ configurable: true
350
+ });
351
+ /**
352
+ * @return {?}
353
+ */
354
+ FormDirective.prototype.ngOnInit = /**
355
+ * @return {?}
356
+ */
357
+ function () {
358
+ var _this = this;
359
+ this._actions$
360
+ .pipe(ofActionDispatched(ResetForm), filter((/**
361
+ * @param {?} action
362
+ * @return {?}
363
+ */
364
+ function (action) { return action.payload.path === _this.path; })), takeUntil(this._destroy$))
365
+ .subscribe((/**
366
+ * @param {?} __0
367
+ * @return {?}
368
+ */
369
+ function (_a) {
370
+ var value = _a.payload.value;
371
+ _this.form.reset(value);
372
+ _this.updateFormStateWithRawValue(true);
373
+ _this._cd.markForCheck();
374
+ }));
375
+ this.getStateStream(this.path + ".model").subscribe((/**
376
+ * @param {?} model
377
+ * @return {?}
378
+ */
379
+ function (model) {
380
+ if (_this._updating || !model) {
381
+ return;
382
+ }
383
+ _this.form.patchValue(model);
384
+ _this._cd.markForCheck();
385
+ }));
386
+ this.getStateStream(this.path + ".dirty").subscribe((/**
387
+ * @param {?} dirty
388
+ * @return {?}
389
+ */
390
+ function (dirty) {
391
+ if (_this.form.dirty === dirty || typeof dirty !== 'boolean') {
392
+ return;
393
+ }
394
+ if (dirty) {
395
+ _this.form.markAsDirty();
396
+ }
397
+ else {
398
+ _this.form.markAsPristine();
399
+ }
400
+ _this._cd.markForCheck();
401
+ }));
402
+ // On first state change, sync form model, status and dirty with state
403
+ this._store
404
+ .selectOnce((/**
405
+ * @param {?} state
406
+ * @return {?}
407
+ */
408
+ function (state) { return getValue(state, _this.path); }))
409
+ .subscribe((/**
410
+ * @return {?}
411
+ */
412
+ function () {
413
+ _this._store.dispatch([
414
+ new UpdateFormValue({
415
+ path: _this.path,
416
+ value: _this.form.getRawValue()
417
+ }),
418
+ new UpdateFormStatus({
419
+ path: _this.path,
420
+ status: _this.form.status
421
+ }),
422
+ new UpdateFormDirty({
423
+ path: _this.path,
424
+ dirty: _this.form.dirty
425
+ })
426
+ ]);
427
+ }));
428
+ this.getStateStream(this.path + ".disabled").subscribe((/**
429
+ * @param {?} disabled
430
+ * @return {?}
431
+ */
432
+ function (disabled) {
433
+ if (_this.form.disabled === disabled || typeof disabled !== 'boolean') {
434
+ return;
435
+ }
436
+ if (disabled) {
437
+ _this.form.disable();
438
+ }
439
+ else {
440
+ _this.form.enable();
441
+ }
442
+ _this._cd.markForCheck();
443
+ }));
444
+ (/** @type {?} */ (this._formGroupDirective.valueChanges)).pipe(this.debounceChange()).subscribe((/**
445
+ * @return {?}
446
+ */
447
+ function () {
448
+ _this.updateFormStateWithRawValue();
449
+ }));
450
+ (/** @type {?} */ (this._formGroupDirective
451
+ .statusChanges)).pipe(distinctUntilChanged(), this.debounceChange())
452
+ .subscribe((/**
453
+ * @param {?} status
454
+ * @return {?}
455
+ */
456
+ function (status) {
457
+ _this._store.dispatch(new UpdateFormStatus({
458
+ status: status,
459
+ path: _this.path
460
+ }));
461
+ }));
462
+ };
463
+ /**
464
+ * @param {?=} withFormStatus
465
+ * @return {?}
466
+ */
467
+ FormDirective.prototype.updateFormStateWithRawValue = /**
468
+ * @param {?=} withFormStatus
469
+ * @return {?}
470
+ */
471
+ function (withFormStatus) {
472
+ var _this = this;
473
+ if (this._updating)
474
+ return;
475
+ /** @type {?} */
476
+ var value = this._formGroupDirective.control.getRawValue();
477
+ /** @type {?} */
478
+ var actions = [
479
+ new UpdateFormValue({
480
+ path: this.path,
481
+ value: value
482
+ }),
483
+ new UpdateFormDirty({
484
+ path: this.path,
485
+ dirty: this._formGroupDirective.dirty
486
+ }),
487
+ new UpdateFormErrors({
488
+ path: this.path,
489
+ errors: this._formGroupDirective.errors
490
+ })
491
+ ];
492
+ if (withFormStatus) {
493
+ actions.push(new UpdateFormStatus({
494
+ path: this.path,
495
+ status: this._formGroupDirective.status
496
+ }));
497
+ }
498
+ this._updating = true;
499
+ this._store.dispatch(actions).subscribe({
500
+ error: (/**
501
+ * @return {?}
502
+ */
503
+ function () { return (_this._updating = false); }),
504
+ complete: (/**
505
+ * @return {?}
506
+ */
507
+ function () { return (_this._updating = false); })
508
+ });
509
+ };
510
+ /**
511
+ * @return {?}
512
+ */
513
+ FormDirective.prototype.ngOnDestroy = /**
514
+ * @return {?}
515
+ */
516
+ function () {
517
+ this._destroy$.next();
518
+ this._destroy$.complete();
519
+ if (this.clearDestroy) {
520
+ this._store.dispatch(new UpdateForm({
521
+ path: this.path,
522
+ value: null,
523
+ dirty: null,
524
+ status: null,
525
+ errors: null
526
+ }));
527
+ }
528
+ };
529
+ /**
530
+ * @private
531
+ * @return {?}
532
+ */
533
+ FormDirective.prototype.debounceChange = /**
534
+ * @private
535
+ * @return {?}
536
+ */
537
+ function () {
538
+ var _this = this;
539
+ /** @type {?} */
540
+ var skipDebounceTime = this._formGroupDirective.control.updateOn !== 'change' || this.debounce < 0;
541
+ return skipDebounceTime
542
+ ? (/**
543
+ * @param {?} change
544
+ * @return {?}
545
+ */
546
+ function (change) { return change.pipe(takeUntil(_this._destroy$)); })
547
+ : (/**
548
+ * @param {?} change
549
+ * @return {?}
550
+ */
551
+ function (change) {
552
+ return change.pipe(debounceTime(_this.debounce), takeUntil(_this._destroy$));
553
+ });
554
+ };
555
+ Object.defineProperty(FormDirective.prototype, "form", {
556
+ get: /**
557
+ * @private
558
+ * @return {?}
559
+ */
560
+ function () {
561
+ return this._formGroupDirective.form;
562
+ },
563
+ enumerable: true,
564
+ configurable: true
565
+ });
566
+ /**
567
+ * @private
568
+ * @param {?} path
569
+ * @return {?}
570
+ */
571
+ FormDirective.prototype.getStateStream = /**
572
+ * @private
573
+ * @param {?} path
574
+ * @return {?}
575
+ */
576
+ function (path) {
577
+ return this._store.select((/**
578
+ * @param {?} state
579
+ * @return {?}
580
+ */
581
+ function (state) { return getValue(state, path); })).pipe(takeUntil(this._destroy$));
582
+ };
583
+ FormDirective.decorators = [
584
+ { type: Directive, args: [{ selector: '[ngxsForm]' },] }
585
+ ];
586
+ /** @nocollapse */
587
+ FormDirective.ctorParameters = function () { return [
588
+ { type: Actions },
589
+ { type: Store },
590
+ { type: FormGroupDirective },
591
+ { type: ChangeDetectorRef }
592
+ ]; };
593
+ FormDirective.propDecorators = {
594
+ path: [{ type: Input, args: ['ngxsForm',] }],
595
+ debounce: [{ type: Input, args: ['ngxsFormDebounce',] }],
596
+ clearDestroy: [{ type: Input, args: ['ngxsFormClearOnDestroy',] }]
597
+ };
598
+ return FormDirective;
599
+ }());
600
+ if (false) {
601
+ /** @type {?} */
602
+ FormDirective.prototype.path;
603
+ /** @type {?} */
604
+ FormDirective.prototype.debounce;
605
+ /** @type {?} */
606
+ FormDirective.prototype._clearDestroy;
607
+ /**
608
+ * @type {?}
609
+ * @private
610
+ */
611
+ FormDirective.prototype._destroy$;
612
+ /**
613
+ * @type {?}
614
+ * @private
615
+ */
616
+ FormDirective.prototype._updating;
617
+ /**
618
+ * @type {?}
619
+ * @private
620
+ */
621
+ FormDirective.prototype._actions$;
622
+ /**
623
+ * @type {?}
624
+ * @private
625
+ */
626
+ FormDirective.prototype._store;
627
+ /**
628
+ * @type {?}
629
+ * @private
630
+ */
631
+ FormDirective.prototype._formGroupDirective;
632
+ /**
633
+ * @type {?}
634
+ * @private
635
+ */
636
+ FormDirective.prototype._cd;
627
637
  }
628
638
 
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;
639
+ /**
640
+ * @fileoverview added by tsickle
641
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
642
+ */
643
+ var NgxsFormPluginModule = /** @class */ (function () {
644
+ function NgxsFormPluginModule() {
645
+ }
646
+ /**
647
+ * @return {?}
648
+ */
649
+ NgxsFormPluginModule.forRoot = /**
650
+ * @return {?}
651
+ */
652
+ function () {
653
+ return {
654
+ ngModule: NgxsFormPluginModule,
655
+ providers: [
656
+ {
657
+ provide: NGXS_PLUGINS,
658
+ useClass: NgxsFormPlugin,
659
+ multi: true
660
+ }
661
+ ]
662
+ };
663
+ };
664
+ NgxsFormPluginModule.decorators = [
665
+ { type: NgModule, args: [{
666
+ imports: [ReactiveFormsModule],
667
+ declarations: [FormDirective],
668
+ exports: [FormDirective]
669
+ },] }
670
+ ];
671
+ return NgxsFormPluginModule;
662
672
  }());
663
673
 
664
- /**
665
- * @fileoverview added by tsickle
666
- * @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
667
677
  */
668
678
 
669
- /**
670
- * @fileoverview added by tsickle
671
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
679
+ /**
680
+ * @fileoverview added by tsickle
681
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
672
682
  */
673
683
 
674
- /**
675
- * @fileoverview added by tsickle
676
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
684
+ /**
685
+ * @fileoverview added by tsickle
686
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
677
687
  */
678
688
 
679
689
  export { NgxsFormPlugin, NgxsFormPluginModule, ResetForm, SetFormDirty, SetFormDisabled, SetFormEnabled, SetFormPristine, UpdateForm, UpdateFormDirty, UpdateFormErrors, UpdateFormStatus, UpdateFormValue, FormDirective as ɵa };