@ngrdt/forms 0.0.41 → 0.0.44

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.
@@ -576,6 +576,7 @@ class RdtOfflineSelectDatasource extends RdtSelectDatasource {
576
576
  }
577
577
 
578
578
  const rdtSelectInitialState = {
579
+ initialized: false,
579
580
  query: null,
580
581
  nextPageIndex: 0,
581
582
  pageSize: 20,
@@ -642,6 +643,14 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
642
643
  return selected;
643
644
  }),
644
645
  })), withMethods((store) => ({
646
+ init(initialValue) {
647
+ if (initialValue && initialValue.length > 0) {
648
+ this.setSelected(initialValue ?? []);
649
+ }
650
+ else {
651
+ patchState(store, { initialized: true });
652
+ }
653
+ },
645
654
  fetch() {
646
655
  const datasource = untracked(store.datasource);
647
656
  const index = untracked(store.nextPageIndex);
@@ -813,9 +822,12 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
813
822
  return newMissing;
814
823
  },
815
824
  _loadMissingSelected() {
825
+ const datasource = store.datasource();
816
826
  const reallyMissing = this._setAndGetMissing();
817
- if (!untracked(store.loading) && reallyMissing.length > 0) {
818
- this._fetchMissing(reallyMissing);
827
+ if (!untracked(store.loading) &&
828
+ reallyMissing.length > 0 &&
829
+ datasource) {
830
+ this._fetchMissing(reallyMissing, datasource);
819
831
  }
820
832
  },
821
833
  _cancelFetchMissingIfNeeded() {
@@ -829,9 +841,8 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
829
841
  });
830
842
  }
831
843
  },
832
- _fetchMissing(ids) {
833
- const datasource = untracked(store.datasource);
834
- if (!datasource || ids.length === 0) {
844
+ _fetchMissing(ids, datasource) {
845
+ if (ids.length === 0) {
835
846
  return;
836
847
  }
837
848
  const sub = datasource.getItemsByIds(ids).subscribe((map) => {
@@ -851,6 +862,7 @@ function getRdtSelectStore(initialState = rdtSelectInitialState) {
851
862
  _fetchMissingRequest: null,
852
863
  _missingSelected: newMissing,
853
864
  selectedMap: newSelected,
865
+ initialized: true,
854
866
  });
855
867
  this._loadMissingSelected();
856
868
  });
@@ -1054,6 +1066,16 @@ class RdtBaseSelectCommonComponent extends RdtBaseFormInputComponent {
1054
1066
  });
1055
1067
  ngOnInit() {
1056
1068
  super.ngOnInit();
1069
+ const control = this.control();
1070
+ if (control && control.value !== null) {
1071
+ const arr = Array.isArray(control.value)
1072
+ ? control.value
1073
+ : [control.value];
1074
+ this.store.init(arr);
1075
+ }
1076
+ else {
1077
+ this.store.init(null);
1078
+ }
1057
1079
  this.debouncedInput$
1058
1080
  .pipe(takeUntilDestroyed(this.destroyRef))
1059
1081
  .subscribe((value) => this.handleInput(value));