onNewState changes the state based on which model actually changes

This commit is contained in:
nklhrstv 2022-07-07 22:38:11 +03:00
parent 94c0016cad
commit 6b20949f68

View file

@ -92,7 +92,7 @@ const useModelState = ({ action, ...args }) => {
};
}, []);
React.useInsertionEffect(() => {
const onNewStateThrottled = throttle(async (models) => {
const onNewState = async (models) => {
if (models.indexOf(model) === -1) {
return;
}
@ -103,11 +103,12 @@ const useModelState = ({ action, ...args }) => {
} else {
setState(state);
}
}, timeout);
};
const onNewStateThrottled = throttle(onNewState, timeout);
if (routeFocused) {
core.transport.on('NewState', onNewStateThrottled);
if (mountedRef.current) {
onNewStateThrottled.call();
onNewState([model]);
}
}
return () => {