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

Separate root and child functions #11

Closed
wants to merge 3 commits into from
Closed

Conversation

mcordova47
Copy link
Collaborator

Adds a Wrapper class, with two instances for root and child wrappers. This way, we can encode into the types whether a function has to run on the root wrapper, like update:

image

I think this should also extend to other things, like:

  • Does the function have to run on a single element?
  • Shallow vs. Full rendering

But I haven’t thought too much about it, yet.

@mcordova47 mcordova47 requested a review from fsoikin December 31, 2021 16:28
Copy link
Contributor

@fsoikin fsoikin left a comment

Choose a reason for hiding this comment

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

While the single/multiple distinction would indeed be useful, I think the root/child distinction doesn't help with anything. Logically, there is no reason functions should work differently between child and root elements, and indeed, in your code only the update function actually uses this distinction.

But there is no deep reason that update should be prohibited on child elements. It's just an implementation quirk of Enzyme.

From the end user perspective, update shouldn't even apply to any element in particular. Rather, it should affect "the world" (or, more precisely, the "current simulation").

There is no reason update should be prohibited inside a withSelector, quite the opposite: it creates an inconvenience. Now I have to exit the withSelector context just to call waitUntil

Currently update simply doesn't work inside a withSelector, but instead of explicitly preventing it from being called there, we should make it work. I'm pretty sure there is a way to find the root element by repeatedly calling parent, but even failing that, we can solve this by carrying around not just the "current" element, but the original root as well.

@mcordova47 mcordova47 closed this Dec 31, 2021
@mcordova47
Copy link
Collaborator Author

I'm pretty sure there is a way to find the root element by repeatedly calling parent, but even failing that, we can solve this by carrying around not just the "current" element, but the original root as well.

But the problem, I think, is how do you get the updated "current" element -- not just how to get the root.

@fsoikin
Copy link
Contributor

fsoikin commented Jan 1, 2022

Ah, I think there is a bit of misunderstanding here. The update function doesn't return an updated root functional-style, it just mutates the internal state of everything. And you can keep using your existing ElementWrapper objects, they still point to the same DOM elements.

But here's the kicker: apparently the Enzyme team had the same idea 3 years ago. Check this out: enzymejs/enzyme#1802 (comment)

And the comment was updated too: https://github.com/enzymejs/enzyme/pull/1802/files#diff-380144706937206c2b8ef0761bb879bc2c25e6cb11b7b31dd0091e5c690f5fddR226

But the docs are apparently out of date now.

@mcordova47 mcordova47 deleted the root-and-child-wrappers branch January 1, 2022 17:32
@mcordova47
Copy link
Collaborator Author

Interesting, but then does that mean this already works?

@fsoikin
Copy link
Contributor

fsoikin commented Jan 1, 2022

Yes, exactly

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

Successfully merging this pull request may close these issues.

2 participants