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

@aktopia/interphase

v0.3.0

Published

Reactive state for React. Sync and async through one interface.

Readme

interphase

Reactive state for React. Sync and async through one interface.

Motive

State in UI apps fractures into two worlds: local state is immediate, remote state drags in loading flags, error branches, and conditional rendering. Components end up shaped by how data arrives rather than what they display.

interphase collapses that distinction. One hook — useSub — reads any subscription. Sync subscriptions resolve from Zustand state. Async subscriptions resolve through TanStack Query with Suspense. Components don't know and don't care which is which.

suspensify wires async subscriptions to React Suspense so fallback UI is declarative, not procedural.

Install

npm install @aktopia/interphase

Package: @aktopia/interphase

Peer dependencies: react, zustand, @tanstack/react-query. Direct dependency (bundled): immer.

Quick start

import { createRegistry, createStore, suspensify, type Event, type Sub } from '@aktopia/interphase';

type Todo = { id: string; text: string; done: boolean };
type SortBy = 'newest' | 'oldest' | 'alphabetical';

type State = {
  sortBy: SortBy;
};

type Subs = {
  'todo/sort-by': Sub<{}, SortBy>;
  'todo/items': Sub<{ sortBy: SortBy }, Todo[]>;
};

type Events = {
  'todo/create': Event<{ text: string }>;
  'todo/toggle': Event<{ id: string }>;
  'todo.sort-by/set': Event<{ value: SortBy }>;
};

const registry = createRegistry<State, Subs, Events>();
const { sub, asyncSub, event } = registry;

sub('todo/sort-by', ({ state }) => state.sortBy);

// Async subscription: backed by TanStack Query + Suspense
asyncSub('todo/items', async ({ params }) => {
  const res = await fetch(`/api/todos?sort=${params.sortBy}`);
  return res.json();
});

event('todo/create', async ({ params, invalidateAsyncSub, fetchSub }) => {
  const sortBy = fetchSub('todo/sort-by');
  await fetch('/api/todos', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ text: params.text }),
  });
  await invalidateAsyncSub(['todo/items', { sortBy }]);
});

event('todo/toggle', async ({ params, invalidateAsyncSub, fetchSub }) => {
  const sortBy = fetchSub('todo/sort-by');
  await fetch(`/api/todos/${params.id}/toggle`, { method: 'POST' });
  await invalidateAsyncSub(['todo/items', { sortBy }]);
});

event('todo.sort-by/set', ({ params, setState }) => {
  setState((state) => {
    state.sortBy = params.value;
  });
});

const store = createStore<State, Subs, Events>({
  registry,
  slices: [() => ({ sortBy: 'newest' })],
});

export const { StoreProvider, useSub, useEvent } = store;
const TodoList = suspensify(function TodoList() {
  const sortBy = useSub('todo/sort-by');             // sync
  const todos = useSub('todo/items', { sortBy });  // async, suspends until resolved
  const create = useEvent('todo/create');
  const toggle = useEvent('todo/toggle');
  const setSort = useEvent('todo.sort-by/set');

  return (
    <div>
      <select value={sortBy} onChange={(e) => setSort({ value: e.target.value as SortBy })}>
        <option value="newest">Newest</option>
        <option value="oldest">Oldest</option>
        <option value="alphabetical">A-Z</option>
      </select>
      <button onClick={() => create({ text: 'New task' })}>Add</button>
      <ul>
        {todos.map((t) => (
          <li key={t.id} onClick={() => toggle({ id: t.id })}>
            {t.done ? '[x]' : '[ ]'} {t.text}
          </li>
        ))}
      </ul>
    </div>
  );
});

function App() {
  return (
    <StoreProvider>
      <TodoList fallback={<p>Loading todos...</p>} />
    </StoreProvider>
  );
}

API reference

createRegistry<State, Subs, Events>()

Creates a registry that collects subscription and event definitions. Returns { sub, asyncSub, event } and internal maps consumed by createStore.

const registry = createRegistry<State, Subs, Events>();
const { sub, asyncSub, event } = registry;

sub(id, resolver)

Registers a sync subscription. The resolver receives { state, params } and returns the derived value.

sub('todo/sort-by', ({ state }) => state.sortBy);

asyncSub(id, resolver)

Registers an async subscription. The resolver returns a Promise. Async subscriptions are backed by TanStack Query and integrate with React Suspense.

asyncSub('todo/items', async ({ params }) => {
  const res = await fetch(`/api/todos?sort=${params.sortBy}`);
  return res.json();
});

event(id, handler)

Registers an event handler. The handler receives { setState, getState, fetchSub, params, dispatchEvent, invalidateAsyncSub, invalidateAsyncSubs, replaceAsyncSub, replaceAsyncSubs }.

setState uses immer. Mutate the draft directly.

fetchSub(id, params?) reads the current value of a subscription.

dispatchEvent(id, params?) runs another event from inside the current event handler.

event('todo.sort-by/set', ({ params, setState }) => {
  setState((state) => {
    state.sortBy = params.value;
  });
});

Event handlers can invalidate async subscriptions to trigger a refetch:

event('todo/create', async ({ params, invalidateAsyncSub, fetchSub }) => {
  const sortBy = fetchSub('todo/sort-by');
  await fetch('/api/todos', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ text: params.text }),
  });
  await invalidateAsyncSub(['todo/items', { sortBy }]);
});

Event handlers can compose other events:

event('todo/toggle-twice', ({ params, dispatchEvent }) => {
  dispatchEvent('todo/toggle', { id: params.id });
  dispatchEvent('todo/toggle', { id: params.id });
});

createStore({ registry, slices })

Creates the store from a registry and initial state slices. Returns { StoreProvider, useSub, useEvent, useBoundEvent }.

Each slice is a function returning a partial state object. Slices are merged to form the initial state.

const store = createStore<State, Subs, Events>({
  registry,
  slices: [
    () => ({ todos: [] }),
  ],
});

export const { StoreProvider, useSub, useEvent, useBoundEvent } = store;

useSub(id, params?)

One hook for all subscriptions — sync or async.

const sortBy = useSub('todo/sort-by');             // sync
const todos = useSub('todo/items', { sortBy });  // async (suspends)

useEvent(id)

Returns a stable dispatcher function for the given event.

const create = useEvent('todo/create');
// ...
<button onClick={() => create({ text: 'New task' })}>Add</button>

useBoundEvent(id, params)

Returns a memoized zero-arg callback. Useful for handlers with fixed params — no allocation on re-render.

const addDefault = useBoundEvent('todo/create', { text: 'Default task' });
// ...
<button onClick={addDefault}>Add default</button>

suspensify(Component)

HOC that wraps a component in <Suspense>. Accepts an optional fallback prop.

Without suspensify:

<Suspense fallback={<p>Loading...</p>}>
  <TodoList />
</Suspense>

With suspensify:

const TodoList = suspensify(function TodoList() {
  const todos = useSub('todo/items', { sortBy });
  // ...
});

<TodoList fallback={<p>Loading...</p>} />

remoteSub pattern

Thin wrapper over asyncSub that wires a subscription directly to an HTTP endpoint:

const remoteSub = <T extends keyof Subs>(id: T) => {
  asyncSub(id, async ({ params }) => {
    const res = await fetch(`/api/${String(id)}`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(params),
    });
    return res.json();
  });
};

One line per subscription:

remoteSub('todo/items');

Examples

examples/todos — a Vite app that demonstrates the full API.

cd examples/todos
npm install
npm run dev

License

MIT