Skip to content

Commit d35fb1c

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 18f108f commit d35fb1c

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, Any } from '@react-spring/types'
2-
import * as G from './globals'
32

43
export function noop() {}
54

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

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

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)