<commit_before>/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
import {Injectable, Provider} from '@angular/core';

import {of} from 'rxjs';

import {navigated, NavigatedPayload} from './actions';
import {Location} from './location';
import {Route, RouteKind} from './types';

/** @typehack */ import * as _typeHackModels from '@ngrx/store/src/models';
/** @typehack */ import * as _typeHackRxjs from 'rxjs';
import {getRouteId} from './internal_utils';

export function buildRoute(routeOverride: Partial<Route> = {}): Route {
  return {
    routeKind: RouteKind.EXPERIMENTS,
    pathname: '/experiments',
    params: {},
    queryParams: [],
    navigationOptions: {
      replaceState: false,
    },
    ...routeOverride,
  };
}

export function buildCompareRoute(
  aliasAndExperimentIds: string[],
  routeOverride: Partial<Route> = {}
): Route {
  return {
    routeKind: RouteKind.COMPARE_EXPERIMENT,
    pathname: '/campare',
    params: {experimentIds: aliasAndExperimentIds.join(',')},
    queryParams: [],
    navigationOptions: {
      replaceState: false,
    },
    ...routeOverride,
  };
}

export function buildNavigatedAction(overrides?: Partial<NavigatedPayload>) {
  return navigated({
    before: null,
    after: buildRoute(),
    beforeNamespaceId: overrides?.before ? 'namespace' : null,
    afterNamespaceId: 'namespace',
    ...overrides,
  });
}

// TODO(bdubois): Remove once all internal callers have been migrated to
// buildNavigatedAction.
/**
 * @deprecated Use buildNavigateAction instead.
 */
export function buildNavigatedActionFull(
  overrides?: Partial<NavigatedPayload>
) {
  return buildNavigatedAction(overrides);
}

/**
 * A navigation that corresponds to a change in route id (new route context)
 * will be created.
 */
export function buildNavigatedToNewRouteIdAction() {
  const beforeRoute = buildRoute({
    routeKind: RouteKind.EXPERIMENT,
    params: {experimentId: 'abc'},
  });
  const afterRoute = buildRoute({
    routeKind: RouteKind.EXPERIMENT,
    params: {experimentId: 'xyz'},
  });
  return navigated({
    before: beforeRoute,
    after: afterRoute,
    beforeNamespaceId: getRouteId(beforeRoute.routeKind, beforeRoute.params),
    afterNamespaceId: getRouteId(afterRoute.routeKind, afterRoute.params),
  });
}

@Injectable()
export class TestableLocation extends Location {
  override getSearch() {
    return [];
  }

  override getHash() {
    return '';
  }

  override getPath() {
    return '/is/cool/';
  }

  override replaceState(path: string) {}

  override pushState(path: string) {}

  override onPopState() {
    return of({
      pathname: '/is/cool/',
    });
  }
}

export function provideLocationTesting(): Provider {
  return [
    TestableLocation,
    {
      provide: Location,
      useExisting: TestableLocation,
    },
  ];
}
<commit_msg>[time-namespaced state] Remove buildNavigatedActionFull. (#5441)<commit_after>/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
import {Injectable, Provider} from '@angular/core';

import {of} from 'rxjs';

import {navigated, NavigatedPayload} from './actions';
import {Location} from './location';
import {Route, RouteKind} from './types';

/** @typehack */ import * as _typeHackModels from '@ngrx/store/src/models';
/** @typehack */ import * as _typeHackRxjs from 'rxjs';
import {getRouteId} from './internal_utils';

export function buildRoute(routeOverride: Partial<Route> = {}): Route {
  return {
    routeKind: RouteKind.EXPERIMENTS,
    pathname: '/experiments',
    params: {},
    queryParams: [],
    navigationOptions: {
      replaceState: false,
    },
    ...routeOverride,
  };
}

export function buildCompareRoute(
  aliasAndExperimentIds: string[],
  routeOverride: Partial<Route> = {}
): Route {
  return {
    routeKind: RouteKind.COMPARE_EXPERIMENT,
    pathname: '/campare',
    params: {experimentIds: aliasAndExperimentIds.join(',')},
    queryParams: [],
    navigationOptions: {
      replaceState: false,
    },
    ...routeOverride,
  };
}

export function buildNavigatedAction(overrides?: Partial<NavigatedPayload>) {
  return navigated({
    before: null,
    after: buildRoute(),
    beforeNamespaceId: overrides?.before ? 'namespace' : null,
    afterNamespaceId: 'namespace',
    ...overrides,
  });
}

/**
 * A navigation that corresponds to a change in route id (new route context)
 * will be created.
 */
export function buildNavigatedToNewRouteIdAction() {
  const beforeRoute = buildRoute({
    routeKind: RouteKind.EXPERIMENT,
    params: {experimentId: 'abc'},
  });
  const afterRoute = buildRoute({
    routeKind: RouteKind.EXPERIMENT,
    params: {experimentId: 'xyz'},
  });
  return navigated({
    before: beforeRoute,
    after: afterRoute,
    beforeNamespaceId: getRouteId(beforeRoute.routeKind, beforeRoute.params),
    afterNamespaceId: getRouteId(afterRoute.routeKind, afterRoute.params),
  });
}

@Injectable()
export class TestableLocation extends Location {
  override getSearch() {
    return [];
  }

  override getHash() {
    return '';
  }

  override getPath() {
    return '/is/cool/';
  }

  override replaceState(path: string) {}

  override pushState(path: string) {}

  override onPopState() {
    return of({
      pathname: '/is/cool/',
    });
  }
}

export function provideLocationTesting(): Provider {
  return [
    TestableLocation,
    {
      provide: Location,
      useExisting: TestableLocation,
    },
  ];
}

{'fraction_non_alphanumeric': 0.13868832731648617, 'fraction_numerical': 0.0030084235860409147, 'mean_word_length': 4.0143288084464555, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5095995', 'n_tokens_mistral': 1937, 'n_tokens_neox': 1879, 'n_words': 556}