Skip to content

Commit

Permalink
flow ReactPartialRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdustan committed Oct 17, 2017
1 parent 56e5288 commit 6484d95
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions src/renderers/shared/server/ReactPartialRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* @providesModule ReactPartialRenderer
* @flow
*/

'use strict';
Expand Down Expand Up @@ -159,7 +160,7 @@ function createMarkupForStyles(styles, component) {
}

function warnNoop(
publicInstance: ReactComponent<any, any, any>,
publicInstance: React.Component<any, any, any>,
callerName: string,
) {
if (__DEV__) {
Expand Down Expand Up @@ -320,6 +321,7 @@ function validateRenderResult(child, type) {

function resolve(child, context) {
while (React.isValidElement(child)) {
child = (child: React.Element);
if (__DEV__) {
pushElementToDebugStack(child);
}
Expand Down Expand Up @@ -443,18 +445,33 @@ function resolve(child, context) {
return {child, context};
}

type Frame = {
domNamespace: string,
children: any,
childIndex: number,
context: Object,
footer: string,
debugElementStack: Array<any>,
};

class ReactDOMServerRenderer {
constructor(element, makeStaticMarkup) {
stack: Array<Frame>;
exhausted: boolean;
currentSelectValue: null;
previousWasTextNode: boolean;
makeStaticMarkup: boolean;

constructor(element: React.Element | Array<React.Element>, makeStaticMarkup: boolean) {
var children = React.isValidElement(element) ? [element] : toArray(element);
var topFrame = {
var topFrame: Frame = ({
// Assume all trees start in the HTML namespace (not totally true, but
// this is what we did historically)
domNamespace: Namespaces.html,
children,
childIndex: 0,
context: emptyObject,
footer: '',
};
}: any);
if (__DEV__) {
topFrame.debugElementStack = [];
}
Expand All @@ -465,7 +482,7 @@ class ReactDOMServerRenderer {
this.makeStaticMarkup = makeStaticMarkup;
}

read(bytes) {
read(bytes: number) {
if (this.exhausted) {
return null;
}
Expand Down Expand Up @@ -502,7 +519,11 @@ class ReactDOMServerRenderer {
return out;
}

render(child, context, parentNamespace) {
render(
child: string | number | React.Element,
context: Object,
parentNamespace: string
) {
if (typeof child === 'string' || typeof child === 'number') {
var text = '' + child;
if (text === '') {
Expand All @@ -525,13 +546,13 @@ class ReactDOMServerRenderer {
return this.renderDOM(child, context, parentNamespace);
} else {
var children = toArray(child);
var frame = {
var frame: Frame = ({
domNamespace: parentNamespace,
children,
childIndex: 0,
context: context,
footer: '',
};
}: Object);
if (__DEV__) {
frame.debugElementStack = [];
}
Expand All @@ -542,7 +563,11 @@ class ReactDOMServerRenderer {
}
}

renderDOM(element, context, parentNamespace) {
renderDOM(
element: React.Element,
context: Object,
parentNamespace: string
) {
var tag = element.type.toLowerCase();

let namespace = parentNamespace;
Expand Down Expand Up @@ -821,14 +846,14 @@ class ReactDOMServerRenderer {
} else {
children = toArray(props.children);
}
var frame = {
var frame: Frame = ({
domNamespace: getChildNamespace(parentNamespace, element.type),
tag,
children,
childIndex: 0,
context: context,
footer: footer,
};
}: any);
if (__DEV__) {
frame.debugElementStack = [];
}
Expand Down

0 comments on commit 6484d95

Please sign in to comment.