Skip to content

Commit 4e7b835

Browse files
committed
chore(json-crdt-peritext-ui): 🤖 add autoflush to Peritext demo
1 parent b6f1119 commit 4e7b835

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/json-crdt-peritext-ui/__demos__/components/App.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ export const App: React.FC = () => {
3030
return [model, peritext] as const;
3131
});
3232

33+
React.useEffect(() => {
34+
model.api.autoFlush();
35+
return () => {
36+
model.api.stopAutoFlush?.();
37+
};
38+
}, [model]);
39+
3340
const plugins = React.useMemo(() => {
3441
const cursorPlugin = new CursorPlugin();
3542
const toolbarPlugin = new ToolbarPlugin();

src/json-crdt-peritext-ui/react/PeritextView.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ export const PeritextView: React.FC<PeritextViewProps> = React.memo((props) => {
5656
if (onRender) onRender();
5757
}, [peritext]);
5858

59+
const model = peritext.model;
60+
React.useEffect(() => {
61+
const unsubscribe = peritext.model.api.onFlush.listen((patch) => {
62+
console.log('flush', patch);
63+
});
64+
return () => {
65+
unsubscribe();
66+
};
67+
}, [model]);
68+
5969
const state: PeritextSurfaceState = React.useMemo(() => {
6070
const state = new PeritextSurfaceState(peritext, create(peritext), rerender, plugins);
6171
onState?.(state);

0 commit comments

Comments
 (0)