Created
September 30, 2018 16:38
-
-
Save arilotter/d34c684da13a4825285ddfe021ec4be3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const UPDATE_SIGNAL = {} | |
| const emptyObject = {} | |
| function defaultApplyProps(instance, _oldProps, newProps) { | |
| // impl etc | |
| } | |
| function applyProps(instance, oldProps, newProps) { | |
| if (typeof instance._customApplyProps === "function") { | |
| instance._customApplyProps(instance, oldProps, newProps) | |
| } else { | |
| defaultApplyProps(instance, oldProps, newProps) | |
| } | |
| } | |
| function getRootHostContext(_rootContainerInstance) { | |
| return emptyObject | |
| } | |
| function getChildHostContext(_parentHostContext, _type, _instance) { | |
| return emptyObject | |
| } | |
| function getPublicInstance(instance) { | |
| return instance | |
| } | |
| function createInstance( | |
| type, | |
| props, | |
| rootContainerInstance, | |
| _hostContext, | |
| _internalInstanceHandle | |
| ) { | |
| let instance | |
| switch (type) { | |
| case TYPES.TYPE1: | |
| instance = new Type1() | |
| break | |
| case TYPES.Type2: | |
| instance = new Type2() | |
| break | |
| default: | |
| instance = createInjectedTypeInstance( | |
| type, | |
| props, | |
| rootContainerInstance, | |
| defaultApplyProps | |
| ) | |
| break | |
| } | |
| applyProps(instance, {}, props) | |
| return instance | |
| } | |
| function appendInitialChild(parentInstance, child) { | |
| appendChild(parentInstance, child) | |
| } | |
| function finalizeInitialChildren( | |
| _parentInstance, | |
| _type, | |
| _props, | |
| _rootContainerInstance, | |
| _hostContext | |
| ) { | |
| return false | |
| } | |
| function prepareUpdate( | |
| _instance, | |
| _type, | |
| _oldProps, | |
| _newProps, | |
| _rootContainerInstance, | |
| _hostContext | |
| ) { | |
| return UPDATE_SIGNAL | |
| } | |
| function shouldSetTextContent(_type, _props) { | |
| return false | |
| } | |
| function shouldDeprioritizeSubtree(_type, _props) { | |
| return false | |
| } | |
| function createTextInstance( | |
| _text, | |
| _rootContainerInstance, | |
| _hostContext, | |
| _internalInstanceHandle | |
| ) { | |
| invariant( | |
| false, | |
| "does not support text instances. Use Text component instead." | |
| ) | |
| } | |
| function prepareForCommit(_containerInfo) { | |
| // Noop | |
| } | |
| function resetAfterCommit(_containerInfo) { | |
| // Noop | |
| } | |
| function now() { | |
| return window.performance.now() | |
| } | |
| function commitUpdate( | |
| instance, | |
| _updatePayload, | |
| _type, | |
| oldProps, | |
| newProps, | |
| _internalInstanceHandle | |
| ) { | |
| applyProps(instance, oldProps, newProps) | |
| } | |
| function commitMount(_instance, _type, _newProps, _internalInstanceHandle) { | |
| // Noop | |
| } | |
| function commitTextUpdate(_textInstance, _oldText, _newText) { | |
| // Noop | |
| } | |
| function resetTextContent(_instance) { | |
| // Noop | |
| } | |
| // NOTE appendChild and appendChildToContainer are same.. | |
| function appendChild(parentInstance, child) { | |
| parentInstance.add(child) | |
| if (typeof child._customDidAttach === "function") { | |
| child._customDidAttach(child) | |
| } | |
| } | |
| function insertBefore(parentInstance, child, beforeChild) { | |
| invariant(child !== beforeChild, "cannot insert node before itself") | |
| const childExists = parentInstance.children.indexOf(child) !== -1 | |
| if (!childExists) { | |
| parentInstance.add(child) | |
| } | |
| } | |
| function removeChild(parentInstance, child) { | |
| if (typeof child._customWillDetach === "function") { | |
| child._customWillDetach(child) | |
| } | |
| parentInstance.remove(child) | |
| } | |
| const CustomRenderer = ReactFiberReconciler({ | |
| getRootHostContext: getRootHostContext, | |
| getChildHostContext: getChildHostContext, | |
| getPublicInstance: getPublicInstance, | |
| createInstance: createInstance, | |
| appendInitialChild: appendInitialChild, | |
| finalizeInitialChildren: finalizeInitialChildren, | |
| prepareUpdate: prepareUpdate, | |
| shouldSetTextContent: shouldSetTextContent, | |
| shouldDeprioritizeSubtree: shouldDeprioritizeSubtree, | |
| createTextInstance: createTextInstance, | |
| prepareForCommit: prepareForCommit, | |
| resetAfterCommit: resetAfterCommit, | |
| now: now, | |
| useSyncScheduling: true, | |
| commitUpdate: commitUpdate, | |
| commitMount: commitMount, | |
| commitTextUpdate: commitTextUpdate, | |
| resetTextContent: resetTextContent, | |
| appendChild: appendChild, | |
| appendChildToContainer: appendChild, | |
| insertBefore: insertBefore, | |
| insertInContainerBefore: insertBefore, | |
| removeChild: removeChild, | |
| removeChildFromContainer: removeChild, | |
| supportsMutation: true, | |
| supportsPersistence: false, | |
| supportsHydration: false, | |
| isPrimaryRenderer: true | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment