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

@hey-web-components/context-protocol

v0.2.0

Published

A protocol for data passing between elements using DOM events.

Readme

Context-Protocol

This is an implementation of Context Community Protocol, which is an open protocol for data passing between elements using DOM events.

It is designed to be used with web components but can also be used for other DOM elements.

This implementation is highly inspired by @lit/context.

How to use

Create a context

First of all, a context should be created before use.

import { createContext } from "@hey-web-components/context-protocol";
const myContext = createContext<number>("my-context");

The above code creates a context with identifier "my-context", which should be unique, and the type of the context value is number.

Attch to a context root

Then we should attach the context to a context root, which should be a DOM element. The context would not go above the context root element.

import { attachContextRoot } from "@hey-web-components/context-protocol";
attachContextRoot(myContext, document.body);

The above code attaches myContext to the document body.

Provide a context

To provide a context, call the provideContext function. Any descendant elements can consume the provided context.

It takes three parameters:

  • an DOM elment to be made to the context provider
  • the context
  • more options (optional to give an initial value)

It then returns an array of two callback functions:

  • a callback for updating the context value
  • a callback to stop providing the context.
import { provideContext } from "@hey-web-components/context-protocol";
const [updateValue, stopProviding] = provideContext(el, myContext, {
  initialValue: 0,
});
setTimeout(() => {
  updateValue(1);
}, 1000);

The above code makes el to be a context provider for myContext with the initial value of 0. Then, in one secend, the context value is updated to 1.

Consume a context

To consume a context, call the consumeContext function. It allows an element to consume the context that provided by its nearest ancestor provider.

It takes three parameters:

  • an DOM element to be made to the context consumer
  • the context
  • more options (the callback function and whether to subscribe)

The callback function should takes two parameters:

  • the value
  • an callback to unsubsribe (if subscribe is true)
import { consumeContext } from "@hey-web-components/context-protocol";
const callback = (value) => {
  console.log(value);
};
consumeContext(el, myContext, { callback, subscribe: true });

The above code makes el to be a context consumer and subscribed the updates. Since it subscribes the context, the callback function may be called multiple times when the context value is changed.

Note: since this implementation uses WeakMap and WeakRef, the callback function needs to be hard-ref'ed. (If it is garbage collected, it would no longer be invoked.) For example, if use inside a custom element, the callback should be assigned to a property of the class.

Examples

Some example codes are available here.