mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor(core): remove several private utils and APIs (#48357)
These APIs are no longer used. PR Close #48357
This commit is contained in:
committed by
Andrew Kushnir
parent
e7feaa1412
commit
cf51690341
@@ -73,12 +73,6 @@ export function assertHasParent(tNode: TNode|null) {
|
||||
assertDefined(tNode!.parent, 'currentTNode should have a parent');
|
||||
}
|
||||
|
||||
export function assertDataNext(lView: LView, index: number, arr?: any[]) {
|
||||
if (arr == null) arr = lView;
|
||||
assertEqual(
|
||||
arr.length, index, `index ${index} expected to be at the end of arr (length ${arr.length})`);
|
||||
}
|
||||
|
||||
export function assertLContainer(value: any): asserts value is LContainer {
|
||||
assertDefined(value, 'LContainer must be defined');
|
||||
assertEqual(isLContainer(value), true, 'Expecting LContainer');
|
||||
|
||||
@@ -7,12 +7,4 @@
|
||||
*/
|
||||
|
||||
export const SVG_NAMESPACE = 'svg';
|
||||
export const SVG_NAMESPACE_URI = 'http://www.w3.org/2000/svg';
|
||||
export const MATH_ML_NAMESPACE = 'math';
|
||||
export const MATH_ML_NAMESPACE_URI = 'http://www.w3.org/1998/MathML/';
|
||||
|
||||
export function getNamespaceUri(namespace: string): string|null {
|
||||
const name = namespace.toLowerCase();
|
||||
return name === SVG_NAMESPACE ? SVG_NAMESPACE_URI :
|
||||
(name === MATH_ML_NAMESPACE ? MATH_ML_NAMESPACE_URI : null);
|
||||
}
|
||||
|
||||
@@ -338,9 +338,6 @@ export function isCurrentTNodeParent(): boolean {
|
||||
export function setCurrentTNodeAsNotParent(): void {
|
||||
instructionState.lFrame.isParent = false;
|
||||
}
|
||||
export function setCurrentTNodeAsParent(): void {
|
||||
instructionState.lFrame.isParent = true;
|
||||
}
|
||||
|
||||
export function getContextLView(): LView {
|
||||
const contextLView = instructionState.lFrame.contextLView;
|
||||
|
||||
@@ -58,20 +58,6 @@ export function unwrapLView(value: RNode|LView|LContainer): LView|null {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `LContainer` or `null` if not found.
|
||||
* @param value wrapped value of `RNode`, `LView`, `LContainer`
|
||||
*/
|
||||
export function unwrapLContainer(value: RNode|LView|LContainer): LContainer|null {
|
||||
while (Array.isArray(value)) {
|
||||
// This check is same as `isLContainer()` but we don't call at as we don't want to call
|
||||
// `Array.isArray()` twice and give JITer more work for inlining.
|
||||
if (value[TYPE] === true) return value as LContainer;
|
||||
value = value[HOST] as any;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an element value from the provided `viewData`, by unwrapping
|
||||
* from any containers, component views, or style contexts.
|
||||
|
||||
@@ -8,18 +8,6 @@
|
||||
|
||||
import {assertEqual, assertLessThanOrEqual} from './assert';
|
||||
|
||||
/**
|
||||
* Equivalent to ES6 spread, add each item to an array.
|
||||
*
|
||||
* @param items The items to add
|
||||
* @param arr The array to which you want to add the items
|
||||
*/
|
||||
export function addAllToArray(items: any[], arr: any[]) {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
arr.push(items[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the contents of two arrays is identical
|
||||
*
|
||||
@@ -180,48 +168,6 @@ export function arrayInsert2(array: any[], index: number, value1: any, value2: a
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a `value` into an `array` so that the array remains sorted.
|
||||
*
|
||||
* NOTE:
|
||||
* - Duplicates are not allowed, and are ignored.
|
||||
* - This uses binary search algorithm for fast inserts.
|
||||
*
|
||||
* @param array A sorted array to insert into.
|
||||
* @param value The value to insert.
|
||||
* @returns index of the inserted value.
|
||||
*/
|
||||
export function arrayInsertSorted(array: string[], value: string): number {
|
||||
let index = arrayIndexOfSorted(array, value);
|
||||
if (index < 0) {
|
||||
// if we did not find it insert it.
|
||||
index = ~index;
|
||||
arrayInsert(array, index, value);
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove `value` from a sorted `array`.
|
||||
*
|
||||
* NOTE:
|
||||
* - This uses binary search algorithm for fast removals.
|
||||
*
|
||||
* @param array A sorted array to remove from.
|
||||
* @param value The value to remove.
|
||||
* @returns index of the removed value.
|
||||
* - positive index if value found and removed.
|
||||
* - negative index if value not found. (`~index` to get the value where it should have been
|
||||
* inserted)
|
||||
*/
|
||||
export function arrayRemoveSorted(array: string[], value: string): number {
|
||||
const index = arrayIndexOfSorted(array, value);
|
||||
if (index >= 0) {
|
||||
arraySplice(array, index, 1);
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an index of an `value` in a sorted `array`.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {arrayIndexOfSorted, arrayInsert, arrayInsert2, arrayInsertSorted, arrayRemoveSorted, arraySplice, flatten, KeyValueArray, keyValueArrayDelete, keyValueArrayGet, keyValueArrayIndexOf, keyValueArraySet} from '../../src/util/array_utils';
|
||||
import {arrayIndexOfSorted, arrayInsert, arrayInsert2, arraySplice, flatten, KeyValueArray, keyValueArrayDelete, keyValueArrayGet, keyValueArrayIndexOf, keyValueArraySet} from '../../src/util/array_utils';
|
||||
|
||||
describe('array_utils', () => {
|
||||
describe('flatten', () => {
|
||||
@@ -76,59 +76,6 @@ describe('array_utils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('arrayInsertSorted', () => {
|
||||
it('should insert items don\'t allow duplicates', () => {
|
||||
let a;
|
||||
a = ['a', 'c', 'e', 'g', 'i'];
|
||||
expect(arrayInsertSorted(a, 'a')).toEqual(0);
|
||||
expect(a).toEqual(['a', 'c', 'e', 'g', 'i']);
|
||||
|
||||
a = ['a', 'c', 'e', 'g', 'i'];
|
||||
expect(arrayInsertSorted(a, 'b')).toEqual(1);
|
||||
expect(a).toEqual(['a', 'b', 'c', 'e', 'g', 'i']);
|
||||
|
||||
a = ['a', 'c', 'e', 'g', 'i'];
|
||||
expect(arrayInsertSorted(a, 'c')).toEqual(1);
|
||||
expect(a).toEqual(['a', 'c', 'e', 'g', 'i']);
|
||||
|
||||
a = ['a', 'c', 'e', 'g', 'i'];
|
||||
expect(arrayInsertSorted(a, 'd')).toEqual(2);
|
||||
expect(a).toEqual(['a', 'c', 'd', 'e', 'g', 'i']);
|
||||
|
||||
a = ['a', 'c', 'e', 'g', 'i'];
|
||||
expect(arrayInsertSorted(a, 'e')).toEqual(2);
|
||||
expect(a).toEqual(['a', 'c', 'e', 'g', 'i']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('arrayRemoveSorted', () => {
|
||||
it('should remove items', () => {
|
||||
let a;
|
||||
a = ['a', 'b', 'c', 'd', 'e'];
|
||||
expect(arrayRemoveSorted(a, 'a')).toEqual(0);
|
||||
expect(a).toEqual(['b', 'c', 'd', 'e']);
|
||||
|
||||
a = ['a', 'b', 'c', 'd', 'e'];
|
||||
expect(arrayRemoveSorted(a, 'b')).toEqual(1);
|
||||
expect(a).toEqual(['a', 'c', 'd', 'e']);
|
||||
|
||||
a = ['a', 'b', 'c', 'd', 'e'];
|
||||
expect(arrayRemoveSorted(a, 'c')).toEqual(2);
|
||||
expect(a).toEqual(['a', 'b', 'd', 'e']);
|
||||
|
||||
a = ['a', 'b', 'c', 'd', 'e'];
|
||||
expect(arrayRemoveSorted(a, 'd')).toEqual(3);
|
||||
expect(a).toEqual(['a', 'b', 'c', 'e']);
|
||||
|
||||
a = ['a', 'b', 'c', 'd', 'e'];
|
||||
expect(arrayRemoveSorted(a, 'e')).toEqual(4);
|
||||
expect(a).toEqual(['a', 'b', 'c', 'd']);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('arrayIndexOfSorted', () => {
|
||||
it('should get index of', () => {
|
||||
const a = ['a', 'b', 'c', 'd', 'e'];
|
||||
|
||||
Reference in New Issue
Block a user