nytimes / react-tracking

🎯 Declarative tracking for React apps.
https://open.nytimes.com/introducing-react-tracking-declarative-tracking-for-react-apps-2c76706bb79a
Other
1.88k stars 123 forks source link

Multiple options.process behavior #28

Open oziniak opened 7 years ago

oziniak commented 7 years ago

Currently we encourage to use only one process on top level component, by making checks in constructor method of every tracking HoC

      constructor(props, context) {
        super(props, context);

        if (context.tracking && context.tracking.process && process) {
          console.error('[nyt-react-tracking] options.process should be used once on top level component');
        }
      }

Could these checks be performance consuming?

If there are several usages of options.process down a component tree desired behavior should be:

tizmagik commented 7 years ago

One option is to guard these checks against a NODE_ENV check, which should be optimized and dead-code eliminated by a properly configured Webpack build:

      constructor(props, context) {
        super(props, context);

        if (process.env.NODE_ENV !== 'production' && context.tracking && context.tracking.process && process) {
          console.error('[nyt-react-tracking] options.process should be used once on top level component');
        }
      }