<commit_before>/**
 * This is a fork of the Location service in Angular 2's Component Router.
 * It exposes location updates as a BehaviorSubject, letting the router
 * observe location changes.
 */
import { BehaviorSubject } from 'rxjs/subject/BehaviorSubject';
import { Subscriber } from 'rxjs/Subscriber';
import { LocationStrategy } from 'angular2/src/router/location/location_strategy';
import { UrlChangeEvent, PlatformLocation } from 'angular2/src/router/location/platform_location';
import { BrowserPlatformLocation } from 'angular2/src/router/location/browser_platform_location';
import { Injectable, Inject, Provider, provide } from 'angular2/core';

export interface LocationChange {
  url: string;
  pop: boolean;
  type: string;
}

/**
 * `Location` is a service that applications can use to interact with a browser's URL.
 * Depending on which {@link LocationStrategy} is used, `Location` will either persist
 * to the URL's path or the URL's hash segment.
 *
 * Note: it's better to use {@link Router#navigate} service to trigger route changes. Use
 * `Location` only if you need to interact with or create normalized URLs outside of
 * routing.
 *
 * `Location` is responsible for normalizing the URL against the application's base href.
 * A normalized URL is absolute from the URL host, includes the application's base href, and has no
 * trailing slash:
 * - `/my/app/user/123` is normalized
 * - `my/app/user/123` **is not** normalized
 * - `/my/app/user/123/` **is not** normalized
 *
 * ### Example
 *
 * ```
 * import {Component} from 'angular2/core';
 * import {
 *   ROUTER_DIRECTIVES,
 *   ROUTER_PROVIDERS,
 *   RouteConfig,
 *   Location
 * } from 'angular2/router';
 *
 * @Component({directives: [ROUTER_DIRECTIVES]})
 * @RouteConfig([
 *  {...},
 * ])
 * class AppCmp {
 *   constructor(location: Location) {
 *     location.go('/foo');
 *   }
 * }
 *
 * bootstrap(AppCmp, [ROUTER_PROVIDERS]);
 * ```
 */
@Injectable()
export class Location extends BehaviorSubject<LocationChange>{
  private _baseHref: string;

  constructor(public platformStrategy: LocationStrategy) {
    super(undefined);

    platformStrategy.onPopState(event => this._update(true, event.type));

    var browserBaseHref = this.platformStrategy.getBaseHref();
    this._baseHref = stripTrailingSlash(stripIndexHtml(browserBaseHref));
    this._update();
  }

  private _update(pop: boolean = false, type = 'push') {
    this.next({ url: this.path(), pop, type });
  }

  /**
   * Returns the normalized URL path.
   */
  path(): string {
    return this.normalize(this.platformStrategy.path());
  }

  /**<commit_msg>feat(Location): Updated location to be a ReplaySubject instead of BehaviorSubject<commit_after>/**
 * This is a fork of the Location service in Angular 2's Component Router.
 * It exposes location updates as a BehaviorSubject, letting the router
 * observe location changes.
 */
import { ReplaySubject } from 'rxjs/subject/ReplaySubject';
import { Subscriber } from 'rxjs/Subscriber';
import { LocationStrategy } from 'angular2/src/router/location/location_strategy';
import { UrlChangeEvent, PlatformLocation } from 'angular2/src/router/location/platform_location';
import { BrowserPlatformLocation } from 'angular2/src/router/location/browser_platform_location';
import { Injectable, Inject, Provider, provide } from 'angular2/core';

export interface LocationChange {
  url: string;
  pop: boolean;
  type: string;
}

/**
 * `Location` is a service that applications can use to interact with a browser's URL.
 * Depending on which {@link LocationStrategy} is used, `Location` will either persist
 * to the URL's path or the URL's hash segment.
 *
 * Note: it's better to use {@link Router#navigate} service to trigger route changes. Use
 * `Location` only if you need to interact with or create normalized URLs outside of
 * routing.
 *
 * `Location` is responsible for normalizing the URL against the application's base href.
 * A normalized URL is absolute from the URL host, includes the application's base href, and has no
 * trailing slash:
 * - `/my/app/user/123` is normalized
 * - `my/app/user/123` **is not** normalized
 * - `/my/app/user/123/` **is not** normalized
 *
 * ### Example
 *
 * ```
 * import {Component} from 'angular2/core';
 * import {
 *   ROUTER_DIRECTIVES,
 *   ROUTER_PROVIDERS,
 *   RouteConfig,
 *   Location
 * } from 'angular2/router';
 *
 * @Component({directives: [ROUTER_DIRECTIVES]})
 * @RouteConfig([
 *  {...},
 * ])
 * class AppCmp {
 *   constructor(location: Location) {
 *     location.go('/foo');
 *   }
 * }
 *
 * bootstrap(AppCmp, [ROUTER_PROVIDERS]);
 * ```
 */
@Injectable()
export class Location extends ReplaySubject<LocationChange>{
  private _baseHref: string;

  constructor(public platformStrategy: LocationStrategy) {
    super(1);

    platformStrategy.onPopState(event => this._update(true, event.type));

    var browserBaseHref = this.platformStrategy.getBaseHref();
    this._baseHref = stripTrailingSlash(stripIndexHtml(browserBaseHref));
    this._update();
  }

  private _update(pop: boolean = false, type = 'push') {
    this.next({ url: this.path(), pop, type });
  }

  /**
   * Returns the normalized URL path.
   */
  path(): string {
    return this.normalize(this.platformStrategy.path());
  }

  /**
{'fraction_non_alphanumeric': 0.1245275888133031, 'fraction_numerical': 0.006235827664399093, 'mean_word_length': 4.13883495145631, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7271043', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1544, 'n_words': 473}