@stripchatdev/ext-helper 0.1.43 → 0.1.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -41,6 +41,37 @@ await ext.makeRequest('v1.ext.whisper.local', {
41
41
  });
42
42
  ```
43
43
 
44
+ ### Share state between slots
45
+
46
+ Create the state host in the background slot. The background slot owns the
47
+ canonical state and synchronizes it with visual slots through a shared channel:
48
+
49
+ ```ts
50
+ import {createSlotStateHost} from '@stripchatdev/ext-helper/helpers';
51
+
52
+ const state = createSlotStateHost({
53
+ channel: 'game',
54
+ extHelper: ext,
55
+ initialState: {score: 0},
56
+ });
57
+
58
+ await state.setState({score: 1});
59
+ ```
60
+
61
+ Create a state client in a visual slot to read and update the background state.
62
+ Use the same `channel` value as the background host. The visual slot does not
63
+ own the state; its `setState` calls are sent to the background host, and its state
64
+ updates when the host publishes a snapshot:
65
+
66
+ ```ts
67
+ import {useSlotState} from '@stripchatdev/ext-helper/helpers/react';
68
+
69
+ const {isLoading, setState, state} = useSlotState({
70
+ channel: 'game',
71
+ extHelper: ext,
72
+ });
73
+ ```
74
+
44
75
  ### Call a backend action
45
76
 
46
77
  ```ts