@xh/hoist 74.0.0-SNAPSHOT.1748340686867 → 74.0.0-SNAPSHOT.1748449301934

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
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## 74.0.0-SNAPSHOT - unreleased
4
4
 
5
+ ### 🎁 New Features
6
+ + Add `ViewManagerModel.preserveUnsavedChanges` flag to opt-out of that behaviour.
7
+
8
+ ### 🐞 Bug Fixes
9
+ + Improves `ViewManagerModel.settleTime` by comparing to when the view is pushed to components
10
+ rather than when view is loaded from the server.
11
+
5
12
  ## v73.0.1 - 2025-05-19
6
13
 
7
14
  ### 🐞 Bug Fixes
@@ -43,6 +43,11 @@ export interface ViewManagerConfig {
43
43
  * True (default) to allow users to share their views with other users.
44
44
  */
45
45
  enableSharing?: boolean;
46
+ /**
47
+ * True (default) to save pending state to SessionStorage so that it can be restored across
48
+ * browser refreshes. Unlike auto-save, this does not write to the database.
49
+ */
50
+ preserveUnsavedChanges?: boolean;
46
51
  /**
47
52
  * Function to determine the initial view for a user, when no view has already been persisted.
48
53
  * Will be passed a list of views available to the current user. Implementations where
@@ -132,6 +137,7 @@ export declare class ViewManagerModel<T = PlainObject> extends HoistModel {
132
137
  readonly enableDefault: boolean;
133
138
  readonly enableGlobal: boolean;
134
139
  readonly enableSharing: boolean;
140
+ readonly preserveUnsavedChanges: boolean;
135
141
  readonly manageGlobal: boolean;
136
142
  readonly settleTime: number;
137
143
  readonly initialViewSpec: (views: ViewInfo[]) => ViewInfo;
@@ -198,6 +204,7 @@ export declare class ViewManagerModel<T = PlainObject> extends HoistModel {
198
204
  resetAsync(): Promise<void>;
199
205
  getValue(): Partial<T>;
200
206
  setValue(value: Partial<T>): void;
207
+ noteStatePushed(): void;
201
208
  userPin(view: ViewInfo): void;
202
209
  userUnpin(view: ViewInfo): void;
203
210
  isUserPinned(view: ViewInfo): boolean | null;
@@ -1,10 +1,12 @@
1
+ import { Persistable } from '@xh/hoist/core';
1
2
  import { PersistenceProvider, PersistenceProviderConfig } from '../PersistenceProvider';
2
3
  import type { ViewManagerModel } from '@xh/hoist/cmp/viewmanager/ViewManagerModel';
3
4
  export declare class ViewManagerProvider<S> extends PersistenceProvider<S> {
4
5
  readonly viewManagerModel: ViewManagerModel;
5
6
  constructor(cfg: PersistenceProviderConfig<S>);
6
7
  pushStateToTarget(): void;
7
- readRaw(): Partial<import("../..").PlainObject>;
8
+ bindToTarget(target: Persistable<S>): void;
9
+ readRaw(): Partial<import("@xh/hoist/core").PlainObject>;
8
10
  writeRaw(data: Record<typeof this.path, S>): void;
9
11
  destroy(): void;
10
12
  }
@@ -74,6 +74,12 @@ export interface ViewManagerConfig {
74
74
  */
75
75
  enableSharing?: boolean;
76
76
 
77
+ /**
78
+ * True (default) to save pending state to SessionStorage so that it can be restored across
79
+ * browser refreshes. Unlike auto-save, this does not write to the database.
80
+ */
81
+ preserveUnsavedChanges?: boolean;
82
+
77
83
  /**
78
84
  * Function to determine the initial view for a user, when no view has already been persisted.
79
85
  * Will be passed a list of views available to the current user. Implementations where
@@ -176,6 +182,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
176
182
  readonly enableDefault: boolean;
177
183
  readonly enableGlobal: boolean;
178
184
  readonly enableSharing: boolean;
185
+ readonly preserveUnsavedChanges: boolean;
179
186
  readonly manageGlobal: boolean;
180
187
  readonly settleTime: number;
181
188
  readonly initialViewSpec: (views: ViewInfo[]) => ViewInfo;
@@ -296,6 +303,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
296
303
  enableDefault = true,
297
304
  enableGlobal = true,
298
305
  enableSharing = true,
306
+ preserveUnsavedChanges = true,
299
307
  settleTime = 1000,
300
308
  initialViewSpec = null
301
309
  }: ViewManagerConfig) {
@@ -317,6 +325,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
317
325
  this.enableGlobal = enableGlobal;
318
326
  this.enableSharing = enableSharing;
319
327
  this.enableAutoSave = enableAutoSave;
328
+ this.preserveUnsavedChanges = preserveUnsavedChanges;
320
329
  this.settleTime = settleTime;
321
330
  this.initialViewSpec = initialViewSpec;
322
331
 
@@ -438,6 +447,10 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
438
447
  }
439
448
  }
440
449
 
450
+ noteStatePushed() {
451
+ this.lastPushed = Date.now();
452
+ }
453
+
441
454
  //------------------
442
455
  // Pinning
443
456
  //------------------
@@ -515,7 +528,9 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
515
528
  this.views = views;
516
529
  this.userPinned = state.userPinned;
517
530
  this.autoSave = state.autoSave;
518
- this.pendingValue = XH.sessionStorageService.get(pendingValueStorageKey);
531
+ if (this.preserveUnsavedChanges) {
532
+ this.pendingValue = XH.sessionStorageService.get(pendingValueStorageKey);
533
+ }
519
534
  });
520
535
 
521
536
  // 2) Initialize/choose initial view. Null is ok, and will yield default.
@@ -537,7 +552,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
537
552
  }
538
553
 
539
554
  this.addReaction(
540
- this.pendingValueReaction(),
555
+ this.preserveUnsavedChanges ? this.pendingValueReaction() : null,
541
556
  this.autoSaveReaction(),
542
557
  ...this.stateReactions(initialState)
543
558
  );
@@ -588,7 +603,6 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
588
603
  .thenAction(latest => {
589
604
  this.setAsView(latest, pendingValue?.token == token ? pendingValue : null);
590
605
  this.providers.forEach(it => it.pushStateToTarget());
591
- this.lastPushed = Date.now();
592
606
  })
593
607
  .linkTo(this.selectTask);
594
608
  }
@@ -5,6 +5,7 @@
5
5
  * Copyright © 2025 Extremely Heavy Industries Inc.
6
6
  */
7
7
 
8
+ import {Persistable} from '@xh/hoist/core';
8
9
  import {throwIf} from '@xh/hoist/utils/js';
9
10
  import {pull} from 'lodash';
10
11
  import {PersistenceProvider, PersistenceProviderConfig} from '../PersistenceProvider';
@@ -24,11 +25,17 @@ export class ViewManagerProvider<S> extends PersistenceProvider<S> {
24
25
  pushStateToTarget() {
25
26
  const state = this.read();
26
27
  this.target.setPersistableState(state ? state : this.defaultState);
28
+ this.viewManagerModel.noteStatePushed();
27
29
  }
28
30
 
29
31
  //----------------
30
32
  // Implementation
31
33
  //----------------
34
+ override bindToTarget(target: Persistable<S>) {
35
+ super.bindToTarget(target);
36
+ this.viewManagerModel.noteStatePushed();
37
+ }
38
+
32
39
  override readRaw() {
33
40
  return this.viewManagerModel.getValue();
34
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist",
3
- "version": "74.0.0-SNAPSHOT.1748340686867",
3
+ "version": "74.0.0-SNAPSHOT.1748449301934",
4
4
  "description": "Hoist add-on for building and deploying React Applications.",
5
5
  "repository": "github:xh/hoist-react",
6
6
  "homepage": "https://xh.io",