check for deps intersection

This commit is contained in:
nklhrstv 2022-07-10 12:28:44 +03:00
parent 0f2c9c98d5
commit 659a6f7531

View file

@ -3,6 +3,7 @@
const React = require('react');
const throttle = require('lodash.throttle');
const isEqual = require('lodash.isequal');
const intersection = require('lodash.intersection');
const { useRouteFocused } = require('stremio-router');
const { useServices } = require('stremio/services');
@ -61,8 +62,8 @@ const useModelState = ({ action, ...args }) => {
const { core } = useServices();
const routeFocused = useRouteFocused();
const mountedRef = React.useRef(false);
const [model, timeout, map] = React.useMemo(() => {
return [args.model, args.timeout, args.map];
const [model, timeout, map, deps] = React.useMemo(() => {
return [args.model, args.timeout, args.map, args.deps];
}, []);
const getInitState = React.useContext(ModelSuspenderContext);
const [state, setState] = React.useReducer(
@ -93,7 +94,7 @@ const useModelState = ({ action, ...args }) => {
}, []);
React.useInsertionEffect(() => {
const onNewState = async (models) => {
if (models.indexOf(model) === -1) {
if (models.indexOf(model) === -1 && (!Array.isArray(deps) || intersection(deps, models).length === 0)) {
return;
}