{"size": 954, "ext": "js", "max_stars_repo_path": "src/commands/RouteChangeCommand.js", "max_stars_repo_name": "sematext/browser-sdk", "max_stars_repo_stars_event_min_datetime": "2020-10-21T12:18:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T05:51:20.000Z", "max_issues_repo_path": "src/commands/RouteChangeCommand.js", "max_issues_repo_name": "sematext/browser-sdk", "max_issues_repo_issues_event_min_datetime": "2021-04-19T07:17:29.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-28T22:23:43.000Z", "max_forks_repo_path": "src/commands/RouteChangeCommand.js", "max_forks_repo_name": "sematext/browser-sdk", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 7, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 25.7837837838, "max_line_length": 78, "alphanum_fraction": 0.680293501}
/* @flow */
import type { Command, CommandContext } from './types';
import { informOnRouteChangeListeners } from '../pageload';

class RouteChangeCommand implements Command {
  context: CommandContext;

  constructor(context: CommandContext) {
    this.context = context;
  }

  supported() {
    const { scope } = this.context;
    return scope.performance && scope.performance.timing;
  }

  /**
   * Route change means that the developer is giving us a hint that the Single
   * Page App has navigated to a different route. The goal now is to collect
   * all related network resources that were loaded as a side-effect of
   * navigating to this route.
   */
  execute(args: Array<any>) {
    if (typeof args[0] !== 'string') {
      throw new Error('command requires one argument: pathname');
    }

    if (!this.supported()) {
      return;
    }

    informOnRouteChangeListeners(args[0], this.context);
  }
}

export default RouteChangeCommand;
