@composi/datastore:

send

Send Events

You can send an event that a dataStore is watching. The send method can take two arguments: the event and some optional data to pass with it.

dataStore.watch('uh-oh', data => {
  console.log('Just received some data.')
  console.log(data)
})

// Sometime later send the event:
dataStore.send('uh-oh', 'Woohoo!')

As mentioned above, you can send an event with data, and for that matter, you can have an event that doesn't expect any data either:

dataStore.watch('uh-oh', () => {
  console.log('Looks like something happened.')
})

// Sometime later send the event:
dataStore.send('uh-oh')

Observer

Send is a convenient feature of dataStores, but in many cases it may be more efficient to just use an observer to watch for the event and deal with it. That's because all dataStore watchers are run whenever the dataStore state changes, not just when you send the event. This could lead to some rather convoluted behaviors where having a separate dedicated observer might be more simple and efficient. Please check out the documentation for @composi/observer to learn how to use it.