Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracker integration - child components declare dependencies on parent components #153

Open
davidworkman9 opened this issue Feb 4, 2017 · 0 comments

Comments

@davidworkman9
Copy link

davidworkman9 commented Feb 4, 2017

With the 1.x version and the solution the README for 2, a child component can affect an autorun on a parent, which in my case caused a ton of subscriptions to get called, spiking CPU usage to 80%+ on an AWS general purpose medium instance with two people typing on a controlled component. I fixed this by first upgrading to 2.0, then taking the README solution for tracker and wrapping a nonreactive call around the call to onData.

function getTrackerLoader(reactiveMapper) {
    return (props, onDataOrig, env) => {
        const onData = (...args) =>
            Tracker.nonreactive(() =>
                onDataOrig.apply(this, args));

        let trackerCleanup = null;
        const handler = Tracker.nonreactive(() => {

            return Tracker.autorun(() => {
                trackerCleanup = reactiveMapper(props, onData, env);
            });
        });

        return () => {
            if(typeof trackerCleanup === 'function') trackerCleanup();
            return handler.stop();
        };
    };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant