|
| 1 | +import Reconciler from 'react-reconciler-33'; |
| 2 | +import { |
| 3 | + ConcurrentRoot, |
| 4 | + DefaultEventPriority, |
| 5 | +} from 'react-reconciler-33/constants'; |
| 6 | + |
| 7 | +import propsEqual from './propsEqual'; |
| 8 | +import { ReconcilerFactory } from './types'; |
| 9 | + |
| 10 | +const emptyObject = {}; |
| 11 | + |
| 12 | +const logRecoverableError = console.error; |
| 13 | + |
| 14 | +const createRenderer: ReconcilerFactory = ({ |
| 15 | + appendChild, |
| 16 | + appendChildToContainer, |
| 17 | + commitTextUpdate, |
| 18 | + commitUpdate, |
| 19 | + createInstance, |
| 20 | + createTextInstance, |
| 21 | + insertBefore, |
| 22 | + removeChild, |
| 23 | + removeChildFromContainer, |
| 24 | + resetAfterCommit, |
| 25 | +}) => { |
| 26 | + const _commitUpdate = (instance, type, oldProps, newProps) => { |
| 27 | + if (propsEqual(oldProps, newProps)) return; |
| 28 | + commitUpdate(instance, null, type, oldProps, newProps); |
| 29 | + }; |
| 30 | + |
| 31 | + const reconciler = Reconciler({ |
| 32 | + appendChild, |
| 33 | + appendChildToContainer, |
| 34 | + appendInitialChild: appendChild, |
| 35 | + createInstance, |
| 36 | + createTextInstance, |
| 37 | + insertBefore, |
| 38 | + commitUpdate: _commitUpdate, |
| 39 | + commitTextUpdate, |
| 40 | + removeChild, |
| 41 | + removeChildFromContainer, |
| 42 | + resetAfterCommit, |
| 43 | + noTimeout: -1, |
| 44 | + shouldSetTextContent: () => false, |
| 45 | + finalizeInitialChildren: () => false, |
| 46 | + getPublicInstance: (instance) => instance, |
| 47 | + getRootHostContext: () => emptyObject, |
| 48 | + getChildHostContext: () => emptyObject, |
| 49 | + prepareForCommit() {}, |
| 50 | + clearContainer() {}, |
| 51 | + resetTextContent() {}, |
| 52 | + getCurrentUpdatePriority: () => DefaultEventPriority, |
| 53 | + maySuspendCommit: () => false, |
| 54 | + requestPostPaintCallback: () => {}, |
| 55 | + resolveUpdatePriority: () => DefaultEventPriority, |
| 56 | + setCurrentUpdatePriority: () => {}, |
| 57 | + shouldAttemptEagerTransition: () => false, |
| 58 | + }); |
| 59 | + |
| 60 | + const createContainer = (container) => { |
| 61 | + return reconciler.createContainer( |
| 62 | + container, // containerInfo: Container |
| 63 | + ConcurrentRoot, // tag: RootTag |
| 64 | + null, // hydration callbacks: null | SuspenseHydrationCallbacks |
| 65 | + false, // isStrictMode: boolean |
| 66 | + null, // concurrentUpdatesByDefaultOverride: null | boolean |
| 67 | + '', // identifierPrefix: string |
| 68 | + logRecoverableError, // onUncaughtError: (error: mixed, errorInfo: {+componentStack?: ?string}) => void |
| 69 | + logRecoverableError, // onCaughtError: (error: mixed, errorInfo: { ... }) => void |
| 70 | + logRecoverableError, // onRecoverableError: (error: mixed, errorInfo: {+componentStack?: ?string}) => void |
| 71 | + () => {}, // NEW IN REACT 19.2.0: onDefaultTransitionIndicator: () => void | (() => void) |
| 72 | + null, // transitionCallbacks: null | TransitionTracingCallbacks |
| 73 | + ); |
| 74 | + }; |
| 75 | + |
| 76 | + const updateContainer = (doc, mountNode, parentComponent, callback) => { |
| 77 | + reconciler.updateContainerSync(doc, mountNode, parentComponent, callback); |
| 78 | + reconciler.flushSyncWork(); |
| 79 | + }; |
| 80 | + |
| 81 | + return { |
| 82 | + createContainer, |
| 83 | + updateContainer, |
| 84 | + }; |
| 85 | +}; |
| 86 | + |
| 87 | +export default createRenderer; |
0 commit comments