-
Notifications
You must be signed in to change notification settings - Fork 638
/
beginComponent.js
78 lines (65 loc) · 1.99 KB
/
beginComponent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"use strict";
const ComponentDef = require("./ComponentDef");
var FLAG_WILL_RERENDER_IN_BROWSER = 1;
// var FLAG_HAS_BODY_EL = 2;
// var FLAG_HAS_HEAD_EL = 4;
var FLAG_OLD_HYDRATE_NO_CREATE = 8;
module.exports = function beginComponent(
componentsContext,
component,
key,
ownerComponentDef,
isSplitComponent,
isImplicitComponent
) {
var componentId = component.id;
var componentDef = (componentsContext.___componentDef = new ComponentDef(
component,
componentId,
componentsContext
));
var ownerIsRenderBoundary =
ownerComponentDef && ownerComponentDef.___renderBoundary;
var ownerWillRerender =
ownerComponentDef &&
ownerComponentDef.___flags & FLAG_WILL_RERENDER_IN_BROWSER;
// On the server
if (!componentsContext.___isPreserved && ownerWillRerender) {
componentDef.___flags |= FLAG_WILL_RERENDER_IN_BROWSER;
return componentDef;
}
if (isImplicitComponent === true) {
// We don't mount implicit components rendered on the server
// unless the implicit component is nested within a UI component
// that will re-render in the browser
return componentDef;
}
componentsContext.___components.push(componentDef);
let out = componentsContext.___out;
let runtimeId = out.global.runtimeId;
componentDef.___renderBoundary = true;
if (isSplitComponent === false && out.global.noBrowserRerender !== true) {
componentDef.___flags |= FLAG_WILL_RERENDER_IN_BROWSER;
componentDef.___parentPreserved = componentsContext.___isPreserved;
componentsContext.___isPreserved = false;
}
if (out.global.oldHydrateNoCreate === true) {
componentDef.___flags |= FLAG_OLD_HYDRATE_NO_CREATE;
}
if ((ownerIsRenderBoundary || ownerWillRerender) && key != null) {
out.w(
"<!--" +
runtimeId +
"^" +
componentId +
" " +
ownerComponentDef.id +
" " +
key +
"-->"
);
} else {
out.w("<!--" + runtimeId + "#" + componentId + "-->");
}
return componentDef;
};