Files
nerfstudio/nerfactory/viewer/app/src/subscriber.js
T
2022-08-02 21:02:28 +00:00

20 lines
571 B
JavaScript

import { useContext } from 'react';
import { ReactReduxContext } from 'react-redux';
export function subscribe_to_changes(selector_fn, fn) {
// selector_fn: returns a value from the redux state
// fn_valid: function to run on a valid input
// fn_null: function to run on a null input
const { store } = useContext(ReactReduxContext);
let current;
const handleChange = () => {
const previous = current;
current = selector_fn(store.getState());
if (previous !== current) {
fn(previous, current);
}
};
store.subscribe(handleChange);
}