Exposes the host container to prepareForCommit and resetAfterCommit (#12098)
* Exposes the host container to prepareForCommit and resetAfterCommit * Uses better typing * Adds tests * Removes commit data
Maël Nison committed
Feb 1, 2018 at 18:38 UTC
aeba3c42aa45ecff3278b3596678108f9238ed16
3 files changed
+52
-4
packages/react-reconciler/src/ReactFiberReconciler.js
+2
-2
@@ -93,8 +93,8 @@ export type HostConfig<T, P, I, TI, HI, PI, C, CC, CX, PL> = {
93
): number,
94
cancelDeferredCallback(callbackID: number): void,
95
96
- prepareForCommit(): void,
97
- resetAfterCommit(): void,
96
+ prepareForCommit(containerInfo: C): void,
97
+ resetAfterCommit(containerInfo: C): void,
98
99
now(): number,
100
packages/react-reconciler/src/ReactFiberScheduler.js
+2
-2
@@ -395,7 +395,7 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
395
firstEffect = finishedWork.firstEffect;
396
}
397
398
- prepareForCommit();
398
+ prepareForCommit(root.containerInfo);
399
400
// Commit all the side-effects within a tree. We'll do this in two passes.
401
// The first pass performs all the host insertions, updates, deletions and
@@ -434,7 +434,7 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
434
}
435
stopCommitHostEffectsTimer();
436
437
- resetAfterCommit();
437
+ resetAfterCommit(root.containerInfo);
438
439
// The work-in-progress tree is now the current tree. This must come after
440
// the first pass of the commit phase, so that the previous tree is still
packages/react-reconciler/src/__tests__/ReactFiberHostContext-test.js
+48
@@ -64,4 +64,52 @@ describe('ReactFiberHostContext', () => {
64
);
65
expect(creates).toBe(2);
66
});
67
+
68
+ it('should send the context to prepareForCommit and resetAfterCommit', () => {
69
+ let rootContext = {};
70
+ const Renderer = ReactFiberReconciler({
71
+ prepareForCommit: function(hostContext) {
72
+ expect(hostContext).toBe(rootContext);
73
+ },
74
+ resetAfterCommit: function(hostContext) {
75
+ expect(hostContext).toBe(rootContext);
76
+ },
77
+ getRootHostContext: function() {
78
+ return null;
79
+ },
80
+ getChildHostContext: function() {
81
+ return null;
82
+ },
83
+ shouldSetTextContent: function() {
84
+ return false;
85
+ },
86
+ createInstance: function() {
87
+ return null;
88
+ },
89
+ finalizeInitialChildren: function() {
90
+ return null;
91
+ },
92
+ appendInitialChild: function() {
93
+ return null;
94
+ },
95
+ now: function() {
96
+ return 0;
97
+ },
98
+ mutation: {
99
+ appendChildToContainer: function() {
100
+ return null;
101
+ },
102
+ },
103
+ });
104
+
105
+ const container = Renderer.createContainer(rootContext);
106
+ Renderer.updateContainer(
107
+ <a>
108
+ <b />
109
+ </a>,
110
+ container,
111
+ /* parentComponent: */ null,
112
+ /* callback: */ null,
113
+ );
114
+ });
115
});