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';
|
import {useSocket} from '@latus/socket';
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const [room, setRoom] = useState();
|
|
||||||
const latus = useLatus();
|
const latus = useLatus();
|
||||||
|
const [room, setRoom] = useState(latus.get('%room'));
|
||||||
const socket = useSocket();
|
const socket = useSocket();
|
||||||
const synchronizer = latus.get('%synchronizer');
|
const synchronizer = latus.get('%synchronizer');
|
||||||
if (latus.get('%room') !== room) {
|
|
||||||
setRoom(latus.get('%room'));
|
|
||||||
}
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!room) {
|
if (!room) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import {
|
import {
|
||||||
useEffect,
|
useEffect,
|
||||||
|
useLatus,
|
||||||
useState,
|
useState,
|
||||||
} from '@latus/react';
|
} from '@latus/react';
|
||||||
import {useSelector} from '@latus/redux';
|
import {useSelector} from '@latus/redux';
|
||||||
|
@ -8,14 +9,16 @@ import {selfEntitySelector} from '../state';
|
||||||
import useRoom from './use-room';
|
import useRoom from './use-room';
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
|
const latus = useLatus();
|
||||||
const room = useRoom();
|
const room = useRoom();
|
||||||
const selfEntity = useSelector(selfEntitySelector);
|
const selfEntity = useSelector(selfEntitySelector);
|
||||||
const [entity, setEntity] = useState();
|
const [entity, setEntity] = useState(latus.get('%selfEntity'));
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!room) {
|
if (!room) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const onDestroying = () => {
|
const onDestroying = () => {
|
||||||
|
latus.set('%selfEntity', undefined);
|
||||||
setEntity(undefined);
|
setEntity(undefined);
|
||||||
};
|
};
|
||||||
const augmentSelfEntity = async (entity) => {
|
const augmentSelfEntity = async (entity) => {
|
||||||
|
@ -25,9 +28,10 @@ export default () => {
|
||||||
});
|
});
|
||||||
entity.on('destroying', onDestroying);
|
entity.on('destroying', onDestroying);
|
||||||
}
|
}
|
||||||
|
latus.set('%selfEntity', entity);
|
||||||
setEntity(entity);
|
setEntity(entity);
|
||||||
};
|
};
|
||||||
augmentSelfEntity(room.findEntity(selfEntity));
|
augmentSelfEntity(room.findEntity(selfEntity));
|
||||||
}, [room, selfEntity]);
|
}, [latus, room, selfEntity]);
|
||||||
return entity;
|
return entity;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user