Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix types #376

Merged
merged 1 commit into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/commit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IFiber, IRef } from './type'
import { Ref } from './type'
import { updateElement } from './dom'
import { isFn, TAG } from './reconcile'

Expand Down Expand Up @@ -31,12 +31,12 @@ export const commit = (fiber: any) => {
commit(fiber.sibling)
}

const refer = (ref: IRef, dom?: HTMLElement): void => {
const refer = (ref?: Ref<HTMLElement | undefined>, dom?: HTMLElement) => {
if (ref)
isFn(ref) ? ref(dom) : ((ref as { current?: HTMLElement })!.current = dom)
isFn(ref) ? ref(dom) : ref.current = dom
}

const kidsRefer = (kids: any): void => {
const kidsRefer = (kids: any) => {
kids.forEach(kid => {
kid.kids && kidsRefer(kid.kids)
refer(kid.ref, null)
Expand Down
4 changes: 2 additions & 2 deletions src/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ITask } from './type'

const queue: ITask[] = []
const threshold: number = 5
const transitions = []
const transitions: (() => void)[] = []
let deadline: number = 0

export const startTransition = cb => {
Expand Down Expand Up @@ -52,4 +52,4 @@ export const shouldYield = (): boolean => {

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

const peek = (queue: ITask[]) => queue[0]
const peek = (queue: ITask[]) => queue[0]
16 changes: 6 additions & 10 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,20 @@ export interface IFiber<P extends Attributes = any> {
parentNode: HTMLElementEx
node: HTMLElementEx
kids?: any
dirty:boolean,
dirty: boolean
parent?: IFiber<P>
sibling?: IFiber<P>
child?: IFiber<P>
done?: () => void
ref: IRef
ref?: Ref<HTMLElement | undefined>
hooks: IHook
oldProps: P
action: any
props: P
lane: number
isComp: boolean
}

export type HTMLElementEx = HTMLElement & { last: IFiber | null }
export type IEffect = [Function?, number?, Function?]
export type IEffect = [Function?, number?, cleanup?: Function]

export type FreText = string | number
export type FreNode =
Expand All @@ -72,11 +70,10 @@ export type FreNode =
| null
| undefined
export type SetStateAction<S> = S | ((prevState: S) => S)
export type Dispatch<A> = (value: A, resume?: boolean) => void
export type Dispatch<A> = (value: A) => void
export type Reducer<S, A> = (prevState: S, action: A) => S
export type IVoidCb = () => void
export type EffectCallback = () => void | (IVoidCb | undefined)
export type DependencyList = Array<any>
export type EffectCallback = () => void | (() => void | undefined)
export type DependencyList = ReadonlyArray<unknown>

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

export interface ITask {
callback?: ITaskCallback
fiber: IFiber
}

export type DOM = HTMLElement | SVGElement