live-cache 0.2.4 → 0.2.6
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/index.cjs +8 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +8 -28
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +8 -28
- package/dist/index.umd.js.map +1 -1
- package/dist/react/useController.d.ts +5 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1436,32 +1436,7 @@ function useRegister(controller, store = getDefaultObjectStore()) {
|
|
|
1436
1436
|
return stored;
|
|
1437
1437
|
}
|
|
1438
1438
|
|
|
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
|
-
function useController(name, where, options) {
|
|
1439
|
+
function useController(controllerInstance, where, options) {
|
|
1465
1440
|
var _a, _b;
|
|
1466
1441
|
const optionalStore = options === null || options === void 0 ? void 0 : options.store;
|
|
1467
1442
|
const withInvalidation = (_a = options === null || options === void 0 ? void 0 : options.withInvalidation) !== null && _a !== void 0 ? _a : true;
|
|
@@ -1473,7 +1448,12 @@ function useController(name, where, options) {
|
|
|
1473
1448
|
if (!store) {
|
|
1474
1449
|
throw Error("Store is not defined");
|
|
1475
1450
|
}
|
|
1476
|
-
const controller = React.useMemo(() =>
|
|
1451
|
+
const controller = React.useMemo(() => {
|
|
1452
|
+
if (!store.get(controllerInstance.name)) {
|
|
1453
|
+
store.register(controllerInstance);
|
|
1454
|
+
}
|
|
1455
|
+
return store.get(controllerInstance.name);
|
|
1456
|
+
}, [controllerInstance, store]);
|
|
1477
1457
|
React.useEffect(() => {
|
|
1478
1458
|
const callback = () => {
|
|
1479
1459
|
var _a;
|
|
@@ -1487,7 +1467,7 @@ function useController(name, where, options) {
|
|
|
1487
1467
|
if (withInvalidation) {
|
|
1488
1468
|
controller.invalidator.registerInvalidation();
|
|
1489
1469
|
}
|
|
1490
|
-
void store.initialiseOnce(name, where);
|
|
1470
|
+
void store.initialiseOnce(controller.name, where);
|
|
1491
1471
|
return () => {
|
|
1492
1472
|
controller.abort();
|
|
1493
1473
|
cleanup();
|