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.mjs
CHANGED
|
@@ -1432,32 +1432,7 @@ function useRegister(controller, store = getDefaultObjectStore()) {
|
|
|
1432
1432
|
return stored;
|
|
1433
1433
|
}
|
|
1434
1434
|
|
|
1435
|
-
|
|
1436
|
-
* React hook to subscribe to a registered controller.
|
|
1437
|
-
*
|
|
1438
|
-
* - Looks up the controller by name from the `ObjectStore` (context by default)
|
|
1439
|
-
* - Subscribes to `controller.publish()`
|
|
1440
|
-
* - Exposes `data`, `loading`, `error`, and the `controller` instance
|
|
1441
|
-
*
|
|
1442
|
-
* @param name - controller name
|
|
1443
|
-
* @param where - optional `Collection.find()` filter (string `_id` or partial)
|
|
1444
|
-
* @param options - store selection, initialise behavior, abort-on-unmount, and invalidation wiring
|
|
1445
|
-
*
|
|
1446
|
-
* When `options.withInvalidation` is true, this hook calls
|
|
1447
|
-
* `controller.invalidator.registerInvalidation()` on mount and
|
|
1448
|
-
* `controller.invalidator.unregisterInvalidation()` on unmount.
|
|
1449
|
-
*
|
|
1450
|
-
* @example
|
|
1451
|
-
* ```tsx
|
|
1452
|
-
* const { data, controller } = useController<User, "users">("users", undefined, {
|
|
1453
|
-
* withInvalidation: true,
|
|
1454
|
-
* });
|
|
1455
|
-
* return (
|
|
1456
|
-
* <button onClick={() => void controller.invalidate()}>Refresh</button>
|
|
1457
|
-
* );
|
|
1458
|
-
* ```
|
|
1459
|
-
*/
|
|
1460
|
-
function useController(name, where, options) {
|
|
1435
|
+
function useController(controllerInstance, where, options) {
|
|
1461
1436
|
var _a, _b;
|
|
1462
1437
|
const optionalStore = options === null || options === void 0 ? void 0 : options.store;
|
|
1463
1438
|
const withInvalidation = (_a = options === null || options === void 0 ? void 0 : options.withInvalidation) !== null && _a !== void 0 ? _a : true;
|
|
@@ -1469,7 +1444,12 @@ function useController(name, where, options) {
|
|
|
1469
1444
|
if (!store) {
|
|
1470
1445
|
throw Error("Store is not defined");
|
|
1471
1446
|
}
|
|
1472
|
-
const controller = useMemo(() =>
|
|
1447
|
+
const controller = useMemo(() => {
|
|
1448
|
+
if (!store.get(controllerInstance.name)) {
|
|
1449
|
+
store.register(controllerInstance);
|
|
1450
|
+
}
|
|
1451
|
+
return store.get(controllerInstance.name);
|
|
1452
|
+
}, [controllerInstance, store]);
|
|
1473
1453
|
useEffect(() => {
|
|
1474
1454
|
const callback = () => {
|
|
1475
1455
|
var _a;
|
|
@@ -1483,7 +1463,7 @@ function useController(name, where, options) {
|
|
|
1483
1463
|
if (withInvalidation) {
|
|
1484
1464
|
controller.invalidator.registerInvalidation();
|
|
1485
1465
|
}
|
|
1486
|
-
void store.initialiseOnce(name, where);
|
|
1466
|
+
void store.initialiseOnce(controller.name, where);
|
|
1487
1467
|
return () => {
|
|
1488
1468
|
controller.abort();
|
|
1489
1469
|
cleanup();
|