Skip to content

Store Feature Middleware API

David A. Sanders edited this page Dec 14, 2020 · 1 revision

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
  }
}

call

Fires as soon as state is dispatched. It is a non-blocking side effect.

features: {
  call: (data) => void
}

check

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
}

process

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
}

Data Object Properties

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
   }[]

V3 Docs

Clone this wiki locally