mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
* Enable Yarn workspaces for packages/* * Move src/isomorphic/* into packages/react/src/* * Create index.js stubs for all packages in packages/* This makes the test pass again, but breaks the build because npm/ folders aren't used yet. I'm not sure if we'll keep this structure--I'll just keep working and fix the build after it settles down. * Put FB entry point for react-dom into packages/* * Move src/renderers/testing/* into packages/react-test-renderer/src/* Note that this is currently broken because Jest ignores node_modules, and so Yarn linking makes Jest skip React source when transforming. * Remove src/node_modules It is now unnecessary. Some tests fail though. * Add a hacky workaround for Jest/Workspaces issue Jest sees node_modules and thinks it's third party code. This is a hacky way to teach Jest to still transform anything in node_modules/react* if it resolves outside of node_modules (such as to our packages/*) folder. I'm not very happy with this and we should revisit. * Add a fake react-native package * Move src/renderers/art/* into packages/react-art/src/* * Move src/renderers/noop/* into packages/react-noop-renderer/src/* * Move src/renderers/dom/* into packages/react-dom/src/* * Move src/renderers/shared/fiber/* into packages/react-reconciler/src/* * Move DOM/reconciler tests I previously forgot to move * Move src/renderers/native-*/* into packages/react-native-*/src/* * Move shared code into packages/shared It's not super clear how to organize this properly yet. * Add back files that somehow got lost * Fix the build * Prettier * Add missing license headers * Fix an issue that caused mocks to get included into build * Update other references to src/ * Re-run Prettier * Fix lint * Fix weird Flow violation I didn't change this file but Flow started complaining. Caleb said this annotation was unnecessarily using $Abstract though so I removed it. * Update sizes * Fix stats script * Fix packaging fixtures Use file: instead of NODE_PATH since NODE_PATH. NODE_PATH trick only worked because we had no react/react-dom in root node_modules, but now we do. file: dependency only works as I expect in Yarn, so I moved the packaging fixtures to use Yarn and committed lockfiles. Verified that the page shows up. * Fix art fixture * Fix reconciler fixture * Fix SSR fixture * Rename native packages
229 lines
5.2 KiB
JavaScript
229 lines
5.2 KiB
JavaScript
/**
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @providesModule ReactNativeCSFiberEntry
|
|
* @flow
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const ReactGenericBatching = require('ReactGenericBatching');
|
|
const ReactVersion = require('ReactVersion');
|
|
|
|
const {injectInternals} = require('ReactFiberDevToolsHook');
|
|
|
|
import type {ReactNativeCSType} from 'ReactNativeCSTypes';
|
|
|
|
const ReactFiberReconciler = require('ReactFiberReconciler');
|
|
|
|
const emptyObject = require('fbjs/lib/emptyObject');
|
|
|
|
export type Container = number;
|
|
export type Instance = number;
|
|
export type Props = Object;
|
|
export type TextInstance = number;
|
|
|
|
function processProps(instance: number, props: Props): Object {
|
|
const propsPayload = {};
|
|
for (var key in props) {
|
|
if (key === 'children') {
|
|
// Skip special case.
|
|
continue;
|
|
}
|
|
var value = props[key];
|
|
if (typeof value === 'function') {
|
|
value = {
|
|
style: 'rt-event',
|
|
event: key,
|
|
tag: instance,
|
|
};
|
|
}
|
|
propsPayload[key] = value;
|
|
}
|
|
return propsPayload;
|
|
}
|
|
|
|
function arePropsEqual(oldProps: Props, newProps: Props): boolean {
|
|
var key;
|
|
for (key in newProps) {
|
|
if (key === 'children') {
|
|
// Skip special case.
|
|
continue;
|
|
}
|
|
if (newProps[key] !== oldProps[key]) {
|
|
return false;
|
|
}
|
|
}
|
|
for (key in oldProps) {
|
|
if (key === 'children') {
|
|
// Skip special case.
|
|
continue;
|
|
}
|
|
if (!(key in newProps)) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
const ReactNativeCSFiberRenderer = ReactFiberReconciler({
|
|
appendInitialChild(
|
|
parentInstance: Instance,
|
|
child: Instance | TextInstance,
|
|
): void {},
|
|
|
|
createInstance(
|
|
type: string,
|
|
props: Props,
|
|
rootContainerInstance: Container,
|
|
hostContext: {},
|
|
internalInstanceHandle: Object,
|
|
): Instance {
|
|
return 0;
|
|
},
|
|
|
|
createTextInstance(
|
|
text: string,
|
|
rootContainerInstance: Container,
|
|
hostContext: {},
|
|
internalInstanceHandle: Object,
|
|
): TextInstance {
|
|
return 0;
|
|
},
|
|
|
|
finalizeInitialChildren(
|
|
parentInstance: Instance,
|
|
type: string,
|
|
props: Props,
|
|
rootContainerInstance: Container,
|
|
): boolean {
|
|
return false;
|
|
},
|
|
|
|
getRootHostContext(): {} {
|
|
return emptyObject;
|
|
},
|
|
|
|
getChildHostContext(): {} {
|
|
return emptyObject;
|
|
},
|
|
|
|
getPublicInstance(instance) {
|
|
return instance;
|
|
},
|
|
|
|
prepareForCommit(): void {},
|
|
|
|
prepareUpdate(
|
|
instance: Instance,
|
|
type: string,
|
|
oldProps: Props,
|
|
newProps: Props,
|
|
rootContainerInstance: Container,
|
|
hostContext: {},
|
|
): null | Object {
|
|
if (arePropsEqual(oldProps, newProps)) {
|
|
return null;
|
|
}
|
|
return processProps(instance, newProps);
|
|
},
|
|
|
|
resetAfterCommit(): void {},
|
|
|
|
shouldDeprioritizeSubtree(type: string, props: Props): boolean {
|
|
return false;
|
|
},
|
|
|
|
scheduleDeferredCallback: global.requestIdleCallback,
|
|
|
|
shouldSetTextContent(type: string, props: Props): boolean {
|
|
// TODO: Figure out when we should allow text content.
|
|
return false;
|
|
},
|
|
|
|
useSyncScheduling: true,
|
|
|
|
now(): number {
|
|
// TODO: Enable expiration by implementing this method.
|
|
return 0;
|
|
},
|
|
|
|
persistence: {
|
|
cloneInstance(
|
|
instance: Instance,
|
|
updatePayload: Object,
|
|
type: string,
|
|
oldProps: Props,
|
|
newProps: Props,
|
|
internalInstanceHandle: Object,
|
|
keepChildren: boolean,
|
|
): Instance {
|
|
return 0;
|
|
},
|
|
tryToReuseInstance(
|
|
instance: Instance,
|
|
updatePayload: Object,
|
|
type: string,
|
|
oldProps: Props,
|
|
newProps: Props,
|
|
internalInstanceHandle: Object,
|
|
keepChildren: boolean,
|
|
): Instance {
|
|
return 0;
|
|
},
|
|
|
|
createRootInstance(
|
|
rootContainerInstance: Container,
|
|
hostContext: {},
|
|
): Instance {
|
|
return 123;
|
|
},
|
|
commitRootInstance(rootInstance: Instance): void {},
|
|
},
|
|
});
|
|
|
|
const roots = new Map();
|
|
|
|
const ReactNativeCSFiber: ReactNativeCSType = {
|
|
render(element: React$Element<any>, containerTag: any, callback: ?Function) {
|
|
let root = roots.get(containerTag);
|
|
|
|
if (!root) {
|
|
// TODO (bvaughn): If we decide to keep the wrapper component,
|
|
// We could create a wrapper for containerTag as well to reduce special casing.
|
|
root = ReactNativeCSFiberRenderer.createContainer(containerTag, false);
|
|
roots.set(containerTag, root);
|
|
}
|
|
ReactNativeCSFiberRenderer.updateContainer(element, root, null, callback);
|
|
|
|
return ReactNativeCSFiberRenderer.getPublicRootInstance(root);
|
|
},
|
|
|
|
unmountComponentAtNode(containerTag: number) {
|
|
const root = roots.get(containerTag);
|
|
if (root) {
|
|
// TODO: Is it safe to reset this now or should I wait since this unmount could be deferred?
|
|
ReactNativeCSFiberRenderer.updateContainer(null, root, null, () => {
|
|
roots.delete(containerTag);
|
|
});
|
|
}
|
|
},
|
|
|
|
unstable_batchedUpdates: ReactGenericBatching.batchedUpdates,
|
|
|
|
flushSync: ReactNativeCSFiberRenderer.flushSync,
|
|
};
|
|
|
|
injectInternals({
|
|
findHostInstanceByFiber: ReactNativeCSFiberRenderer.findHostInstance,
|
|
// This is an enum because we may add more (e.g. profiler build)
|
|
bundleType: __DEV__ ? 1 : 0,
|
|
version: ReactVersion,
|
|
rendererPackageName: 'react-cs-renderer',
|
|
});
|
|
|
|
module.exports = ReactNativeCSFiber;
|