Skip to content

Commit 467d7da

Browse files
committed
fix types
1 parent e70644d commit 467d7da

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

src/commit.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IFiber, IRef } from './type'
1+
import { Ref } from './type'
22
import { updateElement } from './dom'
33
import { isFn, TAG } from './reconcile'
44

@@ -31,12 +31,12 @@ export const commit = (fiber: any) => {
3131
commit(fiber.sibling)
3232
}
3333

34-
const refer = (ref: IRef, dom?: HTMLElement): void => {
34+
const refer = (ref?: Ref<HTMLElement | undefined>, dom?: HTMLElement) => {
3535
if (ref)
36-
isFn(ref) ? ref(dom) : ((ref as { current?: HTMLElement })!.current = dom)
36+
isFn(ref) ? ref(dom) : ref.current = dom
3737
}
3838

39-
const kidsRefer = (kids: any): void => {
39+
const kidsRefer = (kids: any) => {
4040
kids.forEach(kid => {
4141
kid.kids && kidsRefer(kid.kids)
4242
refer(kid.ref, null)

src/schedule.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ITask } from './type'
22

33
const queue: ITask[] = []
44
const threshold: number = 5
5-
const transitions = []
5+
const transitions: (() => void)[] = []
66
let deadline: number = 0
77

88
export const startTransition = cb => {
@@ -52,4 +52,4 @@ export const shouldYield = (): boolean => {
5252

5353
export const getTime = () => performance.now()
5454

55-
const peek = (queue: ITask[]) => queue[0]
55+
const peek = (queue: ITask[]) => queue[0]

src/type.ts

+6-10
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,20 @@ export interface IFiber<P extends Attributes = any> {
4646
parentNode: HTMLElementEx
4747
node: HTMLElementEx
4848
kids?: any
49-
dirty:boolean,
49+
dirty: boolean
5050
parent?: IFiber<P>
5151
sibling?: IFiber<P>
5252
child?: IFiber<P>
53-
done?: () => void
54-
ref: IRef
53+
ref?: Ref<HTMLElement | undefined>
5554
hooks: IHook
56-
oldProps: P
5755
action: any
5856
props: P
5957
lane: number
6058
isComp: boolean
6159
}
6260

6361
export type HTMLElementEx = HTMLElement & { last: IFiber | null }
64-
export type IEffect = [Function?, number?, Function?]
62+
export type IEffect = [Function?, number?, cleanup?: Function]
6563

6664
export type FreText = string | number
6765
export type FreNode =
@@ -72,11 +70,10 @@ export type FreNode =
7270
| null
7371
| undefined
7472
export type SetStateAction<S> = S | ((prevState: S) => S)
75-
export type Dispatch<A> = (value: A, resume?: boolean) => void
73+
export type Dispatch<A> = (value: A) => void
7674
export type Reducer<S, A> = (prevState: S, action: A) => S
77-
export type IVoidCb = () => void
78-
export type EffectCallback = () => void | (IVoidCb | undefined)
79-
export type DependencyList = Array<any>
75+
export type EffectCallback = () => void | (() => void | undefined)
76+
export type DependencyList = ReadonlyArray<unknown>
8077

8178
export interface PropsWithChildren {
8279
children?: FreNode
@@ -86,7 +83,6 @@ export type ITaskCallback = (() => ITaskCallback) | null
8683

8784
export interface ITask {
8885
callback?: ITaskCallback
89-
fiber: IFiber
9086
}
9187

9288
export type DOM = HTMLElement | SVGElement

0 commit comments

Comments
 (0)