Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add examples for sendUpdate, setUpdateListener #82

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

WofWca
Copy link
Member

@WofWca WofWca commented Jul 13, 2024

Closes #60

Some might say that the setUpdateListener example is too convoluted, but you can't really showcase the usage of serial without this much code.
Plus, a briefer example is already shown in sendUpdate() docs.
Update: I simplified the example.

The code has been tested with the webxdc-dev tool,
and (mostly) fomatted with Prettier.

@WofWca WofWca force-pushed the sendUpdate-and-setUpdateListener-examples branch 2 times, most recently from 40ac2ef to f9a7c9a Compare July 13, 2024 13:47
@hpk42
Copy link
Contributor

hpk42 commented Jul 13, 2024

thanks! the setUpdateListener example is too big -- it almost provides more of a framework where you can just implement some functions but that's not needed for a basic example.
The basic logic boils down do

process-update() 
if update.serial == update.max_serial { render()}

and i would do this without any extra function. Anything more advanced should be link to a github-repo if needed.

WofWca added 2 commits July 14, 2024 12:44
Closes #60

Some might say that the setUpdateListener example is too convoluted,
but you can't really showcase the usage of `serial`
without this much code.
Plus, a briefer example is already shown in `sendUpdate()` docs.

The code has been tested with the `webxdc-dev` tool,
and (mostly) fomatted with Prettier.
@WofWca WofWca force-pushed the sendUpdate-and-setUpdateListener-examples branch from f9a7c9a to 7263ac5 Compare July 14, 2024 08:53
@WofWca WofWca requested a review from hpk42 July 14, 2024 08:54
Copy link
Contributor

@hpk42 hpk42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some changes needed i think still

src-docs/spec/setUpdateListener.md Outdated Show resolved Hide resolved
src-docs/spec/setUpdateListener.md Outdated Show resolved Hide resolved
src-docs/spec/setUpdateListener.md Show resolved Hide resolved
src-docs/spec/setUpdateListener.md Outdated Show resolved Hide resolved
}

// Peers can send messages like this
window.webxdc.sendUpdate({ payload: "Knight d3" }, "Bob made a move!");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

above you talk about a hyptothetic chess thing, but suddenly you send a move.
I'd rather stay within the "document state" terminology.

Suggested change
window.webxdc.sendUpdate({ payload: "Knight d3" }, "Bob made a move!");
window.webxdc.sendUpdate({ payload: "new document set from ${window.webxdc.selfName}" });

Comment on lines +42 to +43
// Yours might be more complex,
// such as applying a chess move to the board.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Yours might be more complex,
// such as applying a chess move to the board.

@WofWca
Copy link
Member Author

WofWca commented Dec 3, 2024

Ok, feel free to proceed with the suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide examples of API usage in https://docs.webxdc.org/spec.html
2 participants