<commit_before>import isObject from 'lodash/lang/isObject';
import isEqual from 'lodash/lang/isEqual';
import cloneDeep from 'lodash/lang/cloneDeep';

import transform from 'lodash/object/transform';

import Url from '../url';

import Scope from './services/scope';
import Injector from './services/injector';

let _scope = Symbol('scope');
let _state = Symbol('state');

export default class AngularUrl extends Url {
  constructor(pattern, struct) {
    super(pattern, struct);

    this[_state] = {};
    this[_scope] = null;
  }

  // $scope is using for url.watch() method
  attachScope($scope) {
    this[_scope] = $scope;
  }

  hasScope() {
    return !!this[_scope];
  }

  parse() {
    let $location = Injector.get('$location');
    let decoded = this.decode($location.$$url);

    this.cacheParams(decoded);

    return decoded;
  }

  go(params, options) {
    let $location = Injector.get('$location');

    if (options) {
      let $rootScope = Injector.get('$rootScope');

      let unsubscribe = $rootScope.$on('$routeUpdate', event => {

        Object.assign(event, {
          $valentEvent: options
        });

        unsubscribe();
      });
    }

    let url = this.stringify(params);
    $location.url(url);
  }

  redirect(params = {}) {
    if (!isObject(params)) {
      throw new Error('params should be an object');
    }

    let url = this.stringify(params);
    let $window = Injector.get('$window');

    $window.location.href = url;
  }

  stringify(params) {
    let url = super.stringify(params);

    let $browser = Injector.get('$browser');
    let base = $browser.baseHref();

    return base ? url.replace(/^\//, '') : url;
  }

  watch(callback) {
    let $scope = this[_scope];

    return $scope.$on('$routeUpdate', (event) => {
      let valentEvent = event.$valentEvent;

      let params = this.parse();

      let diff = transform(params, (result, n, key) => {
        // TODO: use cached params instead of state
        let state = this[_state][key];

        if (!isEqual(n, state)) {
          result[key] = n;
        }
      });

      this[_state] = cloneDeep(params);
<commit_msg>AngularUrl - add reload method<commit_after>import isObject from 'lodash/lang/isObject';
import isEqual from 'lodash/lang/isEqual';
import cloneDeep from 'lodash/lang/cloneDeep';

import transform from 'lodash/object/transform';

import Url from '../url';

import Scope from './services/scope';
import Injector from './services/injector';

let _scope = Symbol('scope');
let _state = Symbol('state');

export default class AngularUrl extends Url {
  constructor(pattern, struct) {
    super(pattern, struct);

    this[_state] = {};
    this[_scope] = null;
  }

  // $scope is using for url.watch() method
  attachScope($scope) {
    this[_scope] = $scope;
  }

  hasScope() {
    return !!this[_scope];
  }

  parse() {
    let $location = Injector.get('$location');
    let decoded = this.decode($location.$$url);

    this.cacheParams(decoded);

    return decoded;
  }

  go(params, options) {
    let $location = Injector.get('$location');

    if (options) {
      let $rootScope = Injector.get('$rootScope');

      let unsubscribe = $rootScope.$on('$routeUpdate', event => {

        Object.assign(event, {
          $valentEvent: options
        });

        unsubscribe();
      });
    }

    let url = this.stringify(params);
    $location.url(url);
  }

  redirect(params = {}) {
    if (!isObject(params)) {
      throw new Error('params should be an object');
    }

    let url = this.stringify(params);
    let $window = Injector.get('$window');

    $window.location.href = url;
  }

  reload() {
    let $route = Injector.get('$route');
    $route.reload();
  }

  stringify(params) {
    let url = super.stringify(params);

    let $browser = Injector.get('$browser');
    let base = $browser.baseHref();

    return base ? url.replace(/^\//, '') : url;
  }

  watch(callback) {
    let $scope = this[_scope];

    return $scope.$on('$routeUpdate', (event) => {
      let valentEvent = event.$valentEvent;

      let params = this.parse();

      let diff = transform(params, (result, n, key) => {
        // TODO: use cached params instead of state
        let state = this[_state][key];

        if (!isEqual(n, state)) {
          result[key] = n;
        }
      });

      this[_state] = cloneDeep(params);

{'fraction_non_alphanumeric': 0.15777421570872452, 'fraction_numerical': 0.0, 'mean_word_length': 2.79496090356212, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4409977', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1352, 'n_words': 326}