How to use the react-redux/lib/utils/Subscription function in react-redux

To help you get started, we’ve selected a few react-redux examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lolatravel / realm-react-redux / src / components / connectAdvanced.js View on Github external
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]);
github wangtao0101 / resa / src / components / Subscribe.tsx View on Github external
const [subscription, notifyNestedSubs] = useMemo(() => {
                const subscription = new Subscription(store, contextValue.subscription);

                const notifyNestedSubs = subscription.notifyNestedSubs.bind(subscription);
                return [subscription, notifyNestedSubs];
            }, [store, , contextValue]);
github lolatravel / realm-react-redux / src / components / provider.js View on Github external
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 });
        }
    }
github wangtao0101 / resa / src / components / useResa.ts View on Github external
    const subscription = useMemo(() => new Subscription(store, contextValue.subscription), [
        store,
github lolatravel / realm-react-redux / src / components / provider.js View on Github external
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();
    }