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

Resolve host configs at build time #12792

Merged
merged 15 commits into from
May 19, 2018
7 changes: 1 addition & 6 deletions packages/react-art/src/ReactART.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
*/

import React from 'react';
import ReactFiberReconciler from 'react-reconciler';
import * as ARTRenderer from 'react-reconciler/inline.art';
import Transform from 'art/core/transform';
import Mode from 'art/modes/current';
import FastNoSideEffects from 'art/modes/fast-noSideEffects';

import ReactARTHostConfig from './ReactARTHostConfig';
import {TYPES, childrenAsString} from './ReactARTInternals';

Mode.setCurrent(
Expand Down Expand Up @@ -132,10 +131,6 @@ class Text extends React.Component {
}
}

/** ART Renderer */

const ARTRenderer = ReactFiberReconciler(ReactARTHostConfig);

/** API */

export const ClippingRectangle = TYPES.CLIPPING_RECTANGLE;
Expand Down
272 changes: 141 additions & 131 deletions packages/react-art/src/ReactARTHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,157 +234,167 @@ function applyTextProps(instance, props, prevProps = {}) {
}
}

const ReactARTHostConfig = {
appendInitialChild(parentInstance, child) {
if (typeof child === 'string') {
// Noop for string children of Text (eg <Text>{'foo'}{'bar'}</Text>)
invariant(false, 'Text children should already be flattened.');
return;
}
export * from 'shared/HostConfigWithNoPersistence';
export * from 'shared/HostConfigWithNoHydration';

export function appendInitialChild(parentInstance, child) {
if (typeof child === 'string') {
// Noop for string children of Text (eg <Text>{'foo'}{'bar'}</Text>)
invariant(false, 'Text children should already be flattened.');
return;
}

child.inject(parentInstance);
},

createInstance(type, props, internalInstanceHandle) {
let instance;

switch (type) {
case TYPES.CLIPPING_RECTANGLE:
instance = Mode.ClippingRectangle();
instance._applyProps = applyClippingRectangleProps;
break;
case TYPES.GROUP:
instance = Mode.Group();
instance._applyProps = applyGroupProps;
break;
case TYPES.SHAPE:
instance = Mode.Shape();
instance._applyProps = applyShapeProps;
break;
case TYPES.TEXT:
instance = Mode.Text(
props.children,
props.font,
props.alignment,
props.path,
);
instance._applyProps = applyTextProps;
break;
}
child.inject(parentInstance);
}

invariant(instance, 'ReactART does not support the type "%s"', type);
export function createInstance(type, props, internalInstanceHandle) {
let instance;

switch (type) {
case TYPES.CLIPPING_RECTANGLE:
instance = Mode.ClippingRectangle();
instance._applyProps = applyClippingRectangleProps;
break;
case TYPES.GROUP:
instance = Mode.Group();
instance._applyProps = applyGroupProps;
break;
case TYPES.SHAPE:
instance = Mode.Shape();
instance._applyProps = applyShapeProps;
break;
case TYPES.TEXT:
instance = Mode.Text(
props.children,
props.font,
props.alignment,
props.path,
);
instance._applyProps = applyTextProps;
break;
}

instance._applyProps(instance, props);
invariant(instance, 'ReactART does not support the type "%s"', type);

return instance;
},
instance._applyProps(instance, props);

createTextInstance(text, rootContainerInstance, internalInstanceHandle) {
return text;
},
return instance;
}

finalizeInitialChildren(domElement, type, props) {
return false;
},
export function createTextInstance(
text,
rootContainerInstance,
internalInstanceHandle,
) {
return text;
}

getPublicInstance(instance) {
return instance;
},
export function finalizeInitialChildren(domElement, type, props) {
return false;
}

prepareForCommit() {
// Noop
},
export function getPublicInstance(instance) {
return instance;
}

prepareUpdate(domElement, type, oldProps, newProps) {
return UPDATE_SIGNAL;
},
export function prepareForCommit() {
// Noop
}

resetAfterCommit() {
// Noop
},
export function prepareUpdate(domElement, type, oldProps, newProps) {
return UPDATE_SIGNAL;
}

resetTextContent(domElement) {
// Noop
},
export function resetAfterCommit() {
// Noop
}

shouldDeprioritizeSubtree(type, props) {
return false;
},
export function resetTextContent(domElement) {
// Noop
}

getRootHostContext() {
return emptyObject;
},
export function shouldDeprioritizeSubtree(type, props) {
return false;
}

getChildHostContext() {
return emptyObject;
},
export function getRootHostContext() {
return emptyObject;
}

scheduleDeferredCallback: ReactScheduler.scheduleWork,
export function getChildHostContext() {
return emptyObject;
}

shouldSetTextContent(type, props) {
return (
typeof props.children === 'string' || typeof props.children === 'number'
);
},

now: ReactScheduler.now,

// The ART renderer is secondary to the React DOM renderer.
isPrimaryRenderer: false,

mutation: {
appendChild(parentInstance, child) {
if (child.parentNode === parentInstance) {
child.eject();
}
child.inject(parentInstance);
},

appendChildToContainer(parentInstance, child) {
if (child.parentNode === parentInstance) {
child.eject();
}
child.inject(parentInstance);
},

insertBefore(parentInstance, child, beforeChild) {
invariant(
child !== beforeChild,
'ReactART: Can not insert node before itself',
);
child.injectBefore(beforeChild);
},
export const scheduleDeferredCallback = ReactScheduler.scheduleWork;
export const cancelDeferredCallback = ReactScheduler.cancelScheduledWork;

insertInContainerBefore(parentInstance, child, beforeChild) {
invariant(
child !== beforeChild,
'ReactART: Can not insert node before itself',
);
child.injectBefore(beforeChild);
},
export function shouldSetTextContent(type, props) {
return (
typeof props.children === 'string' || typeof props.children === 'number'
);
}

removeChild(parentInstance, child) {
destroyEventListeners(child);
child.eject();
},
export const now = ReactScheduler.now;

removeChildFromContainer(parentInstance, child) {
destroyEventListeners(child);
child.eject();
},
// The ART renderer is secondary to the React DOM renderer.
export const isPrimaryRenderer = false;

commitTextUpdate(textInstance, oldText, newText) {
// Noop
},
export const supportsMutation = true;

commitMount(instance, type, newProps) {
// Noop
},
export function appendChild(parentInstance, child) {
if (child.parentNode === parentInstance) {
child.eject();
}
child.inject(parentInstance);
}

commitUpdate(instance, updatePayload, type, oldProps, newProps) {
instance._applyProps(instance, newProps, oldProps);
},
},
};
export function appendChildToContainer(parentInstance, child) {
if (child.parentNode === parentInstance) {
child.eject();
}
child.inject(parentInstance);
}

export default ReactARTHostConfig;
export function insertBefore(parentInstance, child, beforeChild) {
invariant(
child !== beforeChild,
'ReactART: Can not insert node before itself',
);
child.injectBefore(beforeChild);
}

export function insertInContainerBefore(parentInstance, child, beforeChild) {
invariant(
child !== beforeChild,
'ReactART: Can not insert node before itself',
);
child.injectBefore(beforeChild);
}

export function removeChild(parentInstance, child) {
destroyEventListeners(child);
child.eject();
}

export function removeChildFromContainer(parentInstance, child) {
destroyEventListeners(child);
child.eject();
}

export function commitTextUpdate(textInstance, oldText, newText) {
// Noop
}

export function commitMount(instance, type, newProps) {
// Noop
}

export function commitUpdate(
instance,
updatePayload,
type,
oldProps,
newProps,
) {
instance._applyProps(instance, newProps, oldProps);
}
Loading