-
Notifications
You must be signed in to change notification settings - Fork 85
Fix useLocalAwareness & useRemoteAwareness types #436
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
base: main
Are you sure you want to change the base?
Conversation
| import { useEffect } from "react" | ||
| import useStateRef from "react-usestateref" | ||
| import { peerEvents } from "./useRemoteAwareness.js" | ||
| import { peerEvents } from "./useRemoteAwareness" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
separate commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, I think we can roll in other minor cleanup.
| export const useLocalAwareness = ({ | ||
| handle, | ||
| export const useLocalAwareness = <T>({ | ||
| handle?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
separate commit? (as well as optional chaining)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for a separate commit, but why the ? here? I don't think I know that syntax.
| ) | ||
| const [heartbeats, setHeartbeats, heartbeatsRef] = useStateRef<Heartbeats>({}) | ||
| useEffect(() => { | ||
| if (!handle) return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
separate commit? also add braces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer braces, but if it passes linting, this is okay by me. We can litigate that separately. No need for a separate commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution. I added some suggestion, but overall it looks good.
I see it's still a draft. Are you interested in continuing it?
| import { useEffect } from "react" | ||
| import useStateRef from "react-usestateref" | ||
| import { peerEvents } from "./useRemoteAwareness.js" | ||
| import { peerEvents } from "./useRemoteAwareness" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, I think we can roll in other minor cleanup.
| export const useLocalAwareness = ({ | ||
| handle, | ||
| export const useLocalAwareness = <T>({ | ||
| handle?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for a separate commit, but why the ? here? I don't think I know that syntax.
| }: UseLocalAwarenessProps<T>): [ | ||
| T, | ||
| (stateOrUpdater: T | StateUpdater<T>) => void | ||
| ] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're following React patterns for these hooks, it would be good to return
[ T, React.Dispatch<React.SetStateAction<T>> ]from them.
| handle?: DocHandle<unknown> | ||
| /** Our user ID - Automerge BroadcastChannel sometimes sends us our own messages; optionally filters them */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment feels out of place. Maybe it should be here instead, but it's fairly clear what's going on there...
| handle?: DocHandle<unknown> | |
| /** Our user ID - Automerge BroadcastChannel sometimes sends us our own messages; optionally filters them */ | |
| handle?: DocHandle<unknown> | |
| /** Our user ID */ |
| /** How long to wait (in ms) before marking a peer as offline */ | ||
| offlineTimeout?: number | ||
| /** Function to provide current epoch time */ | ||
| /** Function to provide current epoch time (used for testing) */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a slightly bigger (and separate) project, but I wonder if we can use mockdate or another similar package instead to avoid this API wart. I've had a pretty good experience with mockdate in the past.
| ) | ||
| const [heartbeats, setHeartbeats, heartbeatsRef] = useStateRef<Heartbeats>({}) | ||
| useEffect(() => { | ||
| if (!handle) return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer braces, but if it passes linting, this is okay by me. We can litigate that separately. No need for a separate commit.
| event: DocHandleEphemeralMessagePayload<T> | ||
| event: DocHandleEphemeralMessagePayload<unknown> | ||
| ) => { | ||
| const [userId, state] = event.message as [string, unknown] | ||
| const [userId, state] = event.message as [string, T] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand these changes. Can you clarify?
|
Hey! Thanks for the review. I will be 100% continuing work, but it will be a couple of months before I have the bandwidth to focus on this again :) |
|
@neftaly hey, no problem. Just follow up when you're ready. |
No description provided.