live-cache 0.2.5 → 0.2.7
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/dist/core/Collection.d.ts +2 -0
- package/dist/index.cjs +11 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +11 -25
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +11 -25
- package/dist/index.umd.js.map +1 -1
- package/dist/react/useController.d.ts +3 -1
- package/package.json +1 -1
|
@@ -15,11 +15,13 @@ export default class Collection<TVariable, TName extends string> {
|
|
|
15
15
|
private dataMap;
|
|
16
16
|
private indexes;
|
|
17
17
|
private counter;
|
|
18
|
+
lastUpdated: Date;
|
|
18
19
|
constructor(name: TName);
|
|
19
20
|
/**
|
|
20
21
|
* Clear all in-memory documents and indexes.
|
|
21
22
|
*/
|
|
22
23
|
clear(): void;
|
|
24
|
+
updateLastUpdated(): void;
|
|
23
25
|
/**
|
|
24
26
|
* Add a document to all relevant indexes
|
|
25
27
|
*/
|
package/dist/index.cjs
CHANGED
|
@@ -133,6 +133,7 @@ class Collection {
|
|
|
133
133
|
this.dataMap = {};
|
|
134
134
|
this.indexes = {};
|
|
135
135
|
this.counter = 0;
|
|
136
|
+
this.lastUpdated = new Date();
|
|
136
137
|
}
|
|
137
138
|
/**
|
|
138
139
|
* Clear all in-memory documents and indexes.
|
|
@@ -141,6 +142,10 @@ class Collection {
|
|
|
141
142
|
this.dataMap = {};
|
|
142
143
|
this.indexes = {};
|
|
143
144
|
this.counter = 0;
|
|
145
|
+
this.lastUpdated = new Date();
|
|
146
|
+
}
|
|
147
|
+
updateLastUpdated() {
|
|
148
|
+
this.lastUpdated = new Date();
|
|
144
149
|
}
|
|
145
150
|
/**
|
|
146
151
|
* Add a document to all relevant indexes
|
|
@@ -168,6 +173,7 @@ class Collection {
|
|
|
168
173
|
if (!this.indexes[fullIndexKey].includes(doc._id)) {
|
|
169
174
|
this.indexes[fullIndexKey].push(doc._id);
|
|
170
175
|
}
|
|
176
|
+
this.updateLastUpdated();
|
|
171
177
|
}
|
|
172
178
|
/**
|
|
173
179
|
* Remove a document from all indexes
|
|
@@ -195,6 +201,7 @@ class Collection {
|
|
|
195
201
|
delete this.indexes[fullIndexKey];
|
|
196
202
|
}
|
|
197
203
|
}
|
|
204
|
+
this.updateLastUpdated();
|
|
198
205
|
}
|
|
199
206
|
/**
|
|
200
207
|
* Find a single document by _id or by matching conditions (optimized with indexes)
|
|
@@ -263,6 +270,7 @@ class Collection {
|
|
|
263
270
|
this.dataMap[doc._id] = doc;
|
|
264
271
|
// Add to indexes
|
|
265
272
|
this.addToIndexes(doc);
|
|
273
|
+
this.updateLastUpdated();
|
|
266
274
|
return doc;
|
|
267
275
|
}
|
|
268
276
|
/**
|
|
@@ -277,6 +285,7 @@ class Collection {
|
|
|
277
285
|
this.removeFromIndexes(doc);
|
|
278
286
|
// Remove from dataMap
|
|
279
287
|
delete this.dataMap[doc._id];
|
|
288
|
+
this.updateLastUpdated();
|
|
280
289
|
return true;
|
|
281
290
|
}
|
|
282
291
|
/**
|
|
@@ -301,6 +310,7 @@ class Collection {
|
|
|
301
310
|
this.removeFromIndexes(doc);
|
|
302
311
|
doc.updateData(update);
|
|
303
312
|
this.addToIndexes(doc);
|
|
313
|
+
this.updateLastUpdated();
|
|
304
314
|
return doc;
|
|
305
315
|
}
|
|
306
316
|
/**
|
|
@@ -317,6 +327,7 @@ class Collection {
|
|
|
317
327
|
this.addToIndexes(doc);
|
|
318
328
|
insertedDocs.push(doc);
|
|
319
329
|
}
|
|
330
|
+
this.updateLastUpdated();
|
|
320
331
|
return insertedDocs;
|
|
321
332
|
}
|
|
322
333
|
/**
|
|
@@ -1436,31 +1447,6 @@ function useRegister(controller, store = getDefaultObjectStore()) {
|
|
|
1436
1447
|
return stored;
|
|
1437
1448
|
}
|
|
1438
1449
|
|
|
1439
|
-
/**
|
|
1440
|
-
* React hook to subscribe to a registered controller.
|
|
1441
|
-
*
|
|
1442
|
-
* - Looks up the controller by name from the `ObjectStore` (context by default)
|
|
1443
|
-
* - Subscribes to `controller.publish()`
|
|
1444
|
-
* - Exposes `data`, `loading`, `error`, and the `controller` instance
|
|
1445
|
-
*
|
|
1446
|
-
* @param name - controller name
|
|
1447
|
-
* @param where - optional `Collection.find()` filter (string `_id` or partial)
|
|
1448
|
-
* @param options - store selection, initialise behavior, abort-on-unmount, and invalidation wiring
|
|
1449
|
-
*
|
|
1450
|
-
* When `options.withInvalidation` is true, this hook calls
|
|
1451
|
-
* `controller.invalidator.registerInvalidation()` on mount and
|
|
1452
|
-
* `controller.invalidator.unregisterInvalidation()` on unmount.
|
|
1453
|
-
*
|
|
1454
|
-
* @example
|
|
1455
|
-
* ```tsx
|
|
1456
|
-
* const { data, controller } = useController<User, "users">("users", undefined, {
|
|
1457
|
-
* withInvalidation: true,
|
|
1458
|
-
* });
|
|
1459
|
-
* return (
|
|
1460
|
-
* <button onClick={() => void controller.invalidate()}>Refresh</button>
|
|
1461
|
-
* );
|
|
1462
|
-
* ```
|
|
1463
|
-
*/
|
|
1464
1450
|
function useController(controllerInstance, where, options) {
|
|
1465
1451
|
var _a, _b;
|
|
1466
1452
|
const optionalStore = options === null || options === void 0 ? void 0 : options.store;
|