@ethlete/core 4.32.0 → 4.32.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ethlete/core
2
2
 
3
+ ## 4.32.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`ba5501f`](https://github.com/ethlete-io/ethdk/commit/ba5501f9d86878d1d02a2dea68ccaf591ff48611) Thanks [@TomTomB](https://github.com/TomTomB)! - Let a user selection change in `SelectionModel` cancel a pending `setSelectionFromValue$`, and expose `isSyncingSelectionFromValue` while it waits for options.
8
+
3
9
  ## 4.32.0
4
10
 
5
11
  ### Minor Changes
@@ -3078,6 +3078,9 @@ function formatRuntimeError(code, message, devOnly) {
3078
3078
  }
3079
3079
 
3080
3080
  class SelectionModel {
3081
+ get isSyncingSelectionFromValue() {
3082
+ return this._isSyncingSelectionFromValue;
3083
+ }
3081
3084
  get selection$() {
3082
3085
  return this._selection$.asObservable();
3083
3086
  }
@@ -3129,6 +3132,7 @@ class SelectionModel {
3129
3132
  constructor() {
3130
3133
  this._destroy$ = createDestroy();
3131
3134
  this._lastSelectionSetSubscription = null;
3135
+ this._isSyncingSelectionFromValue = false;
3132
3136
  this._selection$ = new BehaviorSubject([]);
3133
3137
  this._options$ = new BehaviorSubject([]);
3134
3138
  this.optionsSignal = toSignal(this.options$);
@@ -3175,19 +3179,22 @@ class SelectionModel {
3175
3179
  }
3176
3180
  else {
3177
3181
  const selection = this.getOptionByValue(value);
3178
- if (selection) {
3179
- this.setSelection(selection);
3180
- }
3181
- else {
3182
- this.clearSelectedOptions();
3183
- }
3182
+ this.setSelection(selection !== undefined ? selection : []);
3184
3183
  }
3185
3184
  }
3185
+ /**
3186
+ * Applies `value` once options are available. Until then, and while applying it, `isSyncingSelectionFromValue` is `true`.
3187
+ * Any user selection change cancels a pending sync.
3188
+ */
3186
3189
  setSelectionFromValue$(value) {
3187
- this._lastSelectionSetSubscription?.unsubscribe();
3190
+ this._cancelPendingSelectionFromValue();
3191
+ this._isSyncingSelectionFromValue = true;
3188
3192
  this._lastSelectionSetSubscription = this.options$
3189
- .pipe(takeUntil(this._destroy$), filter((o) => !!o.length), tap(() => this.setSelectionFromValue(value)), take(1))
3190
- .subscribe();
3193
+ .pipe(takeUntil(this._destroy$), filter((o) => !!o.length), take(1))
3194
+ .subscribe(() => {
3195
+ this.setSelectionFromValue(value);
3196
+ this._isSyncingSelectionFromValue = false;
3197
+ });
3191
3198
  }
3192
3199
  setValueBinding(fnOrPropertyPath) {
3193
3200
  this._valueBinding$.next(fnOrPropertyPath);
@@ -3403,6 +3410,7 @@ class SelectionModel {
3403
3410
  });
3404
3411
  }
3405
3412
  addSelectedOption(option) {
3413
+ this._cancelPendingSelectionFromValue();
3406
3414
  if (this.allowMultiple) {
3407
3415
  if (this.isSelected(option))
3408
3416
  return;
@@ -3413,6 +3421,7 @@ class SelectionModel {
3413
3421
  }
3414
3422
  }
3415
3423
  removeSelectedOption(option) {
3424
+ this._cancelPendingSelectionFromValue();
3416
3425
  const optionKey = this.execFnOrGetOptionProperty(option, this.keyBinding);
3417
3426
  if (!this.isSelected(option))
3418
3427
  return;
@@ -3422,6 +3431,7 @@ class SelectionModel {
3422
3431
  }));
3423
3432
  }
3424
3433
  clearSelectedOptions() {
3434
+ this._cancelPendingSelectionFromValue();
3425
3435
  this._selection$.next([]);
3426
3436
  }
3427
3437
  toggleSelectedOption(option) {
@@ -3434,6 +3444,7 @@ class SelectionModel {
3434
3444
  }
3435
3445
  // FIXME: Toggle should respect disabled binding if it exists
3436
3446
  toggleAllSelectedOptions() {
3447
+ this._cancelPendingSelectionFromValue();
3437
3448
  const filteredOptions = this.getFilteredOptions();
3438
3449
  const unselectedOptions = filteredOptions.filter((option) => !this.isSelected(option));
3439
3450
  if (unselectedOptions.length) {
@@ -3445,6 +3456,11 @@ class SelectionModel {
3445
3456
  this._selection$.next(selection);
3446
3457
  }
3447
3458
  }
3459
+ _cancelPendingSelectionFromValue() {
3460
+ this._lastSelectionSetSubscription?.unsubscribe();
3461
+ this._lastSelectionSetSubscription = null;
3462
+ this._isSyncingSelectionFromValue = false;
3463
+ }
3448
3464
  }
3449
3465
 
3450
3466
  const scrollBehaviorSupported = supportsScrollBehavior();