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

@real-router/sources

v0.3.0

Published

Framework-agnostic subscription layer for Real-Router state

Downloads

1,352

Readme

@real-router/sources

npm npm downloads bundle size License: MIT

Framework-agnostic subscription layer for Real-Router. Reactive primitives compatible with useSyncExternalStore and vanilla JS.

Used internally by @real-router/react. Use this package directly when building integrations for other frameworks or vanilla JS applications.

Installation

npm install @real-router/sources

Peer dependency: @real-router/core

Quick Start

import { createRouter } from "@real-router/core";
import { createRouteSource } from "@real-router/sources";

const router = createRouter([
  { name: "home", path: "/" },
  { name: "users", path: "/users/:id" },
]);

await router.start("/");

const source = createRouteSource(router);
const unsubscribe = source.subscribe(() => {
  console.log("Route:", source.getSnapshot().route?.name);
});

Source Factories

| Factory | Snapshot | Updates when | | ------------------------------------------------------- | ----------------------------------------- | --------------------------------------------------- | | createRouteSource(router) | { route, previousRoute } | Every navigation | | createRouteNodeSource(router, node) | { route, previousRoute } | Only when node activates/deactivates | | createActiveRouteSource(router, name, params?, opts?) | boolean | Route active status changes | | createTransitionSource(router) | { isTransitioning, toRoute, fromRoute } | Transition start/end/cancel/error | | createErrorSource(router) | { error, toRoute, fromRoute, version } | Navigation error (guard rejection, route not found) |

All factories return a RouterSource<T>:

interface RouterSource<T> {
  subscribe(listener: () => void): () => void; // useSyncExternalStore-compatible
  getSnapshot(): T; // current value, synchronous
  destroy(): void; // teardown, remove router subscription
}

Lazy vs Eager Subscription

  • createRouteSource, createRouteNodeSource, createActiveRouteSourcelazy: subscribe to the router on first listener, unsubscribe when all removed
  • createTransitionSourceeager: subscribes immediately (needs to track TRANSITION_START)
  • createErrorSourceeager: subscribes immediately (needs to track TRANSITION_ERROR)

createActiveRouteSource Options

const source = createActiveRouteSource(router, "users", undefined, {
  strict: false, // default: false — match descendants too
  ignoreQueryParams: true, // default: true
});

Usage Examples

With React (useSyncExternalStore)

import { useSyncExternalStore } from "react";
import { createRouteSource } from "@real-router/sources";

const source = createRouteSource(router);

function CurrentRoute() {
  const { route } = useSyncExternalStore(source.subscribe, source.getSnapshot);
  return <p>Current route: {route?.name}</p>;
}

With Vanilla JS

import { createRouteNodeSource } from "@real-router/sources";

// Only fires when navigating within the "users" subtree
const source = createRouteNodeSource(router, "users");

const unsubscribe = source.subscribe(() => {
  const { route } = source.getSnapshot();
  console.log("Users section:", route?.name);
});

unsubscribe(); // automatically unsubscribes from router

Transition Tracking

import { createTransitionSource } from "@real-router/sources";

const source = createTransitionSource(router);

source.subscribe(() => {
  const { isTransitioning, toRoute, fromRoute } = source.getSnapshot();
  if (isTransitioning) {
    showSpinner();
  } else {
    hideSpinner();
  }
});

Error Tracking

import { createErrorSource } from "@real-router/sources";

const source = createErrorSource(router);

source.subscribe(() => {
  const { error, toRoute } = source.getSnapshot();
  if (error) {
    console.error(`Navigation to ${toRoute?.name} failed: ${error.code}`);
  }
});

Documentation

Full documentation: Wiki — sources

Related Packages

| Package | Description | | ---------------------------------------------------------------------- | ------------------------------------------- | | @real-router/core | Core router (required dependency) | | @real-router/react | React integration (uses sources internally) | | @real-router/rx | Observable API (state$, events$) |

Contributing

See contributing guidelines for development setup and PR process.

License

MIT © Oleg Ivanov