Pico-PubSub – the smallest PubSub library

Hassan Shaikley created Pico-PubSub, the smallest PubSub library possible. With zero dependencies and only 149 bytes of code it beats the competition, both Tiny-PubSub and Nano-PubSub.

PubSub is a pattern I really like, but I have to be careful when pulling in dependencies that are too big. In the context of js13kGames that means almost any dependency.

Here’s how you can use it after installing it via npm with npm install pico-pubsub:

import "pico-pubsub"

const unsub = sub('jump', function (anything) {
  console.log("someone jumped - " + anything.detail)
});

pub('jump', "a_user_id")
>> "someone jumped - a_user_id"

unsub()

pub('jump', "another_user_id")
>> Nothing happens now

The author wrote a short blog post about it as well.

If publish and subscribe are the only features you need, then this version of PubSub is the one you should definitely go for – especially if you’re aiming to participate in the js13kGames competition where every byte counts.

No Comments

Leave a Reply

Gamedev.js Jam 2025
Gamedev.js Survey 2024 Report
Gamedev.js Shop
Gamedev.js Discord

Follow us

Gamedev.js Weekly newsletter

Or visit gamedevjsweekly.com directly.

Websites worth visiting

Log in

Forgot password?

Already registered? Log in


Register

Forgot password?