README
Reactive - Node
Basic Example
const core = new reactive.Controller()
const weatherStation = new reactive.Subject(core)
weatherStation.registerChannel('au.com.acme.station/temps')
core.on('au.com.acme.station/temps', (event) => {
if (event.source === 'temp_update') {
console.log('tempData:', event.data)
}
})
const tempUpdateEvent = createReactiveEvent(
'temp_update',
'au.com.acme.station/temps',
{
temp0: 54,
temp1: 48,
}
)
weatherStation.emit(tempUpdateEvent)
Output:
>> tempData: { temp0: 54, temp1: 48 }
Event Controller
The controllers acts as the hub, provides an interface to manage observers, subjects and channels. allowing subjects and observers to register to channels, and able to emit to any channel that's registered.
Controller by default has access to a special channel called global which is shared amougst all controllers locally.
Creation of a controller is simple:
const core = new Controller()
Event Channel
Subject
Reactive Event Structure
{
specversion: '1.0'
type: 'au.com.acme.reactive/update'
source: 'tempUpdate'
id: 'e709e3a6-1e01-4209-b7d2-b592446e0011'
time: '<iso standard time stamp here>'
datacontenttype: 'application/json'
data: '<json formatted string>'
}