Skip to content

Conversation

@gaearon
Copy link
Collaborator

@gaearon gaearon commented Dec 9, 2016

As discussed in #8490 (comment).

function getRootHostContainer() : C {
if (containerDepth === -1) {
throw new Error('Expected to find a root container.');
if (rootInstance == null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

For the new Context API I was thinking that we should require a default value so that the type is always guaranteed to be satisfied and the user doesn't have to add extra null checks. Maybe we should do the same for host context?

contextFibers,
contextValues,
contextDepth,
};
Copy link
Collaborator

@sebmarkbage sebmarkbage Dec 9, 2016

Choose a reason for hiding this comment

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

Why does context arrays have to be stored separately here? Can't you just push another context onto the stack of contexts? Even if that is null. Then pop it on the way back up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd need to know how many can I pop. If I make null the sentinel then I need to somehow forbid renderers from specifying something like string | null as type argument. Is this even possible with Flow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh never mind, I see how this could work.

This lets us keep subtrees separated without maintaining independent context arrays for subtrees.
@gaearon
Copy link
Collaborator Author

gaearon commented Dec 10, 2016

Addressed #8544 (comment) in 6463d67.
I don't see benefits to addressing #8544 (comment) here. Maybe let's think again when we unify?

rootInstance = portalStack[portalDepth];
portalStack[portalDepth] = null;
portalDepth--;
// If we pushed any context while in a portal, we need to roll it back.
Copy link
Collaborator

Choose a reason for hiding this comment

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

How can you ever pop a host container with a context deeper than one null? Wouldn't this always be exactly one null?

Because any new context provider will be below the portal in the tree and pop on the way up to the portal.

Think of this problem in terms of a normal execution stack. You wouldn't need multiple arrays and these special cases for unwinding in a normal execution stack other than when you unwind for errors so you shouldn't need it here.

I was trying to be smart but didn't need to.
containerDepth--;
}

function getHostContext() : CX | null {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ideally getHotsContext could just return a value from the closure instead of going through the array just like getRootHostContainer does.

@gaearon gaearon merged commit 0f34bdc into facebook:master Dec 12, 2016
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.

3 participants