@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.
@@ -38488,6 +38488,14 @@ const activeRouteReadsSignal = computed(() => {
38488
38488
  * params read: that address is the current one with the state set to the
38489
38489
  * popup's value (see `prefetch` on Button).
38490
38490
  * @param {object} [options]
38491
+ * @param {() => any} [options.when] - a condition on app state the action
38492
+ * asks under, read off signals like the params: falsy, it runs nothing.
38493
+ * Unlike a params function it leaves the action asking nothing of the
38494
+ * address, so a link to the route still prefetches an action without
38495
+ * params when the condition holds at that moment — a page's code only some
38496
+ * readers may download (`() => meIsAdminSignal.value`). A condition reading
38497
+ * the address belongs in the params: a link reads `when` as it is, not as
38498
+ * the address it leads to will make it.
38491
38499
  * @param {boolean} [options.prefetch=true] - `false` keeps the action from
38492
38500
  * being prerun ahead of what asks for it, when the read is not worth a
38493
38501
  * hover or a press that may not end in an opening.
@@ -38496,7 +38504,7 @@ const routeAction = (
38496
38504
  routeOrRoutes,
38497
38505
  action,
38498
38506
  paramsEffect,
38499
- { prefetch = true, ...options } = {},
38507
+ { when, prefetch = true, ...options } = {},
38500
38508
  ) => {
38501
38509
  if (typeof action === "function") {
38502
38510
  action = createAction(action);
@@ -38506,7 +38514,12 @@ const routeAction = (
38506
38514
  routes.length === 1
38507
38515
  ? routes[0].matchingSignal
38508
38516
  : anyMatchingRouteSignal(routes);
38509
- const readParams = paramsEffect || (() => true);
38517
+ const readParams = () => {
38518
+ if (when && !when()) {
38519
+ return null;
38520
+ }
38521
+ return paramsEffect ? paramsEffect() : true;
38522
+ };
38510
38523
  const readParamsAsked = () => {
38511
38524
  const matching = routeMatchingSignal.value;
38512
38525
  const params = readParams();
@@ -38542,10 +38555,13 @@ const routeAction = (
38542
38555
  for (const route of routes) {
38543
38556
  if (paramsEffect) {
38544
38557
  registerRouteStatePreload(route, (values) => {
38545
- prefetchAsIf(action, paramsEffect, values);
38558
+ prefetchAsIf(action, readParams, values);
38546
38559
  });
38547
38560
  } else {
38548
38561
  registerRoutePreload(route, () => {
38562
+ if (!untracked(readParams)) {
38563
+ return;
38564
+ }
38549
38565
  prerunAhead(action.bindParams(true));
38550
38566
  });
38551
38567
  }
@@ -38558,12 +38574,12 @@ const routeAction = (
38558
38574
  // (see readStateAsIf), prerun only when that changes them: params the state
38559
38575
  // leaves alone are the ones the action already runs on — or is meant not to,
38560
38576
  // and a prerun would retry a FAILED one behind the screen's back.
38561
- const prefetchAsIf = (action, paramsEffect, values) => {
38562
- const params = readStateAsIf(values, paramsEffect);
38577
+ const prefetchAsIf = (action, readParams, values) => {
38578
+ const params = readStateAsIf(values, readParams);
38563
38579
  if (!params) {
38564
38580
  return;
38565
38581
  }
38566
- if (compareTwoJsValues(params, untracked(paramsEffect))) {
38582
+ if (compareTwoJsValues(params, untracked(readParams))) {
38567
38583
  return;
38568
38584
  }
38569
38585
  prerunAhead(action.bindParams(params));