@jsenv/navi 0.29.457 → 0.29.458

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.
@@ -39484,6 +39484,14 @@ const activeRouteReadsSignal = computed(() => {
39484
39484
  * params read: that address is the current one with the state set to the
39485
39485
  * popup's value (see `prefetch` on Button).
39486
39486
  * @param {object} [options]
39487
+ * @param {() => any} [options.when] - a condition on app state the action
39488
+ * asks under, read off signals like the params: falsy, it runs nothing.
39489
+ * Unlike a params function it leaves the action asking nothing of the
39490
+ * address, so a link to the route still prefetches an action without
39491
+ * params when the condition holds at that moment — a page's code only some
39492
+ * readers may download (`() => meIsAdminSignal.value`). A condition reading
39493
+ * the address belongs in the params: a link reads `when` as it is, not as
39494
+ * the address it leads to will make it.
39487
39495
  * @param {boolean} [options.prefetch=true] - `false` keeps the action from
39488
39496
  * being prerun ahead of what asks for it, when the read is not worth a
39489
39497
  * hover or a press that may not end in an opening.
@@ -39492,7 +39500,7 @@ const routeAction = (
39492
39500
  routeOrRoutes,
39493
39501
  action,
39494
39502
  paramsEffect,
39495
- { prefetch = true, ...options } = {},
39503
+ { when, prefetch = true, ...options } = {},
39496
39504
  ) => {
39497
39505
  if (typeof action === "function") {
39498
39506
  action = createAction(action);
@@ -39502,7 +39510,12 @@ const routeAction = (
39502
39510
  routes.length === 1
39503
39511
  ? routes[0].matchingSignal
39504
39512
  : anyMatchingRouteSignal(routes);
39505
- const readParams = paramsEffect || (() => true);
39513
+ const readParams = () => {
39514
+ if (when && !when()) {
39515
+ return null;
39516
+ }
39517
+ return paramsEffect ? paramsEffect() : true;
39518
+ };
39506
39519
  const readParamsAsked = () => {
39507
39520
  const matching = routeMatchingSignal.value;
39508
39521
  const params = readParams();
@@ -39538,10 +39551,13 @@ const routeAction = (
39538
39551
  for (const route of routes) {
39539
39552
  if (paramsEffect) {
39540
39553
  registerRouteStatePreload(route, (values) => {
39541
- prefetchAsIf(action, paramsEffect, values);
39554
+ prefetchAsIf(action, readParams, values);
39542
39555
  });
39543
39556
  } else {
39544
39557
  registerRoutePreload(route, () => {
39558
+ if (!untracked(readParams)) {
39559
+ return;
39560
+ }
39545
39561
  prerunAhead(action.bindParams(true));
39546
39562
  });
39547
39563
  }
@@ -39554,12 +39570,12 @@ const routeAction = (
39554
39570
  // (see readStateAsIf), prerun only when that changes them: params the state
39555
39571
  // leaves alone are the ones the action already runs on — or is meant not to,
39556
39572
  // and a prerun would retry a FAILED one behind the screen's back.
39557
- const prefetchAsIf = (action, paramsEffect, values) => {
39558
- const params = readStateAsIf(values, paramsEffect);
39573
+ const prefetchAsIf = (action, readParams, values) => {
39574
+ const params = readStateAsIf(values, readParams);
39559
39575
  if (!params) {
39560
39576
  return;
39561
39577
  }
39562
- if (compareTwoJsValues(params, untracked(paramsEffect))) {
39578
+ if (compareTwoJsValues(params, untracked(readParams))) {
39563
39579
  return;
39564
39580
  }
39565
39581
  prerunAhead(action.bindParams(params));