npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

lit-ui-router-effect

v0.7.2

Published

Effect bindings for lit-ui-router: a SubscriptionRef of the route and ref-following Lit ReactiveControllers

Downloads

10,426

Readme

lit-ui-router-effect

npm version GitHub Release License: MIT Website codecov

Effect bindings for lit-ui-router: a SubscriptionRef of the route, from ui-router-effect, and ref-following Lit ReactiveControllers.

A thin wrapper on top of lit-ui-router — it registers no custom elements and adds no routing behavior. It mirrors the router's state into a SubscriptionRef and gives components a declarative, lifecycle-safe way to follow it (and any other SubscriptionRef) with automatic requestUpdate() — no manual refresh plumbing.

Features

  • routeRef(router) — a SubscriptionRef<TypedRouteSnapshot> of the current state, params, and transition; one ref (and one transition hook) per router, attached lazily on first use
  • RouterRefController — follows the route ref of the nearest <ui-router> context, requested automatically over the context-request protocol; no prop drilling and no wiring in router configuration
  • RefController — the generic primitive: selects over one or more SubscriptionRefs while the host is connected; works with any ref, not just the router's
  • Lifecycle-safe — one fiber per controller, forked in hostConnected and interrupted in hostDisconnected; the value is re-read on every (re)connect so components that re-enter the DOM (e.g. sticky states) never render stale values
  • Renders before connect — refs given directly are read at construction, so a host rendered on the server sees the same value a browser would

Installation

npm install lit-ui-router-effect ui-router-effect effect

lit-ui-router, ui-router-effect, lit, effect, and @uirouter/core are peer dependencies.

Effect 3 and 4

Both majors are supported (effect@^3.22.0 || ^4.0.2) and both are exercised in CI. The bindings' own API is identical on either. The examples below are written for Effect 4, whose Equal.equals compares plain objects structurally. On Effect 3 it compares them by reference, so wrap a selected object in Data.struct(...) for equals: Equal.equals to see two equal selections as unchanged.

Quick Start

import { html, LitElement } from 'lit';
import { Equal } from 'effect';
import { RouterRefController } from 'lit-ui-router-effect';

class AppNav extends LitElement {
  // Re-renders only when a section's visibility actually flips —
  // not on every transition. Equal.equals compares the selection
  // structurally.
  private active = new RouterRefController(
    this,
    (route) => ({
      inbox: route.includes('inbox.**'),
      contacts: route.includes('contacts.**'),
    }),
    { equals: Equal.equals },
  );

  render() {
    return html`...${this.active.value.inbox ? 'Inbox is open' : ''}...`;
  }
}

No router configuration is required: the controller discovers the router from the enclosing <ui-router> element on hostConnected, and routeRef(router) lazily attaches the ref's single transition hook on first use.

API

routeRef(router)

The SubscriptionRef<TypedRouteSnapshot> for a router — memoized, one per router instance. The first call registers one transitionService.onSuccess hook that replaces the value per successful transition. It is ui-router-effect's routeRef, re-exported, so code using either package shares one ref per router.

RouteSnapshot

A value taken once per successful transition. Every member answers for that moment, so a selector asking during a later transition gets the settled answer, not the in-flight one.

| Member | Description | | --------------------------- | ---------------------------------------------------------------------------- | | current | The current StateDeclaration (globals.current) | | params | The current RawParams (globals.params), a fresh object per transition | | transition | The transition that produced the snapshot | | includes(stateOrName, p?) | StateService.includes evaluated against the snapshot (globs like 'a.**') |

RouterRefController

A ReactiveController that follows the route ref of the host's <ui-router> context:

new RouterRefController(host, selector, options?)
  • selector: (route: TypedRouteSnapshot) => T — the selected expression; the result is exposed as .value. TypedRouteSnapshot is the snapshot routeRef holds: typed when an app or a registry fills in ui-router-effect's RouteTypes, a RouteSnapshot otherwise
  • options.router — explicit router instance, skipping context discovery; the route is then read at construction, so .value is live before the host connects. A thunk (() => UIRouter | undefined) is resolved at construction and again on every hostConnected; when it returns undefined, the controller discovers the router as if the option were omitted. Discovery subscribes, so on a page served by lit-ui-router-ssr the host follows <ui-router> from its placeholder router to the app's when hydrateRoot() sets it. A lit-ui-router that does not hand that router to subscribers leaves the host on the placeholder; hand such a host its router here or through setRouter()
  • options.onChange — effect invoked when the selected value changes (and once on every (re)connect); useful for resetting component state from route params
  • options.equals — comparer for precise, value-based change detection (Equal.equals, or any (a, b) => boolean); defaults to Object.is
  • options.initialValue — the value .value carries before the router is discovered: before hostConnected, and while a host has no router context
  • options.runtime — the runtime the subscription fiber is forked on; defaults to Effect's default runtime. It runs the controller's own fibers and provides no services: the selector stays a plain function over the snapshot. An app's ManagedRuntime<R> satisfies it because the controller requires nothing from R

controller.setRouter(router) hands the controller a router after construction, such as one that arrives as a host property. A connected host interrupts its fiber, re-seeds .value from the new router, re-forks, and updates; a disconnected one takes the router on its next hostConnected. Passing the router already followed does nothing.

RefController

The generic primitive behind RouterRefController — the same selector/options contract over any SubscriptionRefs:

import { Equal } from 'effect';
import { RefController } from 'lit-ui-router-effect';

class NavHeader extends LitElement {
  private auth = new RefController(
    this,
    [Session.user$, Session.loggedIn$],
    (user, loggedIn) => ({ user, loggedIn }),
    { equals: Equal.equals },
  );

  render() {
    const { user, loggedIn } = this.auth.value;
    // ...
  }
}

The refs are a tuple, and the selector receives their values positionally. Pass a thunk instead (() => [ref]) for refs that depend on the host's place in the DOM; it is resolved on every hostConnected, and .value carries options.initialValue until then.

ui-router-effect's pendingRef(router) and errorRef(router) are SubscriptionRefs too, so a RefController over them follows the in-flight transition and the last failed one.

Development and production builds

dist/development/index.js is published alongside dist/index.js and picked by the development export condition, which bundlers resolve automatically in development; production builds get the default. Nothing to configure. lit-ui-router ships the same split — see the Development & Production Builds guide for the mechanism and the warnings both packages carry.

The development build adds one console warning here: a RouterRefController whose host has no <ui-router> ancestor warns once, naming that host, and follows nothing — .value stays at options.initialValue, so the host renders once and never again. Wrap the subtree in <ui-router>, or hand a host outside the router's DOM its router with options.router or setRouter(). Production builds drop the warning and its message text, and lit's own production build silences it as well.

Links