Remove optionality from session socket

Co-Authored-By: Nicola Thouliss <53867736+nthouliss@users.noreply.github.com>
This commit is contained in:
Mitchell McCaffrey
2021-09-04 10:04:25 +10:00
parent 816320c1c2
commit b307a20169
6 changed files with 33 additions and 38 deletions

View File

@@ -60,7 +60,7 @@ function useNetworkedState<S extends { readonly [x: string]: any } | null>(
const debouncedState = useDebounce(state, debounceRate);
const lastSyncedStateRef = useRef<S>();
useEffect(() => {
if (session.socket && dirtyRef.current) {
if (dirtyRef.current) {
// If partial updates enabled, send just the changes to the socket
if (
lastSyncedStateRef.current &&
@@ -112,11 +112,11 @@ function useNetworkedState<S extends { readonly [x: string]: any } | null>(
});
}
session.socket?.on(eventName, handleSocketEvent);
session.socket?.on(`${eventName}_update`, handleSocketUpdateEvent);
session.socket.on(eventName, handleSocketEvent);
session.socket.on(`${eventName}_update`, handleSocketUpdateEvent);
return () => {
session.socket?.off(eventName, handleSocketEvent);
session.socket?.off(`${eventName}_update`, handleSocketUpdateEvent);
session.socket.off(eventName, handleSocketEvent);
session.socket.off(`${eventName}_update`, handleSocketUpdateEvent);
};
}, [session.socket, eventName, partialUpdatesKey]);