@@ -32,43 +32,28 @@ Each `update` which is passed to the callback comes with the following propertie
3232Example:
3333
3434``` js
35- let myDocumentState = localStorage .getItem (" myDocumentState" ) ?? " " ;
36-
37- let initialPendingUpdatesHandled = false ;
35+ let myDocumentState = " " ;
3836const initialPendingUpdatesHandledPromise = window .webxdc .setUpdateListener (
3937 (update ) => {
4038 // Remember that the listener is invoked for
4139 // your own `window.webxdc.sendUpdate()` calls as well!
4240
43- applyDocumentUpdate (update .payload );
44- localStorage .setItem (" myDocumentState" , myDocumentState);
45- localStorage .setItem (" lastHandledUpdateSerial" , update .serial );
41+ // Dummy document update logic.
42+ // Yours might be more complex,
43+ // such as applying a chess move to the board.
44+ myDocumentState = myDocumentUpdate;
4645
4746 const areMoreUpdatesPending = update .serial !== update .max_serial ;
48- if (
49- ! areMoreUpdatesPending &&
50- // We'll make the initial render when the promise resolves,
51- // because if there are no pending updates,
52- // the listener will not be invoked.
53- initialPendingUpdatesHandled
54- ) {
47+ if (! areMoreUpdatesPending) {
5548 renderDocument ();
5649 }
57- },
58- parseInt (localStorage .getItem (" lastHandledUpdateSerial" ) ?? " 0" )
50+ }
5951);
6052
6153initialPendingUpdatesHandledPromise .then (() => {
62- initialPendingUpdatesHandled = true ;
6354 renderDocument ();
6455});
6556
66- function applyDocumentUpdate (myDocumentUpdate ) {
67- // Dummy `applyDocumentUpdate` logic.
68- // Yours might be more complex,
69- // such as applying a chess move to the board.
70- myDocumentState = myDocumentUpdate;
71- }
7257// Let's only call this when there are no pending updates.
7358function renderDocument () {
7459 document .body .innerText = myDocumentState;
0 commit comments