reactive-robot gives you this API:
- - rr.addObserver(key, observerFunction) - key is a unique identifier for your component, observerFunction is your event handler function, by convention called onEvent. After adding an object or component as an observer, it will be called whenever a new event occurs. The recipient decides if this event is of interest and can update, send events or re-render as appropriate.
- - rr.removeObserver(key) - key is unique identifier. Remove this object or component from the observers list, so it will not be notified of subsequent events.
- - rr.next(eventName, data) - eventName is a string, data is an optional object. Calls to next() call onEvent for each registered observer. You could think of this as a pub/sub mechanism or event stream - the reactive-robot next() method creates a stream of events over time, and observers decide if they want to react to these events. Store your event names as constants so they are type-safe and reusable. For event payloads in javascript, just add a data object as the second argument. In typescript, you can define an interface for the data payload. Make the properties optional and use it as the type for your payload data.See the example here: test-rr-vite.