a tool for shared writing and social publishing
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

debounce text updates to replicache

+14 -15
+14 -15
components/Blocks/TextBlock/index.tsx
··· 592 592 useEffect(() => { 593 593 if (!rep.rep) return; 594 594 let timeout = null as null | number; 595 + const updateReplicache = async () => { 596 + const update = Y.encodeStateAsUpdate(ydoc); 597 + await rep.rep?.mutate.assertFact({ 598 + //These undos are handled above in the Prosemirror context 599 + ignoreUndo: true, 600 + entity: entityID, 601 + attribute: "block/text", 602 + data: { 603 + value: base64.fromByteArray(update), 604 + type: "text", 605 + }, 606 + }); 607 + }; 595 608 const f = async (events: Y.YEvent<any>[], transaction: Y.Transaction) => { 596 609 if (!transaction.origin) return; 597 - const updateReplicache = async () => { 598 - const update = Y.encodeStateAsUpdate(ydoc); 599 - await rep.rep?.mutate.assertFact({ 600 - //These undos are handled above in the Prosemirror context 601 - ignoreUndo: true, 602 - entity: entityID, 603 - attribute: "block/text", 604 - data: { 605 - value: base64.fromByteArray(update), 606 - type: "text", 607 - }, 608 - }); 609 - }; 610 610 if (timeout) clearTimeout(timeout); 611 - updateReplicache(); 612 611 timeout = window.setTimeout(async () => { 613 612 updateReplicache(); 614 - }, 20); 613 + }, 300); 615 614 }; 616 615 617 616 yText.observeDeep(f);