Skip to content

Commit ecabfaa

Browse files
committed
nit: stop using tiny-invariant
I would prefer having a Babel plugin that strips __DEV__ statements
1 parent 0e0fe1f commit ecabfaa

File tree

6 files changed

+18
-28
lines changed

6 files changed

+18
-28
lines changed

packages/core/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"dependencies": {
1010
"@react-spring/animated": "link:../animated",
1111
"@react-spring/shared": "link:../shared",
12-
"tiny-invariant": "^1.0.6",
1312
"use-memo-one": "^1.1.0"
1413
},
1514
"publishConfig": {

packages/core/src/FrameLoop.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { is, isFluidValue, toArray } from 'shared'
44
import * as G from 'shared/globals'
55

66
import { SpringValue } from './SpringValue'
7-
import invariant from 'tiny-invariant'
87

98
type FrameUpdater = (this: FrameLoop, time?: number) => boolean
109
type RequestFrameFn = (cb: FrameRequestCallback) => number | void
@@ -286,10 +285,11 @@ export class FrameLoop {
286285
}
287286
}
288287

289-
invariant(
290-
!Number.isNaN(position),
291-
`Found NaN value while advancing "${spring.key as any}" animation`
292-
)
288+
if (Number.isNaN(position)) {
289+
throw Error(
290+
`Found NaN value while advancing "${spring.key as any}" animation`
291+
)
292+
}
293293

294294
if (position !== node.lastPosition) {
295295
changed = true

packages/core/src/SpringValue.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
AnimatedArray,
1717
OnChange,
1818
} from '@react-spring/animated'
19-
import invariant from 'tiny-invariant'
2019
import * as G from 'shared/globals'
2120

2221
import { Indexable } from './types/common'
@@ -487,10 +486,11 @@ export class SpringValue<T = any> extends AnimationValue<T> {
487486
let nodeType: AnimatedType<T>
488487
if (changed) {
489488
nodeType = this._getNodeType(to!)
490-
invariant(
491-
nodeType == node.constructor,
492-
`Cannot animate to the given "to" prop, because the current value has a different type`
493-
)
489+
if (nodeType !== node.constructor) {
490+
throw Error(
491+
`Cannot animate to the given "to" prop, because the current value has a different type`
492+
)
493+
}
494494
} else {
495495
nodeType = node.constructor as any
496496
}
@@ -685,10 +685,11 @@ export class SpringValue<T = any> extends AnimationValue<T> {
685685

686686
// TODO: makes this tree-shakeable
687687
function checkDisposed(spring: SpringValue, name: string) {
688-
invariant(
689-
!spring.is(DISPOSED),
690-
`Cannot call "${name}" of disposed "${spring.constructor.name}" object`
691-
)
688+
if (spring.is(DISPOSED)) {
689+
throw Error(
690+
`Cannot call "${name}" of disposed "${spring.constructor.name}" object`
691+
)
692+
}
692693
}
693694

694695
// Merge configs when the existence of "decay" or "duration" has not changed.

packages/shared/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
"scripts": {
77
"build": "tsc -p ."
88
},
9-
"dependencies": {
10-
"tiny-invariant": "^1.0.4"
11-
},
129
"publishConfig": {
1310
"directory": "dist"
1411
}

packages/shared/src/stringInterpolation.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { createInterpolator } from './createInterpolator'
22
import { InterpolatorConfig } from './types/interpolation'
33
import { colorToRgba } from './colorToRgba'
4-
import invariant from 'tiny-invariant'
54
import * as G from './globals'
65

76
// Problem: https://github.com/animatedjs/animated/pull/102
@@ -50,7 +49,9 @@ export const createStringInterpolator = (
5049
// Convert ["1px 2px", "0px 0px"] into [[1, 0], [2, 0]]
5150
const outputRanges = keyframes[0].map((_, i) =>
5251
keyframes.map(values => {
53-
invariant(i in values, 'The arity of each "output" value must be equal')
52+
if (!(i in values)) {
53+
throw Error('The arity of each "output" value must be equal')
54+
}
5455
return values[i]
5556
})
5657
)

yarn.lock

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,6 @@
18851885
dependencies:
18861886
"@react-spring/animated" "link:packages/animated"
18871887
"@react-spring/shared" "link:packages/shared"
1888-
tiny-invariant "^1.0.6"
18891888
use-memo-one "^1.1.0"
18901889

18911890
"@react-spring/konva@link:targets/konva":
@@ -1904,8 +1903,6 @@
19041903

19051904
"@react-spring/shared@link:packages/shared":
19061905
version "9.0.0-beta.33"
1907-
dependencies:
1908-
tiny-invariant "^1.0.4"
19091906

19101907
"@react-spring/three@link:targets/three":
19111908
version "9.0.0-beta.33"
@@ -9302,11 +9299,6 @@ time-stamp@^1.0.0:
93029299
resolved "https://registry.yarnpkg.com/time-stamp/-/time-stamp-1.1.0.tgz#764a5a11af50561921b133f3b44e618687e0f5c3"
93039300
integrity sha1-dkpaEa9QVhkhsTPztE5hhofg9cM=
93049301

9305-
tiny-invariant@^1.0.4, tiny-invariant@^1.0.6:
9306-
version "1.0.6"
9307-
resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.0.6.tgz#b3f9b38835e36a41c843a3b0907a5a7b3755de73"
9308-
integrity sha512-FOyLWWVjG+aC0UqG76V53yAWdXfH8bO6FNmyZOuUrzDzK8DI3/JRY25UD7+g49JWM1LXwymsKERB+DzI0dTEQA==
9309-
93109302
tmp@^0.0.33:
93119303
version "0.0.33"
93129304
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"

0 commit comments

Comments
 (0)