@collective-intelligence/external-apps-client-sdk-react 0.1.18 → 0.1.21
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 +28 -0
- package/dist/{index-netjbk62.js → index-rqhq16cy.js} +2 -2
- package/dist/index.d.ts +48 -0
- package/dist/index.js +1 -1
- package/dist/resources.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -114,6 +114,34 @@ record props arrive. Remount it intentionally (for example with a React `key`)
|
|
|
114
114
|
after the user chooses to discard the draft and edit a newer server revision.
|
|
115
115
|
Drafts and operation keys never enter the URL.
|
|
116
116
|
|
|
117
|
+
## Realtime topics
|
|
118
|
+
|
|
119
|
+
`RealtimeProvider` shares one `createRealtimeClient` instance, and so one
|
|
120
|
+
connection, with every component of the tab.
|
|
121
|
+
`useRealtimeTopic(topic, onChanges)` subscribes while the component is mounted
|
|
122
|
+
and unsubscribes on unmount. A new topic object for the same topic keeps the
|
|
123
|
+
subscription; `null` subscribes to nothing. The latest `onChanges` is called
|
|
124
|
+
without resubscribing. It receives the changes of the topic in batches: one
|
|
125
|
+
delivery per tab, 250 to 1000 ms after the first pending change, with the
|
|
126
|
+
latest change of each record.
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
const realtime = createRealtimeClient({ ticketUrl: "/api/realtime/ticket" })
|
|
130
|
+
|
|
131
|
+
<RealtimeProvider client={realtime}>
|
|
132
|
+
<LeadBoard />
|
|
133
|
+
</RealtimeProvider>
|
|
134
|
+
|
|
135
|
+
const LeadBoard = () => {
|
|
136
|
+
const queryClient = useQueryClient()
|
|
137
|
+
useRealtimeTopic({ schema: "crm.lead" }, () =>
|
|
138
|
+
// One invalidation per batch, however many leads changed.
|
|
139
|
+
queryClient.invalidateQueries({ queryKey: ["leads"] })
|
|
140
|
+
)
|
|
141
|
+
// …
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
117
145
|
## Workspace development
|
|
118
146
|
|
|
119
147
|
See the repository's [Effect demo](../../../demo/external-app-effect/README.md)
|