refactor(): use const and let instead of var
This commit is contained in:

committed by
Victor Berchet

parent
73593d4bf3
commit
77ee27c59e
@ -28,12 +28,12 @@ class ComplexItem {
|
||||
export function main() {
|
||||
describe('iterable differ', function() {
|
||||
describe('DefaultIterableDiffer', function() {
|
||||
var differ: any /** TODO #9100 */;
|
||||
let differ: any /** TODO #9100 */;
|
||||
|
||||
beforeEach(() => { differ = new DefaultIterableDiffer(); });
|
||||
|
||||
it('should support list and iterables', () => {
|
||||
var f = new DefaultIterableDifferFactory();
|
||||
const f = new DefaultIterableDifferFactory();
|
||||
expect(f.supports([])).toBeTruthy();
|
||||
expect(f.supports(new TestIterable())).toBeTruthy();
|
||||
expect(f.supports(new Map())).toBeFalsy();
|
||||
@ -41,7 +41,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should support iterables', () => {
|
||||
let l = new TestIterable();
|
||||
const l = new TestIterable();
|
||||
|
||||
differ.check(l);
|
||||
expect(differ.toString()).toEqual(iterableChangesAsString({collection: []}));
|
||||
@ -64,7 +64,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should detect additions', () => {
|
||||
let l: any[] /** TODO #9100 */ = [];
|
||||
const l: any[] /** TODO #9100 */ = [];
|
||||
differ.check(l);
|
||||
expect(differ.toString()).toEqual(iterableChangesAsString({collection: []}));
|
||||
|
||||
@ -106,7 +106,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should handle swapping element', () => {
|
||||
let l = [1, 2];
|
||||
const l = [1, 2];
|
||||
differ.check(l);
|
||||
|
||||
l.length = 0;
|
||||
@ -121,7 +121,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should handle incremental swapping element', () => {
|
||||
let l = ['a', 'b', 'c'];
|
||||
const l = ['a', 'b', 'c'];
|
||||
differ.check(l);
|
||||
|
||||
l.splice(1, 1);
|
||||
@ -144,7 +144,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should detect changes in list', () => {
|
||||
let l: any[] /** TODO #9100 */ = [];
|
||||
const l: any[] /** TODO #9100 */ = [];
|
||||
differ.check(l);
|
||||
|
||||
l.push('a');
|
||||
@ -193,11 +193,11 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should test string by value rather than by reference (Dart)', () => {
|
||||
let l = ['a', 'boo'];
|
||||
const l = ['a', 'boo'];
|
||||
differ.check(l);
|
||||
|
||||
var b = 'b';
|
||||
var oo = 'oo';
|
||||
const b = 'b';
|
||||
const oo = 'oo';
|
||||
l[1] = b + oo;
|
||||
differ.check(l);
|
||||
expect(differ.toString())
|
||||
@ -205,7 +205,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should ignore [NaN] != [NaN] (JS)', () => {
|
||||
let l = [NaN];
|
||||
const l = [NaN];
|
||||
differ.check(l);
|
||||
differ.check(l);
|
||||
expect(differ.toString())
|
||||
@ -213,7 +213,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should detect [NaN] moves', () => {
|
||||
let l: any[] = [NaN, NaN];
|
||||
const l: any[] = [NaN, NaN];
|
||||
differ.check(l);
|
||||
|
||||
l.unshift('foo');
|
||||
@ -227,7 +227,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should remove and add same item', () => {
|
||||
let l = ['a', 'b', 'c'];
|
||||
const l = ['a', 'b', 'c'];
|
||||
differ.check(l);
|
||||
|
||||
l.splice(1, 1);
|
||||
@ -251,7 +251,7 @@ export function main() {
|
||||
|
||||
|
||||
it('should support duplicates', () => {
|
||||
let l = ['a', 'a', 'a', 'b', 'b'];
|
||||
const l = ['a', 'a', 'a', 'b', 'b'];
|
||||
differ.check(l);
|
||||
|
||||
l.splice(0, 1);
|
||||
@ -265,7 +265,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should support insertions/moves', () => {
|
||||
let l = ['a', 'a', 'b', 'b'];
|
||||
const l = ['a', 'a', 'b', 'b'];
|
||||
differ.check(l);
|
||||
|
||||
l.splice(0, 0, 'b');
|
||||
@ -279,7 +279,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should not report unnecessary moves', () => {
|
||||
let l = ['a', 'b', 'c'];
|
||||
const l = ['a', 'b', 'c'];
|
||||
differ.check(l);
|
||||
|
||||
l.length = 0;
|
||||
@ -296,8 +296,8 @@ export function main() {
|
||||
|
||||
describe('forEachOperation', () => {
|
||||
function stringifyItemChange(record: any, p: number, c: number, originalIndex: number) {
|
||||
var suffix = originalIndex == null ? '' : ' [o=' + originalIndex + ']';
|
||||
var value = record.item;
|
||||
const suffix = originalIndex == null ? '' : ' [o=' + originalIndex + ']';
|
||||
const value = record.item;
|
||||
if (record.currentIndex == null) {
|
||||
return `REMOVE ${value} (${p} -> VOID)${suffix}`;
|
||||
} else if (record.previousIndex == null) {
|
||||
@ -309,7 +309,7 @@ export function main() {
|
||||
|
||||
function modifyArrayUsingOperation(
|
||||
arr: number[], endData: any[], prev: number, next: number) {
|
||||
var value: number = null;
|
||||
let value: number = null;
|
||||
if (prev == null) {
|
||||
value = endData[next];
|
||||
arr.splice(next, 0, value);
|
||||
@ -326,15 +326,15 @@ export function main() {
|
||||
|
||||
it('should trigger a series of insert/move/remove changes for inputs that have been diffed',
|
||||
() => {
|
||||
var startData = [0, 1, 2, 3, 4, 5];
|
||||
var endData = [6, 2, 7, 0, 4, 8];
|
||||
const startData = [0, 1, 2, 3, 4, 5];
|
||||
const endData = [6, 2, 7, 0, 4, 8];
|
||||
|
||||
differ = differ.diff(startData);
|
||||
differ = differ.diff(endData);
|
||||
|
||||
var operations: string[] = [];
|
||||
const operations: string[] = [];
|
||||
differ.forEachOperation((item: any, prev: number, next: number) => {
|
||||
var value = modifyArrayUsingOperation(startData, endData, prev, next);
|
||||
const value = modifyArrayUsingOperation(startData, endData, prev, next);
|
||||
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
|
||||
});
|
||||
|
||||
@ -349,15 +349,15 @@ export function main() {
|
||||
|
||||
it('should consider inserting/removing/moving items with respect to items that have not moved at all',
|
||||
() => {
|
||||
var startData = [0, 1, 2, 3];
|
||||
var endData = [2, 1];
|
||||
const startData = [0, 1, 2, 3];
|
||||
const endData = [2, 1];
|
||||
|
||||
differ = differ.diff(startData);
|
||||
differ = differ.diff(endData);
|
||||
|
||||
var operations: string[] = [];
|
||||
const operations: string[] = [];
|
||||
differ.forEachOperation((item: any, prev: number, next: number) => {
|
||||
var value = modifyArrayUsingOperation(startData, endData, prev, next);
|
||||
const value = modifyArrayUsingOperation(startData, endData, prev, next);
|
||||
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
|
||||
});
|
||||
|
||||
@ -369,15 +369,15 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should be able to manage operations within a criss/cross of move operations', () => {
|
||||
var startData = [1, 2, 3, 4, 5, 6];
|
||||
var endData = [3, 6, 4, 9, 1, 2];
|
||||
const startData = [1, 2, 3, 4, 5, 6];
|
||||
const endData = [3, 6, 4, 9, 1, 2];
|
||||
|
||||
differ = differ.diff(startData);
|
||||
differ = differ.diff(endData);
|
||||
|
||||
var operations: string[] = [];
|
||||
const operations: string[] = [];
|
||||
differ.forEachOperation((item: any, prev: number, next: number) => {
|
||||
var value = modifyArrayUsingOperation(startData, endData, prev, next);
|
||||
const value = modifyArrayUsingOperation(startData, endData, prev, next);
|
||||
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
|
||||
});
|
||||
|
||||
@ -390,15 +390,15 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should skip moves for multiple nodes that have not moved', () => {
|
||||
var startData = [0, 1, 2, 3, 4];
|
||||
var endData = [4, 1, 2, 3, 0, 5];
|
||||
const startData = [0, 1, 2, 3, 4];
|
||||
const endData = [4, 1, 2, 3, 0, 5];
|
||||
|
||||
differ = differ.diff(startData);
|
||||
differ = differ.diff(endData);
|
||||
|
||||
var operations: string[] = [];
|
||||
const operations: string[] = [];
|
||||
differ.forEachOperation((item: any, prev: number, next: number) => {
|
||||
var value = modifyArrayUsingOperation(startData, endData, prev, next);
|
||||
const value = modifyArrayUsingOperation(startData, endData, prev, next);
|
||||
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
|
||||
});
|
||||
|
||||
@ -411,15 +411,15 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should not fail', () => {
|
||||
var startData = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
||||
var endData = [10, 11, 1, 5, 7, 8, 0, 5, 3, 6];
|
||||
const startData = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
||||
const endData = [10, 11, 1, 5, 7, 8, 0, 5, 3, 6];
|
||||
|
||||
differ = differ.diff(startData);
|
||||
differ = differ.diff(endData);
|
||||
|
||||
var operations: string[] = [];
|
||||
const operations: string[] = [];
|
||||
differ.forEachOperation((item: any, prev: number, next: number) => {
|
||||
var value = modifyArrayUsingOperation(startData, endData, prev, next);
|
||||
const value = modifyArrayUsingOperation(startData, endData, prev, next);
|
||||
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
|
||||
});
|
||||
|
||||
@ -437,15 +437,15 @@ export function main() {
|
||||
() => {
|
||||
differ = new DefaultIterableDiffer((index: number) => index);
|
||||
|
||||
var startData = [1, 2, 3, 4];
|
||||
var endData = [5, 6, 7, 8];
|
||||
const startData = [1, 2, 3, 4];
|
||||
const endData = [5, 6, 7, 8];
|
||||
|
||||
differ = differ.diff(startData);
|
||||
differ = differ.diff(endData);
|
||||
|
||||
var operations: string[] = [];
|
||||
const operations: string[] = [];
|
||||
differ.forEachOperation((item: any, prev: number, next: number) => {
|
||||
var value = modifyArrayUsingOperation(startData, endData, prev, next);
|
||||
const value = modifyArrayUsingOperation(startData, endData, prev, next);
|
||||
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
|
||||
});
|
||||
|
||||
@ -478,11 +478,11 @@ export function main() {
|
||||
});
|
||||
|
||||
describe('trackBy function by id', function() {
|
||||
var differ: any /** TODO #9100 */;
|
||||
let differ: any /** TODO #9100 */;
|
||||
|
||||
var trackByItemId = (index: number, item: any): any => item.id;
|
||||
const trackByItemId = (index: number, item: any): any => item.id;
|
||||
|
||||
var buildItemList = (list: string[]) => list.map((val) => new ItemWithId(val));
|
||||
const buildItemList = (list: string[]) => list.map((val) => new ItemWithId(val));
|
||||
|
||||
beforeEach(() => { differ = new DefaultIterableDiffer(trackByItemId); });
|
||||
|
||||
@ -553,7 +553,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should track removals normally', () => {
|
||||
let l = buildItemList(['a', 'b', 'c']);
|
||||
const l = buildItemList(['a', 'b', 'c']);
|
||||
differ.check(l);
|
||||
|
||||
l.splice(2, 1);
|
||||
@ -566,9 +566,9 @@ export function main() {
|
||||
});
|
||||
});
|
||||
describe('trackBy function by index', function() {
|
||||
var differ: any /** TODO #9100 */;
|
||||
let differ: any /** TODO #9100 */;
|
||||
|
||||
var trackByIndex = (index: number, item: any): number => index;
|
||||
const trackByIndex = (index: number, item: any): number => index;
|
||||
|
||||
beforeEach(() => { differ = new DefaultIterableDiffer(trackByIndex); });
|
||||
|
||||
|
@ -14,8 +14,8 @@ import {kvChangesAsString} from '../../change_detection/util';
|
||||
export function main() {
|
||||
describe('keyvalue differ', function() {
|
||||
describe('DefaultKeyValueDiffer', function() {
|
||||
var differ: DefaultKeyValueDiffer;
|
||||
var m: Map<any, any>;
|
||||
let differ: DefaultKeyValueDiffer;
|
||||
let m: Map<any, any>;
|
||||
|
||||
beforeEach(() => {
|
||||
differ = new DefaultKeyValueDiffer();
|
||||
@ -55,7 +55,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should expose previous and current value', () => {
|
||||
var previous: any /** TODO #9100 */, current: any /** TODO #9100 */;
|
||||
let previous: any /** TODO #9100 */, current: any /** TODO #9100 */;
|
||||
|
||||
m.set(1, 10);
|
||||
differ.check(m);
|
||||
@ -137,7 +137,7 @@ export function main() {
|
||||
|
||||
describe('JsObject changes', () => {
|
||||
it('should support JS Object', () => {
|
||||
var f = new DefaultKeyValueDifferFactory();
|
||||
const f = new DefaultKeyValueDifferFactory();
|
||||
expect(f.supports({})).toBeTruthy();
|
||||
expect(f.supports('not supported')).toBeFalsy();
|
||||
expect(f.supports(0)).toBeFalsy();
|
||||
|
@ -14,9 +14,9 @@ import {SpyIterableDifferFactory} from '../../spies';
|
||||
|
||||
export function main() {
|
||||
describe('IterableDiffers', function() {
|
||||
var factory1: any /** TODO #9100 */;
|
||||
var factory2: any /** TODO #9100 */;
|
||||
var factory3: any /** TODO #9100 */;
|
||||
let factory1: any /** TODO #9100 */;
|
||||
let factory2: any /** TODO #9100 */;
|
||||
let factory3: any /** TODO #9100 */;
|
||||
|
||||
beforeEach(() => {
|
||||
factory1 = new SpyIterableDifferFactory();
|
||||
@ -25,7 +25,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should throw when no suitable implementation found', () => {
|
||||
var differs = new IterableDiffers([]);
|
||||
const differs = new IterableDiffers([]);
|
||||
expect(() => differs.find('some object'))
|
||||
.toThrowError(/Cannot find a differ supporting object 'some object'/);
|
||||
});
|
||||
@ -35,7 +35,7 @@ export function main() {
|
||||
factory2.spy('supports').and.returnValue(true);
|
||||
factory3.spy('supports').and.returnValue(true);
|
||||
|
||||
var differs = IterableDiffers.create(<any>[factory1, factory2, factory3]);
|
||||
const differs = IterableDiffers.create(<any>[factory1, factory2, factory3]);
|
||||
expect(differs.find('some object')).toBe(factory2);
|
||||
});
|
||||
|
||||
@ -43,25 +43,25 @@ export function main() {
|
||||
factory1.spy('supports').and.returnValue(true);
|
||||
factory2.spy('supports').and.returnValue(false);
|
||||
|
||||
var parent = IterableDiffers.create(<any>[factory1]);
|
||||
var child = IterableDiffers.create(<any>[factory2], parent);
|
||||
const parent = IterableDiffers.create(<any>[factory1]);
|
||||
const child = IterableDiffers.create(<any>[factory2], parent);
|
||||
|
||||
expect(child.factories).toEqual([factory2, factory1]);
|
||||
});
|
||||
|
||||
describe('.extend()', () => {
|
||||
it('should throw if calling extend when creating root injector', () => {
|
||||
var injector = ReflectiveInjector.resolveAndCreate([IterableDiffers.extend([])]);
|
||||
const injector = ReflectiveInjector.resolveAndCreate([IterableDiffers.extend([])]);
|
||||
|
||||
expect(() => injector.get(IterableDiffers))
|
||||
.toThrowError(/Cannot extend IterableDiffers without a parent injector/);
|
||||
});
|
||||
|
||||
it('should extend di-inherited diffesr', () => {
|
||||
var parent = new IterableDiffers([factory1]);
|
||||
var injector =
|
||||
const parent = new IterableDiffers([factory1]);
|
||||
const injector =
|
||||
ReflectiveInjector.resolveAndCreate([{provide: IterableDiffers, useValue: parent}]);
|
||||
var childInjector = injector.resolveAndCreateChild([IterableDiffers.extend([factory2])]);
|
||||
const childInjector = injector.resolveAndCreateChild([IterableDiffers.extend([factory2])]);
|
||||
|
||||
expect(injector.get(IterableDiffers).factories).toEqual([factory1]);
|
||||
expect(childInjector.get(IterableDiffers).factories).toEqual([factory2, factory1]);
|
||||
|
Reference in New Issue
Block a user