Event Data
Sending event data to consumers is an important feature of the WireBootstrap data event system.

Basic Data Events

To pass a custom object as part of an event, use the data method on the data event.
1
const product = { sku: "SKU0001" }
2
3
const dataevent = new wire.data.DataEvent("myevent")
4
.data(product);
5
6
dataevent.raise();
Copied!
The data can then be retrieved from the object passed into the data event listener callback using the data attribute.
1
wire.data.listen().event("myevent").when((config) => {
2
3
const data = config.data;
4
5
console.log(data.sku);
6
7
});
Copied!

Structured Data Events

The data event system is used extensively by WireBootstrap components to communicate with one another about the changes a user is making on a page as they interact with the components. Components can receive notifications of changes in other components and react accordingly if they are displaying data that may be affected by a user interaction.
Components receive their data as WireBootstrap data tables. The wire.data.DataEvent class contains methods that allow provider components to send out events with the components of their data that was changed or otherwise affected by a user interaction.
In the example below, a new dataselect.wire event is raised and the cell method on the data event is used to store an individual data point contained inside a data table.
1
const table = new wire.data.DataTable([
2
{"product", "SKU001", month: "May", sales: "200"}
3
]);
4
5
...
6
7
new wire.data.DataEvent()
8
.dataselect()
9
.cell("product", "SKU001")
10
.raise();
Copied!
Other methods allow the event to contain more data about the dataselect.wire event supplying the table column, the table row, and the table itself as additional context about the user's selection using methods with the same name.
1
...
2
3
ev.table(table);
4
5
ev.column(table.getColumn("product"));
6
7
ev.row(table.Rows[0]);
8
9
...
Copied!

Listening for Structured Data

Consumers can qualify the events in which they are interested by specifying a number of data elements when setting up the listener.
In the example below, the consumer is listening for dataselect.wire events but only on ones that concern the product column on a structured data event. Also seen below, the callback method when parameter now contains the data elements sent by the provider that raised the data event.
1
wire.data.listen().dataselect().column("product").when((config) => {
2
3
const data = config.data;
4
5
const cell = data.cell;
6
const col = data.column;
7
const row = data.row;
8
const table = data.table;
9
10
...
11
12
})
Copied!