Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const [subscription, notifyNestedSubs] = useMemo(() => {
if (!shouldHandleStateChanges) return NO_SUBSCRIPTION_ARRAY;
// This Subscription's source should match where store came from: props vs. context. A component
// connected to the store via props shouldn't use subscription from context, or vice versa.
const subscription = new Subscription(
store,
didStoreComeFromProps ? null : contextValue.subscription
);
// `notifyNestedSubs` is duplicated to handle the case where the component is unmounted in
// the middle of the notification loop, where `subscription` will then be null. This can
// probably be avoided if Subscription's listeners logic is changed to not call listeners
// that have been unsubscribed in the middle of the notification loop.
const notifyNestedSubs = subscription.notifyNestedSubs.bind(
subscription
);
return [subscription, notifyNestedSubs];
}, [store, didStoreComeFromProps, contextValue]);
const [subscription, notifyNestedSubs] = useMemo(() => {
const subscription = new Subscription(store, contextValue.subscription);
const notifyNestedSubs = subscription.notifyNestedSubs.bind(subscription);
return [subscription, notifyNestedSubs];
}, [store, , contextValue]);
componentDidUpdate(prevProps) {
if (this.props.store !== prevProps.store) {
this.state.subscription.tryUnsubscribe();
const subscription = new Subscription(this.props.store);
subscription.onStateChange = this.notifySubscribers;
this.setState({ store: this.props.store, subscription });
}
}
const subscription = useMemo(() => new Subscription(store, contextValue.subscription), [
store,
constructor(props) {
super(props);
const { store } = props;
this.notifySubscribers = this.notifySubscribers.bind(this);
const subscription = new Subscription(store);
subscription.onStateChange = this.notifySubscribers;
this.state = {
store,
subscription
};
this.previousState = store.getState();
}