shelving 1.109.1 → 1.109.3

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/db/ItemStore.js CHANGED
@@ -27,13 +27,14 @@ export class ItemStore extends Store {
27
27
  }
28
28
  constructor(provider, collection, id) {
29
29
  const memory = getOptionalSource(CacheProvider, provider)?.memory;
30
- const time = memory ? memory.getItemTime(collection, id) : undefined;
31
- super(memory && typeof time === "number" ? memory.getItem(collection, id) : NONE, time);
30
+ const time = memory?.getItemTime(collection, id);
31
+ const value = memory && typeof time === "number" ? memory.getItem(collection, id) : NONE; // Use the value in the memory provider if it's cached, or use mark this store as loading otherwise (which will trigger `refresh()` below.
32
+ super(value, time);
32
33
  this.provider = provider;
33
34
  this.collection = collection;
34
35
  this.id = id;
35
36
  // Queue a request to refresh the value if it doesn't exist.
36
- if (this.loading)
37
+ if (typeof time !== "number")
37
38
  this.refresh();
38
39
  }
39
40
  /** Refresh this store from the source provider. */
package/db/QueryStore.js CHANGED
@@ -45,13 +45,15 @@ export class QueryStore extends Store {
45
45
  }
46
46
  constructor(provider, collection, query) {
47
47
  const memory = getOptionalSource(CacheProvider, provider)?.memory;
48
- super(memory?.getQuery(collection, query) || NONE, memory?.getQueryTime(collection, query));
48
+ const time = memory?.getQueryTime(collection, query);
49
+ const value = memory?.getQuery(collection, query) || NONE; // Always use any matching items currently in the memory store (this might update when we call `refresh()` below).
50
+ super(value, time);
49
51
  this.provider = provider;
50
52
  this.collection = collection;
51
53
  this.query = query;
52
54
  this.limit = getLimit(query) ?? Infinity;
53
55
  // Queue a request to refresh the value if it doesn't exist.
54
- if (this.loading)
56
+ if (typeof time !== "number")
55
57
  this.refresh();
56
58
  }
57
59
  /** Refresh this store from the source provider. */
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.109.1",
14
+ "version": "1.109.3",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -11,8 +11,8 @@ import { type Optional } from "../util/optional.js";
11
11
  export declare function createDataContext<T extends Database>(provider: AbstractProvider<T>): {
12
12
  readonly useItem: <K extends DataKey<T>>(collection: K, id: string) => ItemStore<T, K>;
13
13
  readonly useQuery: <K extends DataKey<T>>(collection: K, query: ItemQuery<T[K]>) => QueryStore<T, K>;
14
- readonly useOptionalItem: <K extends DataKey<T>>(collection: K, id: Optional<string>) => ItemStore<T, K> | undefined;
15
- readonly useOptionalQuery: <K extends DataKey<T>>(collection: K, query: Optional<ItemQuery<T[K]>>) => QueryStore<T, K> | undefined;
14
+ readonly useOptionalItem: <K extends DataKey<T>>(collection: Optional<K>, id: Optional<string>) => ItemStore<T, K> | undefined;
15
+ readonly useOptionalQuery: <K extends DataKey<T>>(collection: Optional<K>, query: Optional<ItemQuery<T[K]>>) => QueryStore<T, K> | undefined;
16
16
  readonly DataProvider: ({ children }: {
17
17
  children: React.ReactNode;
18
18
  }) => React.ReactElement;