refactor: back with latus for HMR smoothness
This commit is contained in:
parent
c4bde402c0
commit
5eb0523389
|
@ -6,13 +6,10 @@ import {
|
|||
import {useSocket} from '@latus/socket';
|
||||
|
||||
export default () => {
|
||||
const [room, setRoom] = useState();
|
||||
const latus = useLatus();
|
||||
const [room, setRoom] = useState(latus.get('%room'));
|
||||
const socket = useSocket();
|
||||
const synchronizer = latus.get('%synchronizer');
|
||||
if (latus.get('%room') !== room) {
|
||||
setRoom(latus.get('%room'));
|
||||
}
|
||||
useEffect(() => {
|
||||
if (!room) {
|
||||
return undefined;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import {
|
||||
useEffect,
|
||||
useLatus,
|
||||
useState,
|
||||
} from '@latus/react';
|
||||
import {useSelector} from '@latus/redux';
|
||||
|
@ -8,14 +9,16 @@ import {selfEntitySelector} from '../state';
|
|||
import useRoom from './use-room';
|
||||
|
||||
export default () => {
|
||||
const latus = useLatus();
|
||||
const room = useRoom();
|
||||
const selfEntity = useSelector(selfEntitySelector);
|
||||
const [entity, setEntity] = useState();
|
||||
const [entity, setEntity] = useState(latus.get('%selfEntity'));
|
||||
useEffect(() => {
|
||||
if (!room) {
|
||||
return;
|
||||
}
|
||||
const onDestroying = () => {
|
||||
latus.set('%selfEntity', undefined);
|
||||
setEntity(undefined);
|
||||
};
|
||||
const augmentSelfEntity = async (entity) => {
|
||||
|
@ -25,9 +28,10 @@ export default () => {
|
|||
});
|
||||
entity.on('destroying', onDestroying);
|
||||
}
|
||||
latus.set('%selfEntity', entity);
|
||||
setEntity(entity);
|
||||
};
|
||||
augmentSelfEntity(room.findEntity(selfEntity));
|
||||
}, [room, selfEntity]);
|
||||
}, [latus, room, selfEntity]);
|
||||
return entity;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user