@xh/hoist 80.0.0-SNAPSHOT.1769042542328 → 80.0.0-SNAPSHOT.1769114224366

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
@@ -36,6 +36,7 @@
36
36
  * Added `AggregationContext` as an additional argument to `CubeField.canAggregateFn`.
37
37
  * Added `filterMatchMode` option to `ColChooserModel`, allowing customizing match to `start`,
38
38
  `startWord`, or `any`.
39
+ * Added support for reconnecting a `View` to its associated `Cube`
39
40
 
40
41
  ### ⚙️ Typescript API Adjustments
41
42
 
@@ -127,6 +127,8 @@ export declare class Cube extends HoistBase {
127
127
  viewIsConnected(view: View): boolean;
128
128
  /** Cease pushing further updates to this Cube's data into a previously connected View. */
129
129
  disconnectView(view: View): void;
130
+ /** Connect a View to this Cube for live updates. */
131
+ connectView(view: View): void;
130
132
  /**
131
133
  * Populate this cube with a new dataset.
132
134
  * This method largely delegates to {@link Store.loadData} - see that method for more info.
@@ -66,11 +66,13 @@ export declare class View extends HoistBase implements FilterBindTarget, FilterV
66
66
  get isFiltered(): boolean;
67
67
  /** Stop receiving live updates into this view when the linked Cube data changes. */
68
68
  disconnect(): void;
69
+ /** Connect to the associated Cube to begin receiving live updates. */
70
+ connect(): void;
69
71
  /**
70
72
  * Change the query in some way, re-computing the data in this View to reflect the new query.
71
73
  *
72
- * @param overrides - changes to be applied to the query. May include any arguments to the query
73
- * constructor except `cube`, which cannot be changed once set via the initial query.
74
+ * @param overrides - changes to be applied to the query. If changing the `cube` and currently
75
+ * connected, then we will disconnect from the old cube and connect to the new one.
74
76
  */
75
77
  updateQuery(overrides: Partial<QueryConfig>): void;
76
78
  /** Gather all unique values for each dimension field in the query. */
package/data/cube/Cube.ts CHANGED
@@ -227,6 +227,18 @@ export class Cube extends HoistBase {
227
227
  this._connectedViews.delete(view);
228
228
  }
229
229
 
230
+ /** Connect a View to this Cube for live updates. */
231
+ connectView(view: View) {
232
+ if (this.viewIsConnected(view)) return;
233
+
234
+ this._connectedViews.add(view);
235
+
236
+ // If the view is not up-to-date with the current cube data, then reload the view
237
+ if (view.info !== this.info) {
238
+ view.noteCubeLoaded();
239
+ }
240
+ }
241
+
230
242
  //-------------------
231
243
  // Data Loading API
232
244
  //-------------------
package/data/cube/View.ts CHANGED
@@ -156,21 +156,45 @@ export class View
156
156
  this.cube.disconnectView(this);
157
157
  }
158
158
 
159
+ /** Connect to the associated Cube to begin receiving live updates. */
160
+ @action
161
+ connect() {
162
+ this.cube.connectView(this);
163
+ }
164
+
159
165
  /**
160
166
  * Change the query in some way, re-computing the data in this View to reflect the new query.
161
167
  *
162
- * @param overrides - changes to be applied to the query. May include any arguments to the query
163
- * constructor except `cube`, which cannot be changed once set via the initial query.
168
+ * @param overrides - changes to be applied to the query. If changing the `cube` and currently
169
+ * connected, then we will disconnect from the old cube and connect to the new one.
164
170
  */
165
171
  @action
166
172
  updateQuery(overrides: Partial<QueryConfig>) {
167
- throwIf(overrides.cube, 'Cannot redirect view to a different cube in updateQuery().');
168
173
  const oldQuery = this.query,
169
174
  newQuery = oldQuery.clone(overrides);
175
+
170
176
  if (oldQuery.equals(newQuery)) return;
171
177
 
172
178
  this.query = newQuery;
173
179
 
180
+ // If the cube is changing then we need to clear the row cache, and potentially disconnect
181
+ // from the old cube and connect to the new one
182
+ const {cube: oldCube} = oldQuery,
183
+ {cube: newCube} = newQuery;
184
+
185
+ if (oldCube !== newCube) {
186
+ this.info = null;
187
+ this._rowCache.clear();
188
+
189
+ if (oldCube.viewIsConnected(this)) {
190
+ oldCube.disconnectView(this);
191
+ newCube.connectView(this);
192
+
193
+ // Connecting to the new cube will have triggered a full update so we early out
194
+ return;
195
+ }
196
+ }
197
+
174
198
  // Must clear row cache if we have complex aggregates or more than filter changing.
175
199
  if (!this.aggregatorsAreSimple || !oldQuery.equalsExcludingFilter(newQuery)) {
176
200
  this._rowCache.clear();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist",
3
- "version": "80.0.0-SNAPSHOT.1769042542328",
3
+ "version": "80.0.0-SNAPSHOT.1769114224366",
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",