mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
onNewState changes the state based on which model actually changes
This commit is contained in:
parent
94c0016cad
commit
6b20949f68
1 changed files with 4 additions and 3 deletions
|
|
@ -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 () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue