Skip to content

Commit

Permalink
fix(react-renderer): implement basic HostConfig API
Browse files Browse the repository at this point in the history
- Type: React element type name.
- Props: React element default props.
- createInstance/createTextInstance/appendInitialChild.
- isPrimaryRenderer.
- supportsHydration.
- supportsMutation.
- supportsPersistence.
  • Loading branch information
sabertazimi committed Mar 24, 2022
1 parent f230498 commit 3f7c3cc
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions packages/react-renderer/src/renderer/reconciler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { HTMLProps } from 'react';
import type { HostConfig } from 'react-reconciler';
import ReactReconciler from 'react-reconciler';

type Type = string;
type Props = { [key: string]: any };
type Props = HTMLProps<HTMLElement>;
export type Container = Document | DocumentFragment | Element;
type Instance = Element;
type TextInstance = Text;
Expand Down Expand Up @@ -31,30 +32,32 @@ const hostConfig: HostConfig<
TimeoutHandle,
NoTimeout
> = {
supportsMutation: false,
supportsPersistence: false,
createInstance: function (
type: string,
props: Props,
rootContainer: Container,
hostContext: any,
internalHandle: any
): Element {
throw new Error('Function not implemented.');
const element = document.createElement(type);
if (props.className) element.className = props.className;
if (props.id) element.id = props.id;
return element;
},
createTextInstance: function (
text: string,
rootContainer: Container,
hostContext: any,
internalHandle: any
): Text {
throw new Error('Function not implemented.');
const textElement = document.createTextNode(text);
return textElement;
},
appendInitialChild: function (
parentInstance: Element,
child: Element | Text
): void {
throw new Error('Function not implemented.');
parentInstance.appendChild(child);
},
finalizeInitialChildren: function (
instance: Element,
Expand Down Expand Up @@ -114,9 +117,11 @@ const hostConfig: HostConfig<
cancelTimeout: function (id: any): void {
throw new Error('Function not implemented.');
},
noTimeout: 0,
isPrimaryRenderer: false,
noTimeout: -1,
isPrimaryRenderer: true,
supportsHydration: false,
supportsMutation: true,
supportsPersistence: false,
};

const reconciler = ReactReconciler(hostConfig);
Expand Down

0 comments on commit 3f7c3cc

Please sign in to comment.