From bcf5e2f2d77610f23e5cb7dc622833ef47727b79 Mon Sep 17 00:00:00 2001 From: Maxim Khvatalin Date: Wed, 16 Sep 2020 14:51:06 +0300 Subject: [PATCH] fix(shared): resolve circular dependencies `shared/helpers` wants entire `shared/globals` inside `isAnimatedString`, `shared/globals` wants `noop` from `shared/helper` to assign exported variable `willAdvance`. If `shared/helpers` is executed before `shared/globals`, `willAdvance` is initialized by given value. Otherwise `willAdvance` is initialized after `noop` inside `shared/helpers` and has no defined value. The safest way is keep `shared/helpers` pure and move `isAnimatedString` to own module. --- packages/shared/src/helpers.ts | 6 ------ packages/shared/src/index.ts | 1 + packages/shared/src/isAnimatedString.ts | 10 ++++++++++ 3 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 packages/shared/src/isAnimatedString.ts diff --git a/packages/shared/src/helpers.ts b/packages/shared/src/helpers.ts index ece54e9dcc..5ee7796cd9 100644 --- a/packages/shared/src/helpers.ts +++ b/packages/shared/src/helpers.ts @@ -1,5 +1,4 @@ import { Lookup, Arrify, AnyFn, Any } from '@react-spring/types' -import * as G from './globals' export function noop() {} @@ -33,11 +32,6 @@ export function isEqual(a: any, b: any) { return a === b } -// Not all strings can be animated (eg: {display: "none"}) -export const isAnimatedString = (value: unknown): value is string => - is.str(value) && - (value[0] == '#' || /\d/.test(value) || value in (G.colors || {})) - type EachFn = (this: This, value: Value, key: Key) => void type Eachable = { forEach(cb: EachFn, ctx?: This): void diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index 287f6c10f8..83c2b01010 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -10,6 +10,7 @@ export * from './createInterpolator' export * from './stringInterpolation' export * from './deprecations' export * from './helpers' +export * from './isAnimatedString' export * from 'fluids' export { raf, Timeout } from 'rafz' diff --git a/packages/shared/src/isAnimatedString.ts b/packages/shared/src/isAnimatedString.ts new file mode 100644 index 0000000000..af8845c703 --- /dev/null +++ b/packages/shared/src/isAnimatedString.ts @@ -0,0 +1,10 @@ +import * as G from './globals' +import { is } from './helpers' + +// Not all strings can be animated (eg: {display: "none"}) +export function isAnimatedString(value: unknown): value is string { + return ( + is.str(value) && + (value[0] == '#' || /\d/.test(value) || value in (G.colors || {})) + ) +}