Outlet Hooks

Outlet Hooks

Every time the Outlet changes an event is emitted with the new Outlet ID.

Data Structure

The data attribute of the event will have the following structure:

{
	"event_name": "outlet:set",
	"data": {
		"outlet_id": "a604d16b-a999-8748-11e6-9a4e7ba6e8d3",
	},
	"source": "Vend Client API"
}

Event Handling

Here's an example of how a browser extension can subscribe to this event and perform actions based on it:

window.addEventListener('message', event => {
  let eventData
  try {
    eventData = JSON.parse(event.data)
  } catch (e) {
    // @todo handle/log error
    return
  }

  if (eventData.event_name === 'outlet:set') {
    const outletId = eventData.data.outlet_id
    // @todo do stuff with outletId
  }
})