Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposes the host container to prepareForCommit and resetAfterCommit #12098

Merged
merged 4 commits into from
Feb 1, 2018

Conversation

arcanis
Copy link
Contributor

@arcanis arcanis commented Jan 25, 2018

This commit exposes containerInfo (which per my experience is the second parameter of the render functions, is that correct?) to prepareForCommit and more importantly resetAfterCommit.

I'm using this change in my custom renderer so that I can trigger a flush of my visual display after the React tree has been reconciled while not needing my visual server to be stored in a global.

@gaearon
Copy link
Collaborator

gaearon commented Jan 25, 2018

cc @sebmarkbage

Copy link
Collaborator

@sebmarkbage sebmarkbage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense. cc @acdlite

@@ -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: any): void,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should have the type C. The return data type needs some new generic type argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the typing (commit data referenced as CD), it seems to pass the flow test. I'd have expected to have to add an any into a generic type instantiation somewhere, but Flow seems able to infer it?

@sebmarkbage
Copy link
Collaborator

It would be good to have a test for this. E.g. the noop renderer could be expanded to use this somehow and use that for a test.

https://github.com/facebook/react/blob/master/packages/react-noop-renderer/src/ReactNoop.js#L176

@arcanis
Copy link
Contributor Author

arcanis commented Jan 25, 2018

Added tests. It currently doesn't check that the data parameter is correctly forwarded from prepareForCommit to resetAfterCommit, I wasn't sure if you'd prefer it to be tested in the same test or somewhere else, since it's not really about the host context (and found no other file testing prepareForCommit).

@sebmarkbage
Copy link
Collaborator

You can just add another file that more or less does what you do in your own renderer and the way you want to use it. Do you use the return value for something there? The closer to real-life that we can write the test, the better.

@arcanis
Copy link
Contributor Author

arcanis commented Jan 26, 2018

I've added the tests for the commit data. I don't use it right now, but it will be handy when I will get to implementing selection inside the renderer. I noticed it had been removed in #9816, but running flow doesn't yield any error here.

return (savedCommitData = {});
},
resetAfterCommit: function(hostContext, commitData) {
expect(commitData).toBe(savedCommitData);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you try to come up with a test case that's more representative of a real world use case? As suggested in Sebastian's comment. Ideally a person should be able to look at this unit test and understand not just what the method does, but why it exists.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will be handy when I will get to implementing selection inside the renderer

This sounds interesting. If you can approximate this use case in the unit test, maybe with some comments to clarify, I'll merge the PR :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I don't use it in my renderer at the moment I removed the commit data from this PR, I'll open a new one when I'll reach the point where it is needed :)

@acdlite acdlite merged commit aeba3c4 into facebook:master Feb 1, 2018
@acdlite
Copy link
Collaborator

acdlite commented Feb 1, 2018

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants