Skip to content

Commit

Permalink
Exposes the host container to prepareForCommit and resetAfterCommit (#…
Browse files Browse the repository at this point in the history
…12098)

* Exposes the host container to prepareForCommit and resetAfterCommit

* Uses better typing

* Adds tests

* Removes commit data
  • Loading branch information
arcanis authored and acdlite committed Feb 1, 2018
1 parent e202f98 commit aeba3c4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export type HostConfig<T, P, I, TI, HI, PI, C, CC, CX, PL> = {
): number,
cancelDeferredCallback(callbackID: number): void,

prepareForCommit(): void,
resetAfterCommit(): void,
prepareForCommit(containerInfo: C): void,
resetAfterCommit(containerInfo: C): void,

now(): number,

Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
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
Expand Down Expand Up @@ -434,7 +434,7 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
}
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<a>
<b />
</a>,
container,
/* parentComponent: */ null,
/* callback: */ null,
);
});
});

0 comments on commit aeba3c4

Please sign in to comment.