@jsenv/navi 0.29.415 → 0.29.416

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.
@@ -23629,6 +23629,21 @@ ${[idKey, ...uniqueKeys].join(", ")}`,
23629
23629
  }
23630
23630
  return result;
23631
23631
  };
23632
+ // A computed of the row with this id, one per id: what a render reads to
23633
+ // follow that row and no other. An upsert replaces only the items it changes
23634
+ // (see assign below), so a row nobody wrote keeps its object, and its
23635
+ // computed stays still while the rest of the store moves — read through
23636
+ // `select`, a render follows the whole store. Kept as long as the store,
23637
+ // like the rows it holds.
23638
+ const itemSignalById = new Map();
23639
+ const itemSignalForId = (id) => {
23640
+ let itemSignal = itemSignalById.get(id);
23641
+ if (!itemSignal) {
23642
+ itemSignal = computed(() => idMapSignal.value.get(id));
23643
+ itemSignalById.set(id, itemSignal);
23644
+ }
23645
+ return itemSignal;
23646
+ };
23632
23647
  const upsert = (...args) => {
23633
23648
  const mutationsMap = new Map(); // Map<itemId, propertyMutations>
23634
23649
  const triggerPropertyMutations = () => {
@@ -24019,6 +24034,7 @@ ${[idKey, ...uniqueKeys].join(", ")}`,
24019
24034
  arraySignal,
24020
24035
  select,
24021
24036
  selectAll,
24037
+ itemSignalForId,
24022
24038
  upsert,
24023
24039
  drop,
24024
24040
 
@@ -25184,12 +25200,34 @@ const createResource = (
25184
25200
  idKey,
25185
25201
  uniqueKeys,
25186
25202
 
25187
- // Reactive reads, not hooks: they subscribe the render that calls them to
25188
- // the store's array signal. Nothing hook-shaped inside, so a loop or a
25189
- // condition is fine. `useAllByIds` skips the ids the store does not hold.
25203
+ // Reactive reads, not hooks: nothing hook-shaped inside, so a loop or a
25204
+ // condition is fine. Each subscribes the render that calls it to what it
25205
+ // returns: the rows asked for, each through a computed of that row (see
25206
+ // itemSignalForId in array_signal_store.js), or the whole store for
25207
+ // `useArray` — a card reading its own row stays still while the page next
25208
+ // to it loads rows of its own. `useAllByIds` skips the ids the store does
25209
+ // not hold.
25190
25210
  useArray: () => store.arraySignal.value,
25191
- useById: (id) => store.select(idKey, id),
25192
- useAllByIds: (idArray) => store.selectAll(idArray),
25211
+ useById: (id) => store.itemSignalForId(id).value,
25212
+ useAllByIds: (idArray) => {
25213
+ const items = [];
25214
+ for (const idOrProps of idArray) {
25215
+ let id = idOrProps;
25216
+ if (isProps(idOrProps) && !Object.hasOwn(idOrProps, idKey)) {
25217
+ // Named by a unique key: which row that is can only be read off
25218
+ // the whole store.
25219
+ const item = store.select(idOrProps);
25220
+ id = item ? item[idKey] : undefined;
25221
+ } else if (isProps(idOrProps)) {
25222
+ id = idOrProps[idKey];
25223
+ }
25224
+ const item = store.itemSignalForId(id).value;
25225
+ if (item) {
25226
+ items.push(item);
25227
+ }
25228
+ }
25229
+ return items;
25230
+ },
25193
25231
 
25194
25232
  withParams: undefined,
25195
25233
  one: undefined,