iterative/vscode-dvc

View on GitHub
webview/src/util/objects.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import isEqual from 'lodash.isequal'

export type BaseType =
  | string
  | number
  | boolean
  | object
  | Obj
  | undefined
  | null

type Any = BaseType | BaseType[]

type Obj = { [key: string]: Any }

export const keepReferenceIfEqual = <T extends BaseType>(
  old: T,
  recent: T
): T => (isEqual(old, recent) ? old : recent)