
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.
HTML5 Game Developer, Enclave Games indie studio founder, js13kGames competition creator and Gamedev.js Weekly newsletter publisher. Mozilla Tech Speaker, Gamedev.js community firestarter. Organizes meetups / workshops / hackathons in Poland, passionate about new, Open Web technologies, excited about WebXR and PWAs. Likes eating sushi and playing Neuroshima Hex.