🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

overhead-js

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

overhead-js

Tiny framework-agnostic pubsub core for modern JavaScript and TypeScript.

latest
npmnpm
Version
1.0.0
Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

overhead

Tiny, framework-agnostic pubsub core with a TypeScript-first API.

Use the core package anywhere JavaScript runs, and add the optional React package only when you want hooks and provider-based integration in React apps.

Install

npm install overhead-js

Usage (ESM/CJS)

import { createPubSub } from 'overhead-js';

type Events = {
  scoreUpdated: { home: number; away: number };
};

const bus = createPubSub<Events>();

const unsubscribe = bus.subscribe('scoreUpdated', (payload) => {
  console.log(payload.home, payload.away);
});

bus.publish('scoreUpdated', { home: 1, away: 0 });
unsubscribe();

React Adapter

import { createPubSub } from 'overhead-js';
import {
  OverheadProvider,
  usePublish,
  useSubscription,
} from 'overhead-js/react';

type Events = {
  toast: { message: string };
};

const testBus = createPubSub<Events>();

function ToastListener() {
  useSubscription<Events, 'toast'>('toast', (payload) => {
    console.log(payload.message);
  });

  return null;
}

function ToastButton() {
  const publishToast = usePublish<Events, 'toast'>('toast');

  return (
    <button onClick={() => publishToast({ message: 'Saved' })}>
      Publish toast
    </button>
  );
}

export function App() {
  return (
    <OverheadProvider bus={testBus}>
      <ToastListener />
      <ToastButton />
    </OverheadProvider>
  );
}

Use bus injection on OverheadProvider when you want a scoped event bus in tests.

Usage (Script Tag)

<script src="https://unpkg.com/overhead-js/dist/index.global.js"></script>
<script>
  const bus = window.Overhead.createPubSub();

  const unsubscribe = bus.subscribe('ping', (payload) => {
    console.log('ping payload:', payload);
  });

  bus.publish('ping', { ok: true });
  unsubscribe();
</script>

API

  • createPubSub()
  • subscribe(topic, handler)
  • publish(topic, payload)
  • clear(topic?)
  • size(topic?)
  • OverheadProvider
  • usePubSub()
  • usePublish(topic)
  • useSubscription(topic, handler)

Scripts

npm run test
npm run build
npm run typecheck

Keywords

pubsub

FAQs

Package last updated on 16 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts