-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! refactor(#141): [wip] enable multiple action receivers
- Loading branch information
1 parent
29b90d9
commit 5d95ffa
Showing
4 changed files
with
53 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { PeerRoom } from 'lib/PeerRoom' | ||
import { PeerAction } from 'models/network' | ||
import { useEffect, useState } from 'react' | ||
import { | ||
ActionProgress, | ||
ActionReceiver, | ||
ActionSender, | ||
DataPayload, | ||
} from 'trystero' | ||
|
||
export const usePeerAction = <T extends DataPayload>({ | ||
peerRoom, | ||
peerAction, | ||
}: { | ||
peerRoom: PeerRoom | ||
peerAction: PeerAction | ||
}): [ActionSender<T>, ActionReceiver<T>, ActionProgress] => { | ||
const [[sender, receiver, progress, detatchReceiver]] = useState(() => | ||
// FIXME: Remove namespace | ||
peerRoom.makeAction<T>(peerAction, '') | ||
) | ||
|
||
useEffect(() => { | ||
return () => { | ||
detatchReceiver() | ||
} | ||
}, [detatchReceiver]) | ||
|
||
return [sender, receiver, progress] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters