From 17e135643294236c5af444bc0155ea5fa7567d6c Mon Sep 17 00:00:00 2001 From: Robert Monfera Date: Thu, 21 Jan 2021 21:45:58 +0100 Subject: [PATCH] chore: pr feedback ht Nick --- src/state/actions/colors.ts | 14 +++++++------- src/utils/common.ts | 4 ++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/state/actions/colors.ts b/src/state/actions/colors.ts index adb36dfdb7..7fbe6db3b2 100644 --- a/src/state/actions/colors.ts +++ b/src/state/actions/colors.ts @@ -29,36 +29,36 @@ export const SET_TEMPORARY_COLOR = 'SET_TEMPORARY_COLOR'; /** @internal */ export const SET_PERSISTED_COLOR = 'SET_PERSISTED_COLOR'; -interface ClearedTemporaryColors { +interface ClearTemporaryColors { type: typeof CLEAR_TEMPORARY_COLORS; } -interface TemporaryColor { +interface SetTemporaryColor { type: typeof SET_TEMPORARY_COLOR; key: SeriesKey; color: Color | null; } -interface PersistedColor { +interface SetPersistedColor { type: typeof SET_PERSISTED_COLOR; key: SeriesKey; color: Color | null; } /** @internal */ -export function clearTemporaryColors(): ClearedTemporaryColors { +export function clearTemporaryColors(): ClearTemporaryColors { return { type: CLEAR_TEMPORARY_COLORS }; } /** @internal */ -export function setTemporaryColor(key: SeriesKey, color: Color | null): TemporaryColor { +export function setTemporaryColor(key: SeriesKey, color: Color | null): SetTemporaryColor { return { type: SET_TEMPORARY_COLOR, key, color }; } /** @internal */ -export function setPersistedColor(key: SeriesKey, color: Color | null): PersistedColor { +export function setPersistedColor(key: SeriesKey, color: Color | null): SetPersistedColor { return { type: SET_PERSISTED_COLOR, key, color }; } /** @internal */ -export type ColorsActions = ClearedTemporaryColors | TemporaryColor | PersistedColor; +export type ColorsActions = ClearTemporaryColors | SetTemporaryColor | SetPersistedColor; diff --git a/src/utils/common.ts b/src/utils/common.ts index a08c4d6352..0dda44d877 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -540,4 +540,8 @@ export const getPercentageValue = (ratio: string | number, relativeValue: num return num && !isNaN(num) ? num : defaultValue; }; +/** + * Predicate function, eg. to be called with [].filter, to keep distinct values + * @example [1, 2, 4, 2, 4, 0, 3, 2].filter(keepDistinct) ==> [1, 2, 4, 0, 3] + */ export const keepDistinct = (d: T, i: number, a: T[]): boolean => a.indexOf(d) === i;