Often the state of one component will need to change, based on what is happening in other components. Events are the way components communicate with one another. In order for Component B to know what’s going on with Component A, it listens for events.

To see events in action, take a look at how the iiif-gallery-component updates its state based on the iiif-tree-component treeNodeSelected event in this jsbin example. You can also see the kind of data passed via the svg-draw-component’s events flashing on the page as you create and edit shapes in the demo.

However, Component A does not necessarily know how or what to listen to from Component B. Therefore, every unique combination of components will need its own custom pubsub library that can be used to publish events and register subscribers. The BaseCommands definition for the Universal Viewer defines all the commands and their associated event identifiers so UV components can listen for these events.

Tiny PubSub

Currently, the base-component is outfitted with a fork of the Tiny PubSub jQuery plugin. This is mixed into the the base-component and allows all components that extend the base-component to emit events.