@ngxs/form-plugin 3.7.6 → 3.8.0-dev.master-c341c15
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.
- package/bundles/ngxs-form-plugin.umd.js +147 -594
- package/bundles/ngxs-form-plugin.umd.js.map +1 -1
- package/esm2015/index.js +2 -6
- package/esm2015/ngxs-form-plugin.js +2 -7
- package/esm2015/src/actions.js +1 -105
- package/esm2015/src/directive.js +54 -184
- package/esm2015/src/form.module.js +13 -15
- package/esm2015/src/form.plugin.js +7 -29
- package/esm2015/src/public_api.js +3 -6
- package/fesm2015/ngxs-form-plugin.js +76 -343
- package/fesm2015/ngxs-form-plugin.js.map +1 -1
- package/ngxs-form-plugin.d.ts +1 -1
- package/package.json +5 -8
- package/src/actions.d.ts +10 -10
- package/src/directive.d.ts +11 -5
- package/src/form.module.d.ts +6 -0
- package/src/form.plugin.d.ts +3 -0
- package/src/public_api.d.ts +1 -0
- package/bundles/ngxs-form-plugin.umd.min.js +0 -16
- package/bundles/ngxs-form-plugin.umd.min.js.map +0 -1
- package/esm5/index.js +0 -9
- package/esm5/ngxs-form-plugin.js +0 -10
- package/esm5/src/actions.js +0 -225
- package/esm5/src/directive.js +0 -335
- package/esm5/src/form.module.js +0 -41
- package/esm5/src/form.plugin.js +0 -100
- package/esm5/src/public_api.js +0 -8
- package/fesm5/ngxs-form-plugin.js +0 -697
- package/fesm5/ngxs-form-plugin.js.map +0 -1
- package/ngxs-form-plugin.metadata.json +0 -1
|
@@ -1,697 +0,0 @@
|
|
|
1
|
-
import { Injectable, Directive, ChangeDetectorRef, Input, NgModule } from '@angular/core';
|
|
2
|
-
import { getActionTypeFromInstance, setValue, getValue, ofActionDispatched, Actions, Store, NGXS_PLUGINS } from '@ngxs/store';
|
|
3
|
-
import { __assign } from 'tslib';
|
|
4
|
-
import { FormGroupDirective, ReactiveFormsModule } from '@angular/forms';
|
|
5
|
-
import { Subject } from 'rxjs';
|
|
6
|
-
import { filter, takeUntil, distinctUntilChanged, debounceTime } from 'rxjs/operators';
|
|
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;
|
|
221
|
-
}
|
|
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)
|
|
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;
|
|
309
|
-
}());
|
|
310
|
-
/**
|
|
311
|
-
* @param {?} target
|
|
312
|
-
* @return {?}
|
|
313
|
-
*/
|
|
314
|
-
function isObjectLike(target) {
|
|
315
|
-
return target !== null && typeof target === 'object';
|
|
316
|
-
}
|
|
317
|
-
|
|
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
|
|
445
|
-
.valueChanges)).pipe(distinctUntilChanged((/**
|
|
446
|
-
* @param {?} a
|
|
447
|
-
* @param {?} b
|
|
448
|
-
* @return {?}
|
|
449
|
-
*/
|
|
450
|
-
function (a, b) { return JSON.stringify(a) === JSON.stringify(b); })), this.debounceChange())
|
|
451
|
-
.subscribe((/**
|
|
452
|
-
* @return {?}
|
|
453
|
-
*/
|
|
454
|
-
function () {
|
|
455
|
-
_this.updateFormStateWithRawValue();
|
|
456
|
-
}));
|
|
457
|
-
(/** @type {?} */ (this._formGroupDirective
|
|
458
|
-
.statusChanges)).pipe(distinctUntilChanged(), this.debounceChange())
|
|
459
|
-
.subscribe((/**
|
|
460
|
-
* @param {?} status
|
|
461
|
-
* @return {?}
|
|
462
|
-
*/
|
|
463
|
-
function (status) {
|
|
464
|
-
_this._store.dispatch(new UpdateFormStatus({
|
|
465
|
-
status: status,
|
|
466
|
-
path: _this.path
|
|
467
|
-
}));
|
|
468
|
-
}));
|
|
469
|
-
};
|
|
470
|
-
/**
|
|
471
|
-
* @param {?=} withFormStatus
|
|
472
|
-
* @return {?}
|
|
473
|
-
*/
|
|
474
|
-
FormDirective.prototype.updateFormStateWithRawValue = /**
|
|
475
|
-
* @param {?=} withFormStatus
|
|
476
|
-
* @return {?}
|
|
477
|
-
*/
|
|
478
|
-
function (withFormStatus) {
|
|
479
|
-
var _this = this;
|
|
480
|
-
if (this._updating)
|
|
481
|
-
return;
|
|
482
|
-
/** @type {?} */
|
|
483
|
-
var value = this._formGroupDirective.control.getRawValue();
|
|
484
|
-
/** @type {?} */
|
|
485
|
-
var actions = [
|
|
486
|
-
new UpdateFormValue({
|
|
487
|
-
path: this.path,
|
|
488
|
-
value: value
|
|
489
|
-
}),
|
|
490
|
-
new UpdateFormDirty({
|
|
491
|
-
path: this.path,
|
|
492
|
-
dirty: this._formGroupDirective.dirty
|
|
493
|
-
}),
|
|
494
|
-
new UpdateFormErrors({
|
|
495
|
-
path: this.path,
|
|
496
|
-
errors: this._formGroupDirective.errors
|
|
497
|
-
})
|
|
498
|
-
];
|
|
499
|
-
if (withFormStatus) {
|
|
500
|
-
actions.push(new UpdateFormStatus({
|
|
501
|
-
path: this.path,
|
|
502
|
-
status: this._formGroupDirective.status
|
|
503
|
-
}));
|
|
504
|
-
}
|
|
505
|
-
this._updating = true;
|
|
506
|
-
this._store.dispatch(actions).subscribe({
|
|
507
|
-
error: (/**
|
|
508
|
-
* @return {?}
|
|
509
|
-
*/
|
|
510
|
-
function () { return (_this._updating = false); }),
|
|
511
|
-
complete: (/**
|
|
512
|
-
* @return {?}
|
|
513
|
-
*/
|
|
514
|
-
function () { return (_this._updating = false); })
|
|
515
|
-
});
|
|
516
|
-
};
|
|
517
|
-
/**
|
|
518
|
-
* @return {?}
|
|
519
|
-
*/
|
|
520
|
-
FormDirective.prototype.ngOnDestroy = /**
|
|
521
|
-
* @return {?}
|
|
522
|
-
*/
|
|
523
|
-
function () {
|
|
524
|
-
this._destroy$.next();
|
|
525
|
-
this._destroy$.complete();
|
|
526
|
-
if (this.clearDestroy) {
|
|
527
|
-
this._store.dispatch(new UpdateForm({
|
|
528
|
-
path: this.path,
|
|
529
|
-
value: null,
|
|
530
|
-
dirty: null,
|
|
531
|
-
status: null,
|
|
532
|
-
errors: null
|
|
533
|
-
}));
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
|
-
/**
|
|
537
|
-
* @private
|
|
538
|
-
* @return {?}
|
|
539
|
-
*/
|
|
540
|
-
FormDirective.prototype.debounceChange = /**
|
|
541
|
-
* @private
|
|
542
|
-
* @return {?}
|
|
543
|
-
*/
|
|
544
|
-
function () {
|
|
545
|
-
var _this = this;
|
|
546
|
-
/** @type {?} */
|
|
547
|
-
var skipDebounceTime = this._formGroupDirective.control.updateOn !== 'change' || this.debounce < 0;
|
|
548
|
-
return skipDebounceTime
|
|
549
|
-
? (/**
|
|
550
|
-
* @param {?} change
|
|
551
|
-
* @return {?}
|
|
552
|
-
*/
|
|
553
|
-
function (change) { return change.pipe(takeUntil(_this._destroy$)); })
|
|
554
|
-
: (/**
|
|
555
|
-
* @param {?} change
|
|
556
|
-
* @return {?}
|
|
557
|
-
*/
|
|
558
|
-
function (change) {
|
|
559
|
-
return change.pipe(debounceTime(_this.debounce), takeUntil(_this._destroy$));
|
|
560
|
-
});
|
|
561
|
-
};
|
|
562
|
-
Object.defineProperty(FormDirective.prototype, "form", {
|
|
563
|
-
get: /**
|
|
564
|
-
* @private
|
|
565
|
-
* @return {?}
|
|
566
|
-
*/
|
|
567
|
-
function () {
|
|
568
|
-
return this._formGroupDirective.form;
|
|
569
|
-
},
|
|
570
|
-
enumerable: true,
|
|
571
|
-
configurable: true
|
|
572
|
-
});
|
|
573
|
-
/**
|
|
574
|
-
* @private
|
|
575
|
-
* @param {?} path
|
|
576
|
-
* @return {?}
|
|
577
|
-
*/
|
|
578
|
-
FormDirective.prototype.getStateStream = /**
|
|
579
|
-
* @private
|
|
580
|
-
* @param {?} path
|
|
581
|
-
* @return {?}
|
|
582
|
-
*/
|
|
583
|
-
function (path) {
|
|
584
|
-
return this._store.select((/**
|
|
585
|
-
* @param {?} state
|
|
586
|
-
* @return {?}
|
|
587
|
-
*/
|
|
588
|
-
function (state) { return getValue(state, path); })).pipe(takeUntil(this._destroy$));
|
|
589
|
-
};
|
|
590
|
-
FormDirective.decorators = [
|
|
591
|
-
{ type: Directive, args: [{ selector: '[ngxsForm]' },] }
|
|
592
|
-
];
|
|
593
|
-
/** @nocollapse */
|
|
594
|
-
FormDirective.ctorParameters = function () { return [
|
|
595
|
-
{ type: Actions },
|
|
596
|
-
{ type: Store },
|
|
597
|
-
{ type: FormGroupDirective },
|
|
598
|
-
{ type: ChangeDetectorRef }
|
|
599
|
-
]; };
|
|
600
|
-
FormDirective.propDecorators = {
|
|
601
|
-
path: [{ type: Input, args: ['ngxsForm',] }],
|
|
602
|
-
debounce: [{ type: Input, args: ['ngxsFormDebounce',] }],
|
|
603
|
-
clearDestroy: [{ type: Input, args: ['ngxsFormClearOnDestroy',] }]
|
|
604
|
-
};
|
|
605
|
-
return FormDirective;
|
|
606
|
-
}());
|
|
607
|
-
if (false) {
|
|
608
|
-
/** @type {?} */
|
|
609
|
-
FormDirective.prototype.path;
|
|
610
|
-
/** @type {?} */
|
|
611
|
-
FormDirective.prototype.debounce;
|
|
612
|
-
/** @type {?} */
|
|
613
|
-
FormDirective.prototype._clearDestroy;
|
|
614
|
-
/**
|
|
615
|
-
* @type {?}
|
|
616
|
-
* @private
|
|
617
|
-
*/
|
|
618
|
-
FormDirective.prototype._destroy$;
|
|
619
|
-
/**
|
|
620
|
-
* @type {?}
|
|
621
|
-
* @private
|
|
622
|
-
*/
|
|
623
|
-
FormDirective.prototype._updating;
|
|
624
|
-
/**
|
|
625
|
-
* @type {?}
|
|
626
|
-
* @private
|
|
627
|
-
*/
|
|
628
|
-
FormDirective.prototype._actions$;
|
|
629
|
-
/**
|
|
630
|
-
* @type {?}
|
|
631
|
-
* @private
|
|
632
|
-
*/
|
|
633
|
-
FormDirective.prototype._store;
|
|
634
|
-
/**
|
|
635
|
-
* @type {?}
|
|
636
|
-
* @private
|
|
637
|
-
*/
|
|
638
|
-
FormDirective.prototype._formGroupDirective;
|
|
639
|
-
/**
|
|
640
|
-
* @type {?}
|
|
641
|
-
* @private
|
|
642
|
-
*/
|
|
643
|
-
FormDirective.prototype._cd;
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
/**
|
|
647
|
-
* @fileoverview added by tsickle
|
|
648
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
649
|
-
*/
|
|
650
|
-
var NgxsFormPluginModule = /** @class */ (function () {
|
|
651
|
-
function NgxsFormPluginModule() {
|
|
652
|
-
}
|
|
653
|
-
/**
|
|
654
|
-
* @return {?}
|
|
655
|
-
*/
|
|
656
|
-
NgxsFormPluginModule.forRoot = /**
|
|
657
|
-
* @return {?}
|
|
658
|
-
*/
|
|
659
|
-
function () {
|
|
660
|
-
return {
|
|
661
|
-
ngModule: NgxsFormPluginModule,
|
|
662
|
-
providers: [
|
|
663
|
-
{
|
|
664
|
-
provide: NGXS_PLUGINS,
|
|
665
|
-
useClass: NgxsFormPlugin,
|
|
666
|
-
multi: true
|
|
667
|
-
}
|
|
668
|
-
]
|
|
669
|
-
};
|
|
670
|
-
};
|
|
671
|
-
NgxsFormPluginModule.decorators = [
|
|
672
|
-
{ type: NgModule, args: [{
|
|
673
|
-
imports: [ReactiveFormsModule],
|
|
674
|
-
declarations: [FormDirective],
|
|
675
|
-
exports: [FormDirective]
|
|
676
|
-
},] }
|
|
677
|
-
];
|
|
678
|
-
return NgxsFormPluginModule;
|
|
679
|
-
}());
|
|
680
|
-
|
|
681
|
-
/**
|
|
682
|
-
* @fileoverview added by tsickle
|
|
683
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
684
|
-
*/
|
|
685
|
-
|
|
686
|
-
/**
|
|
687
|
-
* @fileoverview added by tsickle
|
|
688
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
689
|
-
*/
|
|
690
|
-
|
|
691
|
-
/**
|
|
692
|
-
* @fileoverview added by tsickle
|
|
693
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
694
|
-
*/
|
|
695
|
-
|
|
696
|
-
export { NgxsFormPlugin, NgxsFormPluginModule, ResetForm, SetFormDirty, SetFormDisabled, SetFormEnabled, SetFormPristine, UpdateForm, UpdateFormDirty, UpdateFormErrors, UpdateFormStatus, UpdateFormValue, FormDirective as ɵa };
|
|
697
|
-
//# sourceMappingURL=ngxs-form-plugin.js.map
|