Motivation
The Pub/Sub pattern is needed every now and then and this library is a no dependency, tiny and typesafe solution.
Get started
Install
npm install --save lightcast
yarn add lightcast
Use
import { createPubSub } from 'lightcast'
const pubSub = createPubSub<string>()
pubSub.subscribe(console.log)
pubSub.subscribe(console.log)
pubSub.dispatch('hello world')
Working with groups
const loader = createLoader({
onProgress: (progress) => console.log(progress),
onComplete: () => console.log('done'),
})
import { createPubSub } from 'lightcast'
const pubSub = {
onProgress: createPubSub<number>(),
onComplete: createPubSub<void>(),
}
const loader = createLoader({
onProgress: pubSub.onProgress.dispatch,
onComplete: pubSub.onComplete.dispatch,
})
import { createPubSub, groupByAction } from 'lightcast'
const pubSub = groupByAction({
onProgress: createPubSub<number>(),
onComplete: createPubSub<void>(),
})
const loader = createLoader({
...pubSub.dispatch,
})