Skip to content

Commit 939f8de

Browse files
committed
update
1 parent 6b0447f commit 939f8de

File tree

4 files changed

+34
-56
lines changed

4 files changed

+34
-56
lines changed

demo/src/App.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import {
22
Component,
3-
createEffect,
4-
createMemo,
5-
createSignal,
6-
createComponent,
73
} from "solid-js";
84
import { createSpring, animated } from "solid-spring";
9-
// console.log(createSpring({to: {x: 'h'}}));
105

116
function ChainExample() {
127
const styles = createSpring({
@@ -17,18 +12,14 @@ function ChainExample() {
1712
],
1813
from: { opacity: 0, color: 'red' },
1914
})
20-
console.log(styles()[0])
2115

22-
return <animated.div style={styles()[0]}>I will fade in and out</animated.div>
16+
return <animated.div style={styles()}>I will fade in and out</animated.div>
2317
}
2418

2519
const App: Component = () => {
26-
2720
return (
2821
<ChainExample />
2922
);
3023
};
3124

32-
// console.log(createComponent(() => <h1>hello</h1>, {}));
33-
3425
export default App;

spring/src/solid/createSpring.ts

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Accessor, createEffect, createMemo } from "solid-js";
1+
import { Accessor, createMemo } from "solid-js";
22
import { SpringRef } from "../SpringRef";
33
import type { SpringRef as SpringRefType } from "../SpringRef";
44
import {
@@ -10,7 +10,6 @@ import {
1010
Valid,
1111
} from "../utils";
1212
import { createSprings } from "./createSprings";
13-
import { Controller } from "../Controller";
1413

1514
/**
1615
* The props that `useSpring` recognizes.
@@ -28,42 +27,29 @@ export type CreateSpringProps<Props extends object = any> = unknown &
2827
}
2928
>
3029
: never;
31-
/* export function createSpring<Props extends object>(
32-
props: (...arg: any) => ((Props & Valid<Props, CreateSpringProps<Props>>) | CreateSpringProps)
33-
): Accessor<
34-
[SpringValues<PickAnimated<Props>>, SpringRefType<PickAnimated<Props>>]
35-
>; */
30+
3631
export function createSpring<Props extends object>(
3732
props: () =>
3833
| (Props & Valid<Props, CreateSpringProps<Props>>)
3934
| CreateSpringProps
40-
): Accessor<
41-
[SpringValues<PickAnimated<Props>>, SpringRefType<PickAnimated<Props>>]
42-
>;
35+
): Accessor<SpringValues<PickAnimated<Props>>[]> & {
36+
ref: SpringRefType<PickAnimated<Props>>;
37+
};
4338

4439
export function createSpring<Props extends object>(
4540
props: (Props & Valid<Props, CreateSpringProps<Props>>) | CreateSpringProps
46-
): Accessor<
47-
[SpringValues<PickAnimated<Props>>, SpringRefType<PickAnimated<Props>>]
48-
>;
41+
): Accessor<SpringValues<PickAnimated<Props>>[]> & {
42+
ref: SpringRefType<PickAnimated<Props>>;
43+
};
4944

50-
export function createSpring<Props extends object>(props: any): any {
45+
export function createSpring(props: any): any {
5146
const fn = is.fun(props) ? props : () => props;
5247

53-
const springsFn = createSprings(() => 1, fn);
48+
const springsFn = createSprings(1, fn);
5449
const springMemo = createMemo(() => {
55-
const [[value], ref] = springsFn();
56-
57-
return [value as SpringValues<PickAnimated<Props>>, ref];
50+
const [value] = springsFn();
51+
return value
5852
});
53+
5954
return springMemo;
6055
}
61-
62-
/*
63-
* const props = createSpring(() => ({
64-
to: { opacity: 1 },
65-
from: { opacity: 0 },
66-
reset: true,
67-
onRest: () => set(!flip())
68-
}))
69-
*/

spring/src/solid/createSprings.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,27 @@ export type CreateSpringsProps<State extends Lookup = Lookup> = unknown &
3232
};
3333

3434
export function createSprings<Props extends CreateSpringsProps>(
35-
lengthFn: () => number,
35+
lengthFn: number | (() => number),
3636
props: Props[] & CreateSpringsProps<PickAnimated<Props>>[]
37-
): Accessor<
38-
[SpringValues<PickAnimated<Props>>[], SpringRefType<PickAnimated<Props>>]
39-
>;
37+
): Accessor<SpringValues<PickAnimated<Props>>[]> & {
38+
ref: SpringRefType<PickAnimated<Props>>;
39+
};
4040

4141
export function createSprings<Props extends CreateSpringsProps>(
42-
lengthFn: () => number,
42+
lengthFn: number | (() => number),
4343
props: (i: number, ctrl: Controller) => Props
44-
): Accessor<
45-
[SpringValues<PickAnimated<Props>>[], SpringRefType<PickAnimated<Props>>]
46-
>;
44+
): Accessor<SpringValues<PickAnimated<Props>>[]> & {
45+
ref: SpringRefType<PickAnimated<Props>>;
46+
};
4747

4848
export function createSprings<Props extends CreateSpringsProps>(
49-
lengthFn: () => number,
49+
lengthFn: any,
5050
props: any[] | ((i: number, ctrl: Controller) => any)
51-
): Accessor<
52-
[SpringValues<PickAnimated<Props>>[], SpringRefType<PickAnimated<Props>>]
53-
> {
51+
): Accessor<SpringValues<PickAnimated<Props>>[]> & {
52+
ref: SpringRefType<PickAnimated<Props>>;
53+
} {
54+
const _lengthFn = lengthFn
55+
lengthFn = is.fun(lengthFn) ? lengthFn : () => _lengthFn as number;
5456
const propsFn = is.fun(props) ? props : undefined;
5557
const ref = SpringRef();
5658

@@ -179,7 +181,11 @@ export function createSprings<Props extends CreateSpringsProps>(
179181
each(state.ctrls, (ctrl) => ctrl.stop(true));
180182
});
181183

182-
const value = createMemo(() => [springs.map((x) => ({ ...x })), ref]);
184+
const value: Accessor<SpringValues<PickAnimated<Props>>[]> & {
185+
ref: SpringRefType<PickAnimated<Props>>;
186+
} = createMemo(() => springs.map((x) => ({ ...x }))) as any;
183187

184-
return value as any;
188+
value.ref = ref as any;
189+
190+
return value;
185191
}

spring/src/withAnimated.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import {
33
children,
44
createComponent,
55
createRenderEffect,
6-
JSX,
76
onCleanup,
8-
onMount,
97
} from "solid-js";
108
import { AnimatedObject } from "./AnimatedObject";
119
import { TreeContext } from "./context";
@@ -28,9 +26,7 @@ export const withAnimated = (Component: string, host: HostConfig) => {
2826
createComponent(Dynamic, { component: Component, ...props })
2927
);
3028
const instanceRef: Element = c() as any;
31-
onMount(() => console.log("here"));
3229
const [_props, deps] = getAnimatedState(props, host);
33-
console.log(_props, deps);
3430

3531
const callback = () => {
3632
const didUpdate = instanceRef
@@ -39,7 +35,6 @@ export const withAnimated = (Component: string, host: HostConfig) => {
3935

4036
// Re-render the component when native updates fail.
4137
if (didUpdate === false) {
42-
console.log(didUpdate);
4338
// forceUpdate()
4439
}
4540
};

0 commit comments

Comments
 (0)