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

deep-context-stores

v0.0.7

Published

Creates a new deep context store for managing scoped state and context propagation.

Readme

Deep-Context-Stores

Creates a new deep context store for managing scoped state and context propagation.

createDeepStore

1. With-Store Mode

createDeepStore<T extends Record<string, any>>(
  initialValue: T
): { withStore: <U>(callback: () => U) => U }
  • initialValue: The initial state for the store (object).
  • Returns: An object with a withStore method. Use withStore(func) to run a callback with the store context active.

Example

type Store = { data: string };

const store = createDeepStore({ data: "foo" });
store.withStore(() => {
  console.log(getDeepStore<Store>().data); // "food"
});

1. Factory Mode

createDeepStore<T extends Record<string, any>, R extends object>(
  initialValue: T,
  factory: () => R
): R
  • initialValue: The initial state for the store (object).
  • factory: A function that will be called with the store context active. Use getDeepStore inside the factory to access the current store.
  • Returns: The result of the factory, with all returned objects and functions deeply bound to the store context.

Example

type Store = { data: string };

function clientFactory() {
  const store = getDeepStore<Store>();
  return {
    data: store.data,
    nested: () => `nested ${getDeepStore<Store>().data}`,
  };
}

const client = createDeepStore({ data: "bar" }, clientFactory);
console.log(client.data); // bar
console.log(client.nested()); // bar

getDeepStore

Retrieves the current active store context within the current execution scope.

getDeepStore<T extends Record<string, any>>(): StoreContext<T>
  • Returns: The current store context object, including all properties from your initial value and an instanceId string.
  • Throws: If called outside of a store context, throws an error.

Use this function inside a factory or within a withStore callback to access the current store’s state.

Example

type Store = { data: string };

const store = createDeepStore({ data: "foo" });
store.withStore(() => {
  const ctx = getDeepStore<Store>();
  console.log(ctx.data); // "foo"
});

setDeepStore

Updates the current store state within the active context.

setDeepStore<T extends Record<string, any>>(
  valueOrUpdater: Partial<T> | ((state: T) => Partial<T> | T) | T
): void
  • valueOrUpdater:
    • An object with properties to merge into the current state,
    • or a function that receives the current state and returns a partial or new state,
    • or a new state object to replace the current state.

Example

type Store = { data: string };

const store = createDeepStore<Store>({ data: "foo" });
store.withStore(() => {
  setDeepStore<Store>({ data: "bar" });
  setDeepStore<Store>((state) => ({ data: state.data + "!" }));
});

useDeepStore

A convenience hook that returns the current store state and a setter function, similar to React's useState.

useDeepStore<T extends Record<string, any>>(): [
  T,
  (valueOrUpdater: Partial<T> | ((state: T) => Partial<T> | T) | T) => void
]
  • Returns:
    • The current store state
    • A setter function to update the state (same signature as setDeepStore)

Example

type Store = { data: string };

const store = createDeepStore<Store>({ data: "foo" });
store.withStore(() => {
  const [state, setState] = useDeepStore<Store>();
  console.log(state.data); // "foo"
  setState({ data: "baz" });
  setState((s) => ({ data: s.data + "!" }));
});