-
Notifications
You must be signed in to change notification settings - Fork 0
Events
double-meh ships a tiny synchronous event emitter bolted onto the io instance. It is general-purpose: you register string-keyed listeners with io.on, remove them with io.off, and dispatch with io.emit. All three are chainable and return io.
import io from 'double-meh';
const onReady = () => console.log('io is ready');
io.on('ready', onReady);
io.emit('greet', 'world'); // runs any 'greet' listeners
io.off('ready', onReady);Subscribe fn to event. The same function may be registered more than once (it will be called once per registration). Returns io, so calls chain.
io
.on('ready', () => console.log('ready'))
.on('error', err => console.error(err));Unsubscribe. Removes the first registration matching fn for event by identity — so keep a reference to the exact function you passed to on. Unknown events and unknown functions are silently ignored. Returns io.
const handler = payload => console.log(payload);
io.on('update', handler);
io.off('update', handler); // must be the same referenceDispatch event synchronously, forwarding every extra argument to each listener in registration order. Listeners run over a snapshot of the list, so a handler may safely on/off during dispatch without affecting the current pass. Returns io.
io.on('progress', (loaded, total) => {
console.log(`${loaded}/${total}`);
});
io.emit('progress', 512, 1024); // logs "512/1024"The only event the library emits on its own is 'ready'. It fires once during code-forwarding startup (installCodeForward), after any server-injected __doubleMeh prelude — queued setup callbacks, in-flight requests, and pre-arrived responses — has been drained. Use it to run code that depends on that handoff being complete.
io.on('ready', () => {
// prelude drained; safe to issue follow-up requests
io.get('/api/session');
});Beyond 'ready', the emitter is entirely yours: pick any event name and use io as a lightweight app-wide bus. double-meh never emits custom names itself, so there is no risk of collision.
io.on('auth:expired', () => io.get('/api/refresh'));
// elsewhere, e.g. from a response inspector
io.emit('auth:expired');Guides
Concepts
Services
Modules
- fetch transport
- keys & URLs
- helpers
- records
- sse
- storage backends
- compression encoders
- Service Worker integration
Cookbook