From a9e4ce368d5db545df4b65e0c6574625e6615840 Mon Sep 17 00:00:00 2001 From: Vyrtsev Mikhail Date: Sun, 7 Jul 2019 05:49:01 +0300 Subject: [PATCH] add cmpRef util --- frontend/app/utils/cmpRef.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 frontend/app/utils/cmpRef.ts diff --git a/frontend/app/utils/cmpRef.ts b/frontend/app/utils/cmpRef.ts new file mode 100644 index 00000000..d803b0ed --- /dev/null +++ b/frontend/app/utils/cmpRef.ts @@ -0,0 +1,13 @@ +import isEqual from 'lodash/isEqual'; + +/** + * Deeply compares two entities, + * and if they are equal, then first entity + * will be returned + * + * Useful when we deal with react objects + */ +export function cmpRef(a: T, b: T): T { + if (isEqual(a, b)) return a; + return b; +}