State Adapter
<bk-state-adapter></bk-state-adapter>
The State Adapter allows injecting the window
state into the payload of various events, emitted upon connecting to the DOM.
Window state can be set, for example, using the push-state method.
Since the State Adapter allows to emit events upon landing to the new page, it is often used in the context of plugin navigation, as explained in the dedicated section.
How to configure
Upon connection, the State Adapter consumes the current window
state.
The State Adapter initially searches for data within the window state that is associated with a key matching the value of initKey
. If the data retrieved in this way forms an array of events, the State Adapter emits these events.
Additionally, the configMap
property and the window state are combined, resulting in an object that contains label-payload pairs, where the label is extracted from configMap
and the payload comes from the window
state. The State Adapter emits these pairs as events.
{
"tag": "bk-state-adapter",
"properties": {
"initKey": "__INITIAL_KEY__",
"configMap": {
"__KEY_1__": "loading-data"
}
}
}
Examples
Given the following configuration of the State Adapter:
{
"tag": "bk-state-adapter",
"properties": {
"initKey": "key_0",
"configMap": {
"key_1": "loading-data",
"key_2": "add-new"
}
}
}
and assuming the window state to be:
{
"key_0": [
{
"label": "change-query",
"payload": {"pageSize": 10}
}
],
"key_1": {
"loading": true
},
"key_2": {
"foo": "bar"
}
}
upon connection,the State Adapter emits:
- a change-query event such as:
{
"label": "change-query",
"payload": {
"pageSize": 10
}
}
- a loading-data event such as:
{
"label": "loading-data",
"payload": {
"loading": true
}
}
- an add-new event such as:
{
"label": "add-new",
"payload": {
"foo": "bar"
}
}
API
Properties & Attributes
property | attribute | type | default | description |
---|---|---|---|---|
configMap | - | {[name: string]: string} | {} | map to configure the adapter casting object properties to events labels |
debounce | debounce | number | 500 | delay for initial event emission |
initKey | init-key | string | "__BK_INIT" | key for events to emit once upon connection |
Listens to
This component listens to no event.
Emits
event | description |
---|---|
configurable event | generic event based on its configMap property |