From aeba3c42aa45ecff3278b3596678108f9238ed16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Thu, 1 Feb 2018 18:38:19 +0000 Subject: [PATCH] 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 --- .../src/ReactFiberReconciler.js | 4 +- .../src/ReactFiberScheduler.js | 4 +- .../__tests__/ReactFiberHostContext-test.js | 48 +++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberReconciler.js b/packages/react-reconciler/src/ReactFiberReconciler.js index d4468bec565cc..5ad78944fb50f 100644 --- a/packages/react-reconciler/src/ReactFiberReconciler.js +++ b/packages/react-reconciler/src/ReactFiberReconciler.js @@ -93,8 +93,8 @@ export type HostConfig = { ): number, cancelDeferredCallback(callbackID: number): void, - prepareForCommit(): void, - resetAfterCommit(): void, + prepareForCommit(containerInfo: C): void, + resetAfterCommit(containerInfo: C): void, now(): number, diff --git a/packages/react-reconciler/src/ReactFiberScheduler.js b/packages/react-reconciler/src/ReactFiberScheduler.js index 979172c1fb7ac..19c8956537a7d 100644 --- a/packages/react-reconciler/src/ReactFiberScheduler.js +++ b/packages/react-reconciler/src/ReactFiberScheduler.js @@ -395,7 +395,7 @@ export default function( firstEffect = finishedWork.firstEffect; } - prepareForCommit(); + prepareForCommit(root.containerInfo); // Commit all the side-effects within a tree. We'll do this in two passes. // The first pass performs all the host insertions, updates, deletions and @@ -434,7 +434,7 @@ export default function( } stopCommitHostEffectsTimer(); - resetAfterCommit(); + resetAfterCommit(root.containerInfo); // The work-in-progress tree is now the current tree. This must come after // the first pass of the commit phase, so that the previous tree is still diff --git a/packages/react-reconciler/src/__tests__/ReactFiberHostContext-test.js b/packages/react-reconciler/src/__tests__/ReactFiberHostContext-test.js index a14da4ce57d21..6fb85bad98586 100644 --- a/packages/react-reconciler/src/__tests__/ReactFiberHostContext-test.js +++ b/packages/react-reconciler/src/__tests__/ReactFiberHostContext-test.js @@ -64,4 +64,52 @@ describe('ReactFiberHostContext', () => { ); expect(creates).toBe(2); }); + + it('should send the context to prepareForCommit and resetAfterCommit', () => { + let rootContext = {}; + const Renderer = ReactFiberReconciler({ + prepareForCommit: function(hostContext) { + expect(hostContext).toBe(rootContext); + }, + resetAfterCommit: function(hostContext) { + expect(hostContext).toBe(rootContext); + }, + getRootHostContext: function() { + return null; + }, + getChildHostContext: function() { + return null; + }, + shouldSetTextContent: function() { + return false; + }, + createInstance: function() { + return null; + }, + finalizeInitialChildren: function() { + return null; + }, + appendInitialChild: function() { + return null; + }, + now: function() { + return 0; + }, + mutation: { + appendChildToContainer: function() { + return null; + }, + }, + }); + + const container = Renderer.createContainer(rootContext); + Renderer.updateContainer( + + + , + container, + /* parentComponent: */ null, + /* callback: */ null, + ); + }); });