@bolttech/form-engine-core 0.0.1-beta.11 → 0.0.1-beta.12
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/index.esm.js +26 -7
- package/package.json +1 -1
- package/src/helpers/SafeSubject.d.ts +11 -0
- package/src/managers/field.d.ts +8 -6
package/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Subject, Subscription, combineLatest, startWith, groupBy, mergeMap, debounceTime, filter, map } from 'rxjs';
|
|
2
2
|
import creditCardType from 'credit-card-type';
|
|
3
3
|
import { isNumber as isNumber$1, isNil, isEqual, get, set } from 'lodash';
|
|
4
4
|
import { getCurrencySymbol } from '@gaignoux/currency';
|
|
@@ -2252,6 +2252,22 @@ const validations = {
|
|
|
2252
2252
|
const DEFAULT_API_DEBOUNCE_TIME = 1000;
|
|
2253
2253
|
const DEFAULT_STATE_REFRESH_TIME = 100;
|
|
2254
2254
|
|
|
2255
|
+
/**
|
|
2256
|
+
* Custom RXJS Subject to gracefully handle errors on unsubscribed Subjects
|
|
2257
|
+
* that were unmounted due to adapter external handling such as visibility
|
|
2258
|
+
*/
|
|
2259
|
+
class SafeSubject extends Subject {
|
|
2260
|
+
constructor(isMounted) {
|
|
2261
|
+
super();
|
|
2262
|
+
this.isMounted = isMounted;
|
|
2263
|
+
}
|
|
2264
|
+
next(value) {
|
|
2265
|
+
if (this.isMounted()) {
|
|
2266
|
+
super.next(value);
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2255
2271
|
/**
|
|
2256
2272
|
* Represents a form field with observables for managing form state, validations, and API requests.
|
|
2257
2273
|
*/
|
|
@@ -2333,6 +2349,7 @@ class FormField {
|
|
|
2333
2349
|
};
|
|
2334
2350
|
this._errors = {};
|
|
2335
2351
|
this._valid = false;
|
|
2352
|
+
this._mounted = true;
|
|
2336
2353
|
this.initializeObservers();
|
|
2337
2354
|
}
|
|
2338
2355
|
/**
|
|
@@ -2341,25 +2358,25 @@ class FormField {
|
|
|
2341
2358
|
initializeObservers() {
|
|
2342
2359
|
var _a;
|
|
2343
2360
|
if (!this.valueSubject$ || this.valueSubject$.closed) {
|
|
2344
|
-
this.valueSubject$ = new
|
|
2361
|
+
this.valueSubject$ = new SafeSubject(() => this._mounted);
|
|
2345
2362
|
}
|
|
2346
2363
|
if (!this.errorSubject$ || this.errorSubject$.closed) {
|
|
2347
|
-
this.errorSubject$ = new
|
|
2364
|
+
this.errorSubject$ = new SafeSubject(() => this._mounted);
|
|
2348
2365
|
}
|
|
2349
2366
|
if (!this.visibilitySubject$ || this.visibilitySubject$.closed) {
|
|
2350
|
-
this.visibilitySubject$ = new
|
|
2367
|
+
this.visibilitySubject$ = new SafeSubject(() => this._mounted);
|
|
2351
2368
|
}
|
|
2352
2369
|
if (!this.apiSubject$ || this.apiSubject$.closed) {
|
|
2353
|
-
this.apiSubject$ = new
|
|
2370
|
+
this.apiSubject$ = new SafeSubject(() => this._mounted);
|
|
2354
2371
|
}
|
|
2355
2372
|
if (!this.propsSubject$ || this.propsSubject$.closed) {
|
|
2356
|
-
this.propsSubject$ = new
|
|
2373
|
+
this.propsSubject$ = new SafeSubject(() => this._mounted);
|
|
2357
2374
|
}
|
|
2358
2375
|
if (!this.fieldStateSubscription$ || this.fieldStateSubscription$.closed) {
|
|
2359
2376
|
this.fieldStateSubscription$ = new Subscription();
|
|
2360
2377
|
}
|
|
2361
2378
|
if (!this.apiEventQueueSubject$ || this.apiEventQueueSubject$.closed) {
|
|
2362
|
-
this.apiEventQueueSubject$ = new
|
|
2379
|
+
this.apiEventQueueSubject$ = new SafeSubject(() => this._mounted);
|
|
2363
2380
|
}
|
|
2364
2381
|
this.fieldState$ = combineLatest({
|
|
2365
2382
|
visibility: this.visibilitySubject$.pipe(startWith(this._visibility)),
|
|
@@ -2563,6 +2580,7 @@ class FormField {
|
|
|
2563
2580
|
this.initializeObservers();
|
|
2564
2581
|
this.subscribeValue(valueSubscription);
|
|
2565
2582
|
this.subscribeState(propsSubscription);
|
|
2583
|
+
this._mounted = true;
|
|
2566
2584
|
}
|
|
2567
2585
|
/**
|
|
2568
2586
|
* Sets the value of the form field and emits associated events.
|
|
@@ -2796,6 +2814,7 @@ class FormField {
|
|
|
2796
2814
|
* @returns {void}
|
|
2797
2815
|
*/
|
|
2798
2816
|
destroyField() {
|
|
2817
|
+
this._mounted = false;
|
|
2799
2818
|
this.valueSubject$.unsubscribe();
|
|
2800
2819
|
this.visibilitySubject$.unsubscribe();
|
|
2801
2820
|
this.fieldStateSubscription$.unsubscribe();
|
package/package.json
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Subject } from 'rxjs';
|
|
2
|
+
/**
|
|
3
|
+
* Custom RXJS Subject to gracefully handle errors on unsubscribed Subjects
|
|
4
|
+
* that were unmounted due to adapter external handling such as visibility
|
|
5
|
+
*/
|
|
6
|
+
declare class SafeSubject<T> extends Subject<T> {
|
|
7
|
+
private isMounted;
|
|
8
|
+
constructor(isMounted: () => boolean);
|
|
9
|
+
next(value: T): void;
|
|
10
|
+
}
|
|
11
|
+
export { SafeSubject };
|
package/src/managers/field.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { IComponentSchema, IComponentSchemaAsFormField } from '../interfaces/sch
|
|
|
4
4
|
import { IState } from '../interfaces/state';
|
|
5
5
|
import { TEvents, TFieldEvent, TMutationEvents, TValueChangeEvent } from '../types/event';
|
|
6
6
|
import { TMapper } from '../types/mapper';
|
|
7
|
+
import { SafeSubject } from '../helpers/SafeSubject';
|
|
7
8
|
/**
|
|
8
9
|
* Represents a form field with observables for managing form state, validations, and API requests.
|
|
9
10
|
*/
|
|
@@ -35,13 +36,14 @@ declare class FormField {
|
|
|
35
36
|
private _errors;
|
|
36
37
|
private _api;
|
|
37
38
|
private _valid;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
private _mounted;
|
|
40
|
+
propsSubject$: SafeSubject<Record<string, unknown>>;
|
|
41
|
+
errorSubject$: SafeSubject<Record<string, unknown>>;
|
|
42
|
+
valueSubject$: SafeSubject<Record<string, unknown>>;
|
|
43
|
+
visibilitySubject$: SafeSubject<boolean>;
|
|
44
|
+
apiSubject$: SafeSubject<TApiResponse>;
|
|
43
45
|
fieldEventSubject$: Subject<TFieldEvent>;
|
|
44
|
-
apiEventQueueSubject$:
|
|
46
|
+
apiEventQueueSubject$: SafeSubject<{
|
|
45
47
|
event: TEvents;
|
|
46
48
|
}>;
|
|
47
49
|
fieldState$: Observable<IState>;
|