Browse Source

Changes updateEffective to ignore array order

Moves all lodash into system
main
Eric Amodio 5 years ago
parent
commit
d394658aca
4 changed files with 26 additions and 5 deletions
  1. +3
    -3
      src/commands/quickCommand.helpers.ts
  2. +2
    -2
      src/configuration.ts
  3. +8
    -0
      src/system/array.ts
  4. +13
    -0
      src/system/object.ts

+ 3
- 3
src/commands/quickCommand.helpers.ts View File

@ -1,5 +1,5 @@
'use strict';
import { intersectionWith } from 'lodash-es';
import { Arrays } from '../system';
import { GitBranch, GitTag, Repository } from '../git/git';
import { BranchQuickPickItem, TagQuickPickItem } from '../quickpicks';
@ -34,12 +34,12 @@ export async function getBranchesAndOrTags(
]);
branches = GitBranch.sort(
intersectionWith(...branchesByRepo, ((b1: GitBranch, b2: GitBranch) => b1.name === b2.name) as any)
Arrays.intersection(...branchesByRepo, ((b1: GitBranch, b2: GitBranch) => b1.name === b2.name) as any)
);
if (includeTags) {
tags = GitTag.sort(
intersectionWith(...tagsByRepo!, ((t1: GitTag, t2: GitTag) => t1.name === t2.name) as any)
Arrays.intersection(...tagsByRepo!, ((t1: GitTag, t2: GitTag) => t1.name === t2.name) as any)
);
}
}

+ 2
- 2
src/configuration.ts View File

@ -12,7 +12,7 @@ import {
} from 'vscode';
import { Config } from './config';
import { extensionId } from './constants';
import { Functions } from './system';
import { Functions, Objects } from './system';
const emptyConfig: Config = new Proxy<Config>({} as Config, {
get: function() {
@ -273,7 +273,7 @@ export class Configuration {
return configuration.update(
section,
value === inspect.defaultValue ? undefined : value,
Objects.areEquivalent(value, inspect.defaultValue) ? undefined : value,
ConfigurationTarget.Global
);
}

+ 8
- 0
src/system/array.ts View File

@ -1,4 +1,5 @@
'use strict';
import { intersectionWith as _intersectionWith, isEqual as _isEqual, xor as _xor } from 'lodash-es';
export namespace Arrays {
export function countUniques<T>(source: T[], accessor: (item: T) => string): { [key: string]: number } {
@ -78,6 +79,13 @@ export namespace Arrays {
}, new Map<TKey, TMapped[]>());
}
export const intersection = _intersectionWith;
export const isEqual = _isEqual;
export function areEquivalent<T>(value: T[], other: T[]) {
return _xor(value, other).length === 0;
}
export interface HierarchicalItem<T> {
name: string;
relativePath: string;

+ 13
- 0
src/system/object.ts View File

@ -1,4 +1,6 @@
'use strict';
import { isEqual as _isEqual } from 'lodash-es';
import { Arrays } from './array';
export namespace Objects {
export function entries<T>(o: { [key: string]: T }): IterableIterator<[string, T]>;
@ -53,6 +55,17 @@ export namespace Objects {
}
}
export function isEqual(value: any, other: any) {
return _isEqual(value, other);
}
export function areEquivalent(value: any, other: any) {
if (Array.isArray(value) && Array.isArray(other)) {
return Arrays.areEquivalent(value, other);
}
return isEqual(value, other);
}
export function paths(o: { [key: string]: any }, path?: string): string[] {
const results = [];

Loading…
Cancel
Save