Skip to content

Commit 6e11e33

Browse files
committed
fix(shared): resolve circular dependencies
`shared/helpers` wants entire `shared/globals` inside `isAnimatedString`, `shared/globals` wants `noop` from `shared/globals` to assign exported variable. If `shared/helpers` is executed before `shared/globals`, `willAdvance` is initialized by given value. Otherwise `willAdvance` is initialized after `noop` inside `shared/helpers` and have no defined value. The safest way is keep `shared/helpers` pure and move `isAnimatedString` to own module.
1 parent e53fbfb commit 6e11e33

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

packages/shared/src/helpers.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Lookup, Arrify, AnyFn } from '@react-spring/types'
2-
import * as G from './globals'
32

43
export const noop = () => {}
54

@@ -34,11 +33,6 @@ export function isEqual(a: any, b: any) {
3433
return a === b
3534
}
3635

37-
// Not all strings can be animated (eg: {display: "none"})
38-
export const isAnimatedString = (value: unknown): value is string =>
39-
is.str(value) &&
40-
(value[0] == '#' || /\d/.test(value) || !!(G.colors && G.colors[value]))
41-
4236
type Eachable<Value, Key> = {
4337
forEach: (cb: (value: Value, key: Key) => void, ctx?: any) => void
4438
}

packages/shared/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ export * from './createInterpolator'
1515
export * from './stringInterpolation'
1616
export * from './deprecations'
1717
export * from './helpers'
18+
export * from './isAnimatedString'
1819

1920
export * from 'fluids'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as G from './globals'
2+
import { is } from './helpers'
3+
4+
// Not all strings can be animated (eg: {display: "none"})
5+
export function isAnimatedString(value: unknown): value is string {
6+
return (
7+
is.str(value) &&
8+
(value[0] == '#' || /\d/.test(value) || !!(G.colors && G.colors[value]))
9+
)
10+
}

0 commit comments

Comments
 (0)