@websqnl/event-flow
v0.0.1
Published
## Install
Readme
Event Flow
Install
npm
npm install @websqnl/event-flowpnpm
pnpm add @websqnl/event-flowyarn
yarn add @websqnl/event-flowHow to use
The StateEventMap
Create an interface named StateEventMap, the name must be exactly as described, it will contain keys and values where each key informs its respective type for the value.
interface StateEventMap {
ping: Date
}The listeners
import {createListener} from '@websqnl/event-flow'
export const onPing = createListener('ping')then
import {onPing} from './targets'
onPing((value) => {
console.log(`ping`, value)
})The events
import {createEvent} from '@websqnl/event-flow'
export const ping = createEvent('ping')then use the dispatch function + the previously created event
import {dispatch} from '@websqnl/event-flow'
import {ping} from './events'
const button = document.createElement('button')
button.textContent = 'Ping'
button.onclick = () => dispatch(ping(new Date()))or, dispatch method of event state
import {ping} from './events'
const button = document.createElement('button')
button.textContent = 'Ping'
button.onclick = () => ping(new Date()).dispatch()