Skip to content

Commit

Permalink
fix(react-renderer): update function signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
sabertazimi committed Mar 24, 2022
1 parent fead3e6 commit 40f91dc
Showing 1 changed file with 44 additions and 21 deletions.
65 changes: 44 additions & 21 deletions packages/react-renderer/src/renderer/reconciler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { HTMLProps } from 'react';
import type { HostConfig } from 'react-reconciler';
import type { HostConfig, OpaqueHandle } from 'react-reconciler';
import ReactReconciler from 'react-reconciler';

type Type = string;
Expand Down Expand Up @@ -38,12 +38,12 @@ const hostConfig: HostConfig<
NoTimeout
> = {
createInstance(
type: string,
type: Type,
props: Props,
rootContainer: Container,
hostContext: any,
internalHandle: any
): Element {
hostContext: HostContext,
internalHandle: OpaqueHandle
): Instance {
const element = document.createElement(type);

const isListener = (propName: string) => propName.startsWith('on');
Expand All @@ -68,59 +68,82 @@ const hostConfig: HostConfig<
createTextInstance(
text: string,
rootContainer: Container,
hostContext: any,
internalHandle: any
): Text {
hostContext: HostContext,
internalHandle: OpaqueHandle
): TextInstance {
const textElement = document.createTextNode(text);
return textElement;
},
appendInitialChild(parentInstance: Element, child: Element | Text): void {
appendInitialChild(
parentInstance: Instance,
child: Instance | TextInstance
): void {
parentInstance.appendChild(child);
},
appendChildToContainer(container: Container, child: Element | Text): void {
appendChild(parentInstance: Instance, child: Instance | TextInstance): void {
parentInstance.appendChild(child);
},
appendChildToContainer(
container: Container,
child: Instance | TextInstance
): void {
container.appendChild(child);
},
removeChildFromContainer(container: Container, child: Element | Text): void {
removeChildFromContainer(
container: Container,
child: Instance | TextInstance
): void {
container.removeChild(child);
},
removeChild(parentInstance: Instance, child: Instance | TextInstance): void {
parentInstance.removeChild(child);
},
clearContainer(container: Container): void {
while (container.firstChild) {
container.firstChild.remove();
}
},
finalizeInitialChildren(
instance: Element,
type: string,
instance: Instance,
type: Type,
props: Props,
rootContainer: Container,
hostContext: any
hostContext: HostContext
): boolean {
return false;
},
prepareUpdate(
instance: Element,
type: string,
instance: Instance,
type: Type,
oldProps: Props,
newProps: Props,
rootContainer: Container,
hostContext: any
hostContext: HostContext
): UpdatePayload | null {
return null;
},
shouldSetTextContent(type: string, props: Props): boolean {
commitTextUpdate(
textInstance: TextInstance,
oldText: string,
newText: string
): void {
const newTextInstance = document.createTextNode(newText);
textInstance.replaceWith(newTextInstance);
},
shouldSetTextContent(type: Type, props: Props): boolean {
return false;
},
getRootHostContext(rootContainer: Container): HostContext | null {
return null;
},
getChildHostContext(
parentHostContext: HostContext,
type: string,
type: Type,
rootContainer: Container
): HostContext {
return parentHostContext;
},
getPublicInstance(instance: Element | Text): PublicInstance {
getPublicInstance(instance: Instance | TextInstance): PublicInstance {
return instance;
},
prepareForCommit(containerInfo: Container): Record<string, any> | null {
Expand All @@ -137,7 +160,7 @@ const hostConfig: HostConfig<
): TimeoutHandle {
return setTimeout(fn, delay);
},
cancelTimeout(id: any): void {
cancelTimeout(id: TimeoutHandle): void {
clearTimeout(id);
},
noTimeout: -1,
Expand Down

0 comments on commit 40f91dc

Please sign in to comment.