react/shells/dev/app/index.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-01-23 03:04:37 +08:00
/** @flow */
// This test harness mounts each test app as a separate root to test multi-root applications.
2019-01-23 03:04:37 +08:00
import { createElement } from 'react';
import {
// $FlowFixMe Flow does not yet know about createRoot()
unstable_createRoot as createRoot,
} from 'react-dom';
import DeeplyNestedComponents from './DeeplyNestedComponents';
import EditableProps from './EditableProps';
import ElementTypes from './ElementTypes';
import Hydration from './Hydration';
import InspectableElements from './InspectableElements';
import InteractionTracing from './InteractionTracing';
import PriorityLevels from './PriorityLevels';
import ToDoList from './ToDoList';
import Toggle from './Toggle';
2019-04-05 07:29:47 +08:00
import SuspenseTree from './SuspenseTree';
2019-01-23 03:04:37 +08:00
import './styles.css';
const roots = [];
2019-01-23 03:04:37 +08:00
function mountHelper(App) {
const container = document.createElement('div');
((document.body: any): HTMLBodyElement).appendChild(container);
const root = createRoot(container);
root.render(createElement(App));
roots.push(root);
}
function mountTestApp() {
mountHelper(ToDoList);
mountHelper(InteractionTracing);
mountHelper(InspectableElements);
mountHelper(Hydration);
mountHelper(ElementTypes);
mountHelper(EditableProps);
mountHelper(PriorityLevels);
mountHelper(Toggle);
2019-04-05 07:29:47 +08:00
mountHelper(SuspenseTree);
mountHelper(DeeplyNestedComponents);
}
function unmountTestApp() {
roots.forEach(root => root.unmount());
}
mountTestApp();
window.parent.mountTestApp = mountTestApp;
window.parent.unmountTestApp = unmountTestApp;