-
Notifications
You must be signed in to change notification settings - Fork 0
Store Feature Middleware API
TrebleGSM middleware allows the Treble Store to centralize state related logic. It also allows TrebleGSM functionality to be extended with 3rd party middleware.
You can access the Middleware API from a Store Items features
property.
{
action: 'updateSomeState',
state: { someState: 'foo' },
features: {
//middleware properties
}
}
Fires as soon as state is dispatched. It is a non-blocking side effect.
features: {
call: (data) => void
}
Fires as soon as state is dispatched. It returns a boolean value. If true
the dispatch pipeline will continue. If false
it will cancel and the Store will not be updated.
features: {
check: (data) => boolean
}
Fires after the check
middleware finishes. It takes a dispatch value and returns a new value. The new value will be updated to the Store.
features: {
process: (data) => any
}
Each middleware function can recieve a data object with the dispatch value and other Store data properties.
dispatchValue - Value dispatched from SubscribeAPI methods.
dispatchValue: any
dispatchAction - Action data dispatched from SubscribeAPI methods.
dispatchAction: {
dispatchTime: Date,
type: string,
[key: string]: any, //action dispatch method
subscribeType: string,
options?: //Store Method option properties
}
processedValue - Processed dispatch value that is returned from process
middleware.
processedValue: any | undefined,
action - Store item action key.
action: string
features - Store item features.
features: any | undefined
currentState - Store item current state.
currentState: any
storeState - All Store item state.
storeState: {
[key:string]: any
}
storeItems - Returns an array of Store Item objects.
storeItems: {
action: string,
state: any,
features?: //Store item features
}[]