Step 1: Import the middleware
To get started import thecreateLiveStateMiddleware middleware from the Velt SDK.
Step 2: Add the middleware to your Redux store configuration
UsecreateLiveStateMiddleware to create a middleware and a updateLiveStateDataId method.
Then add the created middleware to your Redux store configuration.
You can also export the updateLiveStateDataId method from your Redux store. This method will be used to dynamically set the liveStateDataId.
store.js:
Step 3: Selectively sync actions
createLiveStateMiddleware takes in an optional configuration object with the following schema:
allowedActionTypes- allow live state syncing on specific action types onlydisabledActionTypes- restrict live state syncing on specific action typesallowAction- custom callback method to dynamically decide to allow or disable syncing for that action. Returntrueto allow the action andfalseto restrict the action.liveStateDataId- used to set a custom string value as live state data key. If not provided, we will store data in default key.
It is recommended to first set a custom
liveStateDataId in the middleware configuration. You can then change it dynamically later using the updateLiveStateDataId method.liveStateDataId dynamically, call the updateLiveStateDataId method that was previously created and exported from your store.
Step 4: Action Data Structure
The middleware automatically adds a UTC timestamp to each synced Redux action. The action data structure includes:timestamp field is automatically added by the middleware and represents the UTC time in milliseconds when the action was dispatched. This helps with action ordering and debugging across distributed clients.

