Skip to content

Commit eb0c2a2

Browse files
committed
other files
1 parent 362c094 commit eb0c2a2

File tree

7 files changed

+531
-103
lines changed

7 files changed

+531
-103
lines changed

pnpm-lock.yaml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spring/rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default [
2222
output: {
2323
dir: "dist",
2424
format: "esm",
25+
sourcemap: true,
2526
},
2627
external,
2728
plugins: [

spring/src/SpringValue.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
import * as G from './globals'
2+
import {scheduleProps} from './scheduleProps'
3+
import { Animated, AnimatedValue, getAnimated, getPayload, setAnimated } from "./animated";
4+
import { AnimatedString } from "./AnimatedString";
15
import { Animation } from "./Animation";
2-
import { FluidValue } from "./fluids";
3-
import { FrameValue } from "./FrameValue";
6+
import { getCancelledResult, getCombinedResult, getFinishedResult, getNoopResult } from "./AnimationResult";
7+
import { addFluidObserver, callFluidObservers, FluidValue, getFluidObservers, getFluidValue, hasFluidValue, removeFluidObserver } from "./fluids";
8+
import { FrameValue, isFrameValue } from "./FrameValue";
9+
import { raf } from "./rafz";
10+
import { runAsync, RunAsyncProps, RunAsyncState, stopAsync } from "./runAsync";
11+
import { hasAnimated, isAnimating, isPaused, setActiveBit, setPausedBit } from "./SpringPhase";
412
import {
513
EventKey,
614
Lookup,
@@ -16,7 +24,26 @@ import {
1624
getDefaultProps,
1725
is,
1826
isAsyncTo,
27+
PickEventFns,
28+
AnimationResolver,
29+
VelocityProp,
30+
toArray,
31+
AsyncResult,
32+
flushCalls,
33+
each,
34+
matchProp,
35+
isAnimatedString,
36+
AnimationRange,
37+
getAnimatedType
1938
} from "./utils";
39+
import { mergeConfig } from './AnimationConfig';
40+
import { frameLoop } from './FrameLoop';
41+
42+
declare const console: any
43+
44+
interface DefaultSpringProps<T>
45+
extends Pick<SpringProps<T>, 'pause' | 'cancel' | 'immediate' | 'config'>,
46+
PickEventFns<SpringProps<T>> {}
2047

2148
/**
2249
* Only numbers, strings, and arrays of numbers/strings are supported.

spring/src/fluids.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
const $get = Symbol.for("FluidValue.get");
2828
const $observers = Symbol.for("FluidValue.observers");
2929

30+
/** Returns true if `arg` can be observed. */
31+
export const hasFluidValue = (arg: any): arg is FluidValue => Boolean(arg && arg[$get])
32+
3033
/** An event sent to `FluidObserver` objects. */
3134
export interface FluidEvent<T = any> {
3235
type: string;
@@ -116,3 +119,69 @@ export function callFluidObservers(target: any, event: FluidEvent) {
116119
});
117120
}
118121
}
122+
type GetFluidObservers = {
123+
<E extends FluidEvent>(target: FluidValue<any, E>): ReadonlySet<
124+
FluidObserver<E>
125+
> | null
126+
(target: object): ReadonlySet<FluidObserver> | null
127+
}
128+
129+
130+
/** Observe a `fluids`-compatible object. */
131+
export function addFluidObserver<T, E extends FluidEvent>(
132+
target: FluidValue<T, E>,
133+
observer: FluidObserver<E>
134+
): typeof observer
135+
136+
export function addFluidObserver<E extends FluidEvent>(
137+
target: object,
138+
observer: FluidObserver<E>
139+
): typeof observer
140+
141+
export function addFluidObserver(target: any, observer: FluidObserver) {
142+
if (target[$get]) {
143+
let observers: Set<FluidObserver> = target[$observers]
144+
if (!observers) {
145+
setHidden(target, $observers, (observers = new Set()))
146+
}
147+
if (!observers.has(observer)) {
148+
observers.add(observer)
149+
if (target.observerAdded) {
150+
target.observerAdded(observers.size, observer)
151+
}
152+
}
153+
}
154+
return observer
155+
}
156+
157+
/** Stop observing a `fluids`-compatible object. */
158+
export function removeFluidObserver<E extends FluidEvent>(
159+
target: FluidValue<any, E>,
160+
observer: FluidObserver<E>
161+
): void
162+
163+
export function removeFluidObserver<E extends FluidEvent>(
164+
target: object,
165+
observer: FluidObserver<E>
166+
): void
167+
168+
export function removeFluidObserver(target: any, observer: FluidObserver) {
169+
let observers: Set<FluidObserver> = target[$observers]
170+
if (observers && observers.has(observer)) {
171+
const count = observers.size - 1
172+
if (count) {
173+
observers.delete(observer)
174+
} else {
175+
target[$observers] = null
176+
}
177+
if (target.observerRemoved) {
178+
target.observerRemoved(count, observer)
179+
}
180+
}
181+
}
182+
183+
184+
/** Get the current observer set. Never mutate it directly! */
185+
export const getFluidObservers: GetFluidObservers = (target: any) =>
186+
target[$observers] || null
187+

0 commit comments

Comments
 (0)