Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@neftaly
Copy link
Collaborator

@neftaly neftaly commented Jun 15, 2025

No description provided.

import { useEffect } from "react"
import useStateRef from "react-usestateref"
import { peerEvents } from "./useRemoteAwareness.js"
import { peerEvents } from "./useRemoteAwareness"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

separate commit?

Copy link
Collaborator

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?,
Copy link
Collaborator Author

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)

Copy link
Collaborator

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
Copy link
Collaborator Author

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

Copy link
Collaborator

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.

Copy link
Collaborator

@msakrejda msakrejda left a 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"
Copy link
Collaborator

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?,
Copy link
Collaborator

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.

Comment on lines +36 to +39
}: UseLocalAwarenessProps<T>): [
T,
(stateOrUpdater: T | StateUpdater<T>) => void
] => {
Copy link
Collaborator

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.

Comment on lines +14 to +15
handle?: DocHandle<unknown>
/** Our user ID - Automerge BroadcastChannel sometimes sends us our own messages; optionally filters them */
Copy link
Collaborator

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...

Suggested change
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) */
Copy link
Collaborator

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
Copy link
Collaborator

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.

Comment on lines -53 to +54
event: DocHandleEphemeralMessagePayload<T>
event: DocHandleEphemeralMessagePayload<unknown>
) => {
const [userId, state] = event.message as [string, unknown]
const [userId, state] = event.message as [string, T]
Copy link
Collaborator

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?

@neftaly
Copy link
Collaborator Author

neftaly commented Jul 27, 2025

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 :)

@msakrejda
Copy link
Collaborator

@neftaly hey, no problem. Just follow up when you're ready.

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.

2 participants