Skip to content

Commit d414bcd

Browse files
rootcursoragent
authored andcommitted
docs: Deduplicate ACID playgrounds and persist example
Reuse the existing optimistic-transform demo and list interceptor instead of copying them, and point durability at the managers persist example. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent f74ba7e commit d414bcd

3 files changed

Lines changed: 18 additions & 182 deletions

File tree

docs/core/concepts/acid.md

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import AcidCollections from '../shared/\_acidCollections.mdx';
1818
import AcidQuery from '../shared/\_acidQuery.mdx';
1919
import AcidValidate from '../shared/\_acidValidate.mdx';
2020
import AcidTransports from '../shared/\_acidTransports.mdx';
21-
import AcidFetchOrder from '../shared/\_acidFetchOrder.mdx';
21+
import OptimisticTransform from '../../rest/shared/\_optimisticTransform.mdx';
2222
import AcidSnapshot from '../shared/\_acidSnapshot.mdx';
2323
import AcidRest from '../shared/\_acidRest.mdx';
2424

@@ -33,7 +33,7 @@ ACID. The frontend store is that database for interactive data — but every
3333
durable write is [asynchronous](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous).
3434

3535
Reactive Data Client applies the same guarantees so every view agrees without
36-
[refetching](../api/Controller.md#expireAll), mutations don't flash torn state, and
36+
refetching, mutations don't flash torn state, and
3737
crashes don't lose data that reached a durable store like a REST server or
3838
[IndexedDB](./managers.md#persistence).
3939

@@ -181,7 +181,7 @@ keeps 0, 1, 2.
181181

182182
Click increment several times quickly.
183183

184-
<AcidFetchOrder />
184+
<OptimisticTransform />
185185

186186
[Optimistic updates](/rest/guides/optimistic-updates) amplify these races;
187187
Reactive Data Client handles them automatically.
@@ -222,40 +222,6 @@ for offline reloads. Restore it with
222222
[DataProvider's initialState](../api/DataProvider.md#initialState). Drop
223223
in-flight optimistic updates — they are not cloneable, and they are not the ack.
224224

225-
```typescript
226-
import type { Manager, Middleware } from '@data-client/react';
227-
import { set } from 'idb-keyval';
228-
229-
export default class PersistManager implements Manager {
230-
declare protected timer?: ReturnType<typeof setTimeout>;
231-
232-
middleware: Middleware = controller => next => async action => {
233-
await next(action);
234-
clearTimeout(this.timer);
235-
this.timer = setTimeout(() => {
236-
const state = { ...controller.getState(), optimistic: [] };
237-
set('data-client', state);
238-
}, 1000);
239-
};
240-
241-
cleanup() {
242-
clearTimeout(this.timer);
243-
}
244-
}
245-
```
246-
247-
```tsx
248-
import { get } from 'idb-keyval';
249-
250-
const initialState = await get('data-client');
251-
252-
createRoot(document.body).render(
253-
<DataProvider initialState={initialState} managers={managers}>
254-
<App />
255-
</DataProvider>,
256-
);
257-
```
258-
259225
:::info[Reactivity]
260226

261227
ACID makes writes trustworthy. [useLive()](../api/useLive.md),

docs/core/shared/_acidFetchOrder.mdx

Lines changed: 0 additions & 113 deletions
This file was deleted.

website/src/fixtures/acid.ts

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,19 @@ export function getAcidSideEffectData(): AcidSideEffectState {
9595
};
9696
}
9797

98-
export const acidTodoFixtures: Interceptor<AcidTodoState>[] = [
99-
{
100-
endpoint: getTodoList,
101-
response(params) {
102-
if (params?.userId != null) {
103-
return this.todos.filter(todo => todo.userId == params.userId);
104-
}
105-
return this.todos;
106-
},
107-
delay: 150,
98+
const getTodoListInterceptor: Interceptor<AcidTodoState> = {
99+
endpoint: getTodoList,
100+
response(params) {
101+
if (params?.userId != null) {
102+
return this.todos.filter(todo => todo.userId == params.userId);
103+
}
104+
return this.todos;
108105
},
106+
delay: 150,
107+
};
108+
109+
export const acidTodoFixtures: Interceptor<AcidTodoState>[] = [
110+
getTodoListInterceptor,
109111
{
110112
endpoint: getTodo,
111113
response({ id }) {
@@ -163,16 +165,7 @@ export const acidConsistencyFixtures: Interceptor<AcidConsistencyState>[] = [
163165
];
164166

165167
export const acidRollbackFixtures: Interceptor<AcidTodoState>[] = [
166-
{
167-
endpoint: getTodoList,
168-
response(params) {
169-
if (params?.userId != null) {
170-
return this.todos.filter(todo => todo.userId == params.userId);
171-
}
172-
return this.todos;
173-
},
174-
delay: 150,
175-
},
168+
getTodoListInterceptor,
176169
{
177170
endpoint: createTodo,
178171
response() {
@@ -185,16 +178,7 @@ export const acidRollbackFixtures: Interceptor<AcidTodoState>[] = [
185178
];
186179

187180
export const acidSideEffectFixtures: Interceptor<AcidSideEffectState>[] = [
188-
{
189-
endpoint: getTodoList,
190-
response(params) {
191-
if (params?.userId != null) {
192-
return this.todos.filter(todo => todo.userId == params.userId);
193-
}
194-
return this.todos;
195-
},
196-
delay: 150,
197-
},
181+
getTodoListInterceptor,
198182
{
199183
endpoint: getUser,
200184
response({ id }) {
@@ -206,8 +190,7 @@ export const acidSideEffectFixtures: Interceptor<AcidSideEffectState>[] = [
206190
},
207191
{
208192
endpoint: createTodo,
209-
response(...args) {
210-
const body = args.length > 1 ? args[1] : args[0];
193+
response(body) {
211194
const todo = {
212195
completed: false,
213196
userId: '1',

0 commit comments

Comments
 (0)