@ngx-formly/core 6.0.1 → 6.0.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.
@@ -2,7 +2,7 @@ import * as i0 from '@angular/core';
2
2
  import { Type, TemplateRef, ComponentRef, ChangeDetectorRef, InjectionToken, Injectable, Optional, Directive, Input, ViewContainerRef, Component, ViewChild, EventEmitter, ChangeDetectionStrategy, Output, ContentChildren, Inject, NgModule } from '@angular/core';
3
3
  import * as i2 from '@angular/forms';
4
4
  import { AbstractControl, FormGroup, FormArray, FormControl, Validators } from '@angular/forms';
5
- import { isObservable, merge, of, Observable, Subject } from 'rxjs';
5
+ import { isObservable, merge, of, Observable, tap, Subject } from 'rxjs';
6
6
  import { distinctUntilChanged, startWith, debounceTime, filter, switchMap, take, map } from 'rxjs/operators';
7
7
  import * as i2$1 from '@angular/common';
8
8
  import { DOCUMENT, CommonModule } from '@angular/common';
@@ -894,6 +894,24 @@ class FormlyField {
894
894
  observeDeep(field, ['props'], () => field.options.detectChanges(field)),
895
895
  observeDeep(field.options, ['formState'], () => field.options.detectChanges(field)),
896
896
  ];
897
+ for (const key of Object.keys(field._expressions)) {
898
+ const expressionObserver = observe(field, ['_expressions', key], ({ currentValue, previousValue }) => {
899
+ if (previousValue === null || previousValue === void 0 ? void 0 : previousValue.subscription) {
900
+ previousValue.subscription.unsubscribe();
901
+ previousValue.subscription = null;
902
+ }
903
+ if (isObservable(currentValue.value$)) {
904
+ currentValue.subscription = currentValue.value$.subscribe();
905
+ }
906
+ });
907
+ subscribes.push(() => {
908
+ var _a;
909
+ if ((_a = field._expressions[key]) === null || _a === void 0 ? void 0 : _a.subscription) {
910
+ field._expressions[key].subscription.unsubscribe();
911
+ }
912
+ expressionObserver.unsubscribe();
913
+ });
914
+ }
897
915
  for (const path of [['template'], ['fieldGroupClassName'], ['validation', 'show']]) {
898
916
  const fieldObserver = observe(field, path, ({ firstChange }) => !firstChange && field.options.detectChanges(field));
899
917
  subscribes.push(() => fieldObserver.unsubscribe());
@@ -1425,7 +1443,9 @@ class FieldArrayType extends FieldType {
1425
1443
  markAsDirty && this.formControl.markAsDirty();
1426
1444
  }
1427
1445
  _build() {
1428
- this.options.build(this.field);
1446
+ var _a;
1447
+ const fields = (_a = this.field.formControl._fields) !== null && _a !== void 0 ? _a : [this.field];
1448
+ fields.forEach((f) => this.options.build(f));
1429
1449
  this.options.fieldChanges.next({
1430
1450
  field: this.field,
1431
1451
  value: getFieldValue(this.field),
@@ -1527,22 +1547,11 @@ class FieldExpressionExtension {
1527
1547
  field._expressions[key] = this.parseExpressions(field, key, expr);
1528
1548
  }
1529
1549
  else if (expr instanceof Observable) {
1530
- const subscribe = () => expr.subscribe((v) => {
1531
- this.evalExpr(field, key, v);
1532
- });
1533
- let subscription = null;
1534
- const onInit = field.hooks.onInit;
1535
- field.hooks.onInit = () => {
1536
- if (subscription === null) {
1537
- subscription = subscribe();
1538
- }
1539
- return onInit === null || onInit === void 0 ? void 0 : onInit(field);
1540
- };
1541
- const onDestroy = field.hooks.onDestroy;
1542
- field.hooks.onDestroy = () => {
1543
- onDestroy === null || onDestroy === void 0 ? void 0 : onDestroy(field);
1544
- subscription.unsubscribe();
1545
- subscription = null;
1550
+ field._expressions[key] = {
1551
+ value$: expr.pipe(tap((v) => {
1552
+ this.evalExpr(field, key, v);
1553
+ field.options.detectChanges(field);
1554
+ })),
1546
1555
  };
1547
1556
  }
1548
1557
  };
@@ -1630,17 +1639,17 @@ class FieldExpressionExtension {
1630
1639
  };
1631
1640
  }
1632
1641
  checkExpressions(field, ignoreCache = false) {
1633
- var _a;
1642
+ var _a, _b, _c;
1634
1643
  if (!field) {
1635
1644
  return false;
1636
1645
  }
1637
1646
  let fieldChanged = false;
1638
1647
  if (field._expressions) {
1639
1648
  for (const key of Object.keys(field._expressions)) {
1640
- field._expressions[key].callback(ignoreCache) && (fieldChanged = true);
1649
+ ((_b = (_a = field._expressions[key]).callback) === null || _b === void 0 ? void 0 : _b.call(_a, ignoreCache)) && (fieldChanged = true);
1641
1650
  }
1642
1651
  }
1643
- (_a = field.fieldGroup) === null || _a === void 0 ? void 0 : _a.forEach((f) => this.checkExpressions(f, ignoreCache) && (fieldChanged = true));
1652
+ (_c = field.fieldGroup) === null || _c === void 0 ? void 0 : _c.forEach((f) => this.checkExpressions(f, ignoreCache) && (fieldChanged = true));
1644
1653
  return fieldChanged;
1645
1654
  }
1646
1655
  changeDisabledState(field, value) {