1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 | var ReactFiberReconciler = require('./ReactFiberReconciler');
|
13 |
|
14 | var warning = require('fbjs/lib/warning');
|
15 |
|
16 | function recursivelyAppendChildren(parent, child) {
|
17 | if (!child) {
|
18 | return;
|
19 | }
|
20 |
|
21 | if (child.nodeType === 1) {
|
22 |
|
23 | parent.appendChild(child);
|
24 | } else {
|
25 |
|
26 | var node = child;
|
27 | do {
|
28 | recursivelyAppendChildren(parent, node.output);
|
29 | } while (node = node.sibling);
|
30 | }
|
31 | }
|
32 |
|
33 | var DOMRenderer = ReactFiberReconciler({
|
34 | updateContainer: function (container, children) {
|
35 | container.innerHTML = '';
|
36 | recursivelyAppendChildren(container, children);
|
37 | },
|
38 | createInstance: function (type, props, children) {
|
39 | var domElement = document.createElement(type);
|
40 | recursivelyAppendChildren(domElement, children);
|
41 | if (typeof props.children === 'string') {
|
42 | domElement.textContent = props.children;
|
43 | }
|
44 | return domElement;
|
45 | },
|
46 | prepareUpdate: function (domElement, oldProps, newProps, children) {
|
47 | return true;
|
48 | },
|
49 | commitUpdate: function (domElement, oldProps, newProps, children) {
|
50 | domElement.innerHTML = '';
|
51 | recursivelyAppendChildren(domElement, children);
|
52 | if (typeof newProps.children === 'string') {
|
53 | domElement.textContent = newProps.children;
|
54 | }
|
55 | },
|
56 | deleteInstance: function (instance) {
|
57 |
|
58 | },
|
59 |
|
60 |
|
61 | scheduleAnimationCallback: window.requestAnimationFrame,
|
62 |
|
63 | scheduleDeferredCallback: window.requestIdleCallback
|
64 | });
|
65 |
|
66 | var warned = false;
|
67 |
|
68 | function warnAboutUnstableUse() {
|
69 | process.env.NODE_ENV !== 'production' ? warning(warned, 'You are using React DOM Fiber which is an experimental renderer. ' + 'It is likely to have bugs, breaking changes and is unsupported.') : void 0;
|
70 | warned = true;
|
71 | }
|
72 |
|
73 | var ReactDOM = {
|
74 | render: function (element, container) {
|
75 | warnAboutUnstableUse();
|
76 | if (!container._reactRootContainer) {
|
77 | container._reactRootContainer = DOMRenderer.mountContainer(element, container);
|
78 | } else {
|
79 | DOMRenderer.updateContainer(element, container._reactRootContainer);
|
80 | }
|
81 | },
|
82 | unmountComponentAtNode: function (container) {
|
83 | warnAboutUnstableUse();
|
84 | var root = container._reactRootContainer;
|
85 | if (root) {
|
86 |
|
87 |
|
88 | container._reactRootContainer = null;
|
89 | DOMRenderer.unmountContainer(root);
|
90 | }
|
91 | }
|
92 | };
|
93 |
|
94 | module.exports = ReactDOM; |
\ | No newline at end of file |