Skip to content

Commit 595a489

Browse files
committed
appease flow
1 parent 73fb871 commit 595a489

File tree

4 files changed

+65
-29
lines changed

4 files changed

+65
-29
lines changed

src/renderers/dom/fiber/ReactDOMFiber.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ var DOMRenderer = ReactFiberReconciler({
143143
},
144144

145145
prepareForCommit() : CommitInfo {
146-
eventsEnabled = ReactBrowserEventEmitter.isEnabled();
146+
const eventsEnabled = ReactBrowserEventEmitter.isEnabled();
147147
ReactBrowserEventEmitter.setEnabled(false);
148148
return {
149149
eventsEnabled,

src/renderers/shared/fiber/ReactFiberCommitWork.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,6 @@ module.exports = function<T, P, I, TI, C, CX, CI>(
8585
}
8686
}
8787

88-
function attachRef(current : ?Fiber, finishedWork : Fiber, instance : any) {
89-
const ref = finishedWork.ref;
90-
if (ref && (!current || current.ref !== ref)) {
91-
ref(getPublicInstance(instance));
92-
}
93-
}
94-
9588
function getHostParent(fiber : Fiber) : I | C {
9689
let parent = fiber.return;
9790
while (parent) {
@@ -470,7 +463,7 @@ module.exports = function<T, P, I, TI, C, CX, CI>(
470463
}
471464
const ref = finishedWork.ref;
472465
if (ref) {
473-
const instance = finishedWork.stateNode;
466+
const instance = getPublicInstance(finishedWork.stateNode);
474467
ref(instance);
475468
}
476469
}

src/renderers/shared/fiber/ReactFiberReconciler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export type HostConfig<T, P, I, TI, C, CX, CI> = {
4747

4848
getRootHostContext(rootContainerInstance : C) : CX,
4949
getChildHostContext(parentHostContext : CX, type : T) : CX,
50-
getPublicInstance(instance : I) : I | any,
50+
getPublicInstance(instance : I | TI) : any, // maybe add a PI (public instance type)?
5151

5252
createInstance(type : T, props : P, rootContainerInstance : C, hostContext : CX, internalInstanceHandle : OpaqueNode) : I,
5353
appendInitialChild(parentInstance : I, child : I | TI) : void,

src/renderers/testing/ReactTestRendererFiber.js

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@
1515

1616
var ReactFiberReconciler = require('ReactFiberReconciler');
1717
var emptyObject = require('emptyObject');
18-
var invariant = require('invariant');
1918

20-
import type { ReactElement } from 'ReactElementType';
21-
import type { ReactInstance } from 'ReactInstanceType';
19+
import type { TestRendererOptions } from 'ReactTestMount';
2220

2321
type ReactTestRendererJSON = {
2422
type: string,
2523
props: { [propName: string]: string },
26-
children: null | Array<string | ReactTestRendererJSON>,
24+
children: null | Array<string | number | ReactTestRendererJSON>,
2725
$$typeof?: any
2826
}
2927

3028
let instanceCounter = 0;
3129

3230
class TestContainer {
31+
rootID: string;
32+
createNodeMock: Function;
33+
3334
constructor(rootID, createNodeMock) {
3435
this.rootID = rootID;
3536
this.createNodeMock = createNodeMock;
@@ -41,6 +42,13 @@ class TestContainer {
4142
}
4243

4344
class TestComponent {
45+
id: number;
46+
props: Object;
47+
type: string;
48+
rootContainerInstance: TestContainer;
49+
children: Array<Instance | TextInstance>;
50+
$$typeof: Symbol;
51+
4452
constructor(type, props, rootContainerInstance) {
4553
this.id = instanceCounter++;
4654
this.type = type;
@@ -93,7 +101,7 @@ class TestComponent {
93101
// eslint-disable ignore the children
94102
const {children, ...props} = this.props;
95103
// eslint-enable
96-
const json = {
104+
const json: ReactTestRendererJSON = {
97105
type: this.type,
98106
props: props,
99107
children: null,
@@ -108,7 +116,7 @@ class TestComponent {
108116
if (typeof child.toJSON === 'function') {
109117
childrenJSON.push(child.toJSON());
110118
} else if (typeof child.text !== 'undefined') {
111-
childrenJSON.push(isNaN(+child.text) ? child.text : +child.text);
119+
childrenJSON.push();
112120
}
113121
});
114122
json.children = childrenJSON.length ? childrenJSON : null;
@@ -117,17 +125,22 @@ class TestComponent {
117125
}
118126
}
119127

128+
type Container = TestContainer;
129+
type Props = Object;
120130
type Instance = TestComponent;
131+
type TextInstance = {
132+
text: string | number,
133+
id: number,
134+
rootContainerInstance: Container,
135+
toJSON(): string | number,
136+
};
121137

122138
var TestRenderer = ReactFiberReconciler({
123-
getRootHostContext(rootContainerInstance : Container) : HostContext {
139+
getRootHostContext() {
124140
return emptyObject;
125141
},
126142

127-
getChildHostContext(
128-
parentHostContext : HostContext,
129-
type : string,
130-
) : HostContext {
143+
getChildHostContext() {
131144
return emptyObject;
132145
},
133146

@@ -143,7 +156,7 @@ var TestRenderer = ReactFiberReconciler({
143156
type : string,
144157
props : Props,
145158
rootContainerInstance : Container,
146-
hostContext : HostContext,
159+
hostContext : Object,
147160
internalInstanceHandle : Object,
148161
) : Instance {
149162
return new TestComponent(type, props, rootContainerInstance);
@@ -158,17 +171,18 @@ var TestRenderer = ReactFiberReconciler({
158171
type : string,
159172
props : Props,
160173
rootContainerInstance : Container,
161-
) : void {
174+
) : boolean {
162175
// console.log('finalizeInitialChildren');
163176
// setInitialProperties(testElement, type, props, rootContainerInstance);
177+
return false;
164178
},
165179

166180
prepareUpdate(
167181
testElement : Instance,
168182
type : string,
169183
oldProps : Props,
170184
newProps : Props,
171-
hostContext : HostContext,
185+
hostContext : Object,
172186
) : boolean {
173187
return true;
174188
},
@@ -184,6 +198,16 @@ var TestRenderer = ReactFiberReconciler({
184198
instance.update(type, newProps);
185199
},
186200

201+
commitMount(
202+
instance : Instance,
203+
type : string,
204+
newProps : Props,
205+
rootContainerInstance : Object,
206+
internalInstanceHandle : Object
207+
) : void {
208+
// Noop
209+
},
210+
187211
shouldSetTextContent(props : Props) : boolean {
188212
return (
189213
typeof props.children === 'string' ||
@@ -196,10 +220,15 @@ var TestRenderer = ReactFiberReconciler({
196220
createTextInstance(
197221
text : string,
198222
rootContainerInstance : Container,
199-
hostContext : HostContext,
223+
hostContext : Object,
200224
internalInstanceHandle : Object
201225
) : TextInstance {
202-
var inst = { text : text, id: instanceCounter++ };
226+
var inst = {
227+
text : text,
228+
id: instanceCounter++,
229+
rootContainerInstance,
230+
toJSON: () => isNaN(+inst.text) ? inst.text : +inst.text,
231+
};
203232
// Hide from unit tests
204233
Object.defineProperty(inst, 'id', { value: inst.id, enumerable: false });
205234
return inst;
@@ -245,33 +274,47 @@ var defaultTestOptions = {
245274
};
246275

247276
var ReactTestFiberRenderer = {
248-
create(element, options) {
277+
create(element: ReactElement<any>, options: TestRendererOptions) {
249278
var createNodeMock = defaultTestOptions.createNodeMock;
250279
if (options && typeof options.createNodeMock === 'function') {
251280
createNodeMock = options.createNodeMock;
252281
}
253282
var container = new TestContainer('<default>', createNodeMock);
254283
var root = TestRenderer.createContainer(container);
255-
TestRenderer.updateContainer(element, root, null, null);
284+
if (root) {
285+
TestRenderer.updateContainer(element, root, null, null);
286+
}
256287
return {
257288
toJSON() {
289+
if (root == null) {
290+
return null;
291+
}
258292
const hostInstance = TestRenderer.findHostInstance(root);
259293
if (hostInstance === null) {
260294
return hostInstance;
261295
}
262296
return hostInstance.toJSON();
263297
},
264298

265-
update(newElement) {
299+
update(newElement: ReactElement<any>) {
300+
if (root == null) {
301+
return;
302+
}
266303
TestRenderer.updateContainer(newElement, root, null, null);
267304
},
268305
unmount() {
306+
if (root == null) {
307+
return;
308+
}
269309
TestRenderer.updateContainer(null, root, null, () => {
270310
container = null;
271311
root = null;
272312
});
273313
},
274314
getInstance() {
315+
if (root == null) {
316+
return null;
317+
}
275318
return TestRenderer.getPublicRootInstance(root);
276319
},
277320
};

0 commit comments

Comments
 (0)