@bolttech/form-engine-core 1.0.9 → 1.0.10

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.
Files changed (3) hide show
  1. package/index.d.ts +13 -2
  2. package/index.esm.js +34 -6
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as rxjs from 'rxjs';
2
- import { Subject, Subscription, BehaviorSubject } from 'rxjs';
2
+ import { Subject, BehaviorSubject, Subscription } from 'rxjs';
3
3
  import { TCurrencyLocalCode, TCurrencyCode } from '@gaignoux/currency';
4
4
  import { OutgoingHttpHeaders } from 'http2';
5
5
 
@@ -1314,6 +1314,16 @@ declare class SafeSubject<T> extends Subject<T> {
1314
1314
  constructor(isMounted: () => boolean);
1315
1315
  next(value: T): void;
1316
1316
  }
1317
+ /**
1318
+ * Custom RXJS BehaviourSubject to gracefully handle errors on unsubscribed Subjects
1319
+ * since its fire and forget, no mount status needed to check if its available or not
1320
+ */
1321
+ declare class SafeBehaviourSubject<T> extends BehaviorSubject<T> {
1322
+ defaultValue: T;
1323
+ constructor(value: T);
1324
+ next(value: T): void;
1325
+ get value(): T;
1326
+ }
1317
1327
 
1318
1328
  type TTemplateAvaliableScopes = (typeof TEMPLATE_AVALIABLE_SCOPES)[number];
1319
1329
  /**
@@ -1727,7 +1737,7 @@ declare class FormCore {
1727
1737
  dataSubject$: Subject<TFormDataPayload>;
1728
1738
  formValidSubject$: Subject<TFormValidationPayload>;
1729
1739
  fieldValidNotification$: Subject<TFieldValidationPayload>;
1730
- formValuesStateSubject$: BehaviorSubject<TFormValues<unknown>>;
1740
+ formValuesStateSubject$: SafeBehaviourSubject<TFormValues<unknown>>;
1731
1741
  subscribedTemplates: TSubscribedTemplates[];
1732
1742
  action?: string;
1733
1743
  method?: string;
@@ -1750,6 +1760,7 @@ declare class FormCore {
1750
1760
  stopEventsOnSubmit: boolean;
1751
1761
  submitted: boolean;
1752
1762
  getFormValues: () => TFormValues<unknown>;
1763
+ isolatedFormInstance: boolean;
1753
1764
  /**
1754
1765
  * Creates an instance of FormCore.
1755
1766
  *
package/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Subject, Subscription, groupBy, mergeMap, debounceTime, filter, combineLatest, startWith, BehaviorSubject, map, distinctUntilKeyChanged } from 'rxjs';
1
+ import { BehaviorSubject, Subject, Subscription, groupBy, mergeMap, debounceTime, filter, combineLatest, startWith, map, distinctUntilKeyChanged } from 'rxjs';
2
2
  import creditCardType from 'credit-card-type';
3
3
  import isNumber$1 from 'lodash/isNumber';
4
4
  import { getCurrencySymbol } from '@gaignoux/currency';
@@ -2462,6 +2462,28 @@ class SafeSubject extends Subject {
2462
2462
  }
2463
2463
  }
2464
2464
  }
2465
+ /**
2466
+ * Custom RXJS BehaviourSubject to gracefully handle errors on unsubscribed Subjects
2467
+ * since its fire and forget, no mount status needed to check if its available or not
2468
+ */
2469
+ class SafeBehaviourSubject extends BehaviorSubject {
2470
+ constructor(value) {
2471
+ super(value);
2472
+ this.defaultValue = value;
2473
+ }
2474
+ next(value) {
2475
+ if (!this.closed) {
2476
+ super.next(value);
2477
+ }
2478
+ }
2479
+ get value() {
2480
+ if (!this.closed) {
2481
+ return super.value;
2482
+ } else {
2483
+ return this.defaultValue;
2484
+ }
2485
+ }
2486
+ }
2465
2487
 
2466
2488
  /**
2467
2489
  * @internal
@@ -3273,6 +3295,7 @@ class FormCore {
3273
3295
  this._valid = false;
3274
3296
  this.stopEventsOnSubmit = false;
3275
3297
  this.submitted = false;
3298
+ this.isolatedFormInstance = false;
3276
3299
  this.index = entry.index;
3277
3300
  this.schema = entry.schema;
3278
3301
  this.fields = new Map();
@@ -3286,7 +3309,10 @@ class FormCore {
3286
3309
  (_h = entry.mappers) === null || _h === void 0 ? void 0 : _h.map(mapper => {
3287
3310
  this.mappers.set(mapper.componentName, mapper);
3288
3311
  });
3289
- if ((!entry.submitSubject$ || !entry.dataSubject$ || !entry.formValidSubject$) && this.config.defaultLogVerbose) console.warn(`some formGroup events are not properly instanciated, any onData, onValid, onSubmit events managed by formGroup won't trigger on form: ${this.index}`);
3312
+ if (!entry.submitSubject$ || !entry.dataSubject$ || !entry.formValidSubject$) {
3313
+ this.isolatedFormInstance = true;
3314
+ if (this.config.defaultLogVerbose) console.warn(`some formGroup events are not properly instanciated, any onData, onValid, onSubmit events managed by formGroup won't trigger on form: ${this.index}`);
3315
+ }
3290
3316
  if (this.schema) {
3291
3317
  FormCore.checkIndexes(this.schema.components);
3292
3318
  }
@@ -3297,7 +3323,7 @@ class FormCore {
3297
3323
  this.submitSubject$ = entry.submitSubject$ ? entry.submitSubject$ : new Subject();
3298
3324
  this.dataSubject$ = entry.dataSubject$ ? entry.dataSubject$ : new Subject();
3299
3325
  this.formValidSubject$ = entry.formValidSubject$ ? entry.formValidSubject$ : new Subject();
3300
- this.formValuesStateSubject$ = new BehaviorSubject({
3326
+ this.formValuesStateSubject$ = new SafeBehaviourSubject({
3301
3327
  erroredFields: [],
3302
3328
  isValid: true,
3303
3329
  metadata: [],
@@ -4269,13 +4295,15 @@ class FormCore {
4269
4295
  destroy() {
4270
4296
  this.templateSubject$.unsubscribe();
4271
4297
  this.templateSubscription$.unsubscribe();
4272
- this.submitSubject$.unsubscribe();
4273
4298
  this.mountSubject$.unsubscribe();
4274
4299
  this.fieldEventSubject$.unsubscribe();
4275
- this.dataSubject$.unsubscribe();
4276
- this.formValidSubject$.unsubscribe();
4277
4300
  this.fieldValidNotification$.unsubscribe();
4278
4301
  this.formValuesStateSubject$.unsubscribe();
4302
+ if (this.isolatedFormInstance) {
4303
+ this.submitSubject$.unsubscribe();
4304
+ this.dataSubject$.unsubscribe();
4305
+ this.formValidSubject$.unsubscribe();
4306
+ }
4279
4307
  this.fields.forEach(field => field.destroyField());
4280
4308
  }
4281
4309
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bolttech/form-engine-core",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "dependencies": {
5
5
  "@gaignoux/currency": "^1.1.0",
6
6
  "credit-card-type": "^10.0.0",