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

Introducing functional components #1032

Merged
merged 26 commits into from
Mar 16, 2020
Merged

Conversation

ZainlessBrombie
Copy link
Collaborator

Details in proposal #1026
I think the two main questions are whether the use_effect hook should always run if no arguments are supplied or always, and if FunctionProvider and FunctionComponent are appropriate names

@ZainlessBrombie
Copy link
Collaborator Author

Huh build failed. Worked on my machine 🤔

@ZainlessBrombie
Copy link
Collaborator Author

Oh right wasm-pack is missing from the build server, but I'm using it to run the tests

@ZainlessBrombie
Copy link
Collaborator Author

Another question comes to mind: Should the firing of use_effect cause the component to rerender? It currently does but in retrospect i don't think it should. Instead the setstate method called inside use_effect is what should be causing a rerender.
Future optimizations include rerendering the component only once for multiple calls to setstate. I think a renderpass counter may do the trick for that. Alternatively a next_tick worker queue may be used.

Copy link
Member

@jstarry jstarry left a comment

Choose a reason for hiding this comment

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

This is awesome! Thanks for taking on this proposal, I cannot wait to use it in my project :D

I'm really excited about adding context hooks in the future as well, it will ease a lot of state management headaches.

I have a concern over the restrictiveness of hook ordering.. it's a runtime check unfortunately. So if anyone wraps a hook in a conditional they will get panics. But maybe React has this problem too? I'm curious your thoughts on it.

In regards to use_effect, do you think it should be called after the component is mounted? Maybe promise wrapping it would do the trick.

Thanks again!

Cargo.toml Outdated Show resolved Hide resolved
crates/functional-yew/Cargo.toml Outdated Show resolved Hide resolved
.travis.yml Outdated Show resolved Hide resolved
crates/functional-yew/src/lib.rs Outdated Show resolved Hide resolved
crates/functional-yew/src/lib.rs Outdated Show resolved Hide resolved
crates/functional-yew/src/lib.rs Outdated Show resolved Hide resolved
crates/functional-yew/src/lib.rs Outdated Show resolved Hide resolved
crates/functional-yew/src/lib.rs Outdated Show resolved Hide resolved
crates/functional-yew/src/lib.rs Outdated Show resolved Hide resolved
crates/functional-yew/src/lib.rs Outdated Show resolved Hide resolved
@ZainlessBrombie
Copy link
Collaborator Author

ZainlessBrombie commented Mar 15, 2020

@jstarry Alright use_effect is now refactored to run on next tick 👍
Edit: Also, this reduces rerender count for sequential changes :)
Do you think functional yew is a good name or should we name it something with "hooks"?

ci/run_tests.sh Outdated Show resolved Hide resolved
@jstarry
Copy link
Member

jstarry commented Mar 16, 2020

Hey, I really think this PR should be split. Use effect still needs work and will likely need some core framework changes. Can you remove all use effect code so that we have the foundation in place earlier and then can iterate on use effect implementation?

@ZainlessBrombie
Copy link
Collaborator Author

If you insist I can remove it of course, but I honestly think use_effect is too essential to skip it :/
By framework changes, do you mean the multiple render on multiple messages thing?

@ZainlessBrombie
Copy link
Collaborator Author

ZainlessBrombie commented Mar 16, 2020

Also I've removed next_tick and replaced it by making message a Box<FnOnce() -> bool>. This does indeed now rely on the framework to batch renders.

@jstarry
Copy link
Member

jstarry commented Mar 16, 2020

If you insist I can remove it of course, but I honestly think use_effect is too essential to skip it :/

Not remove, just move use_effect code to a new PR so that the changes are more clear.

@jstarry
Copy link
Member

jstarry commented Mar 16, 2020

I like to give detailed reviews on smaller PRs. This change is already pretty big and hard to keep up with what has changed since the last time I viewed

@ZainlessBrombie
Copy link
Collaborator Author

Ah I see, sorry
I'll have to change the tests since they rely on use_effect after that I can remove use_effect :)

@ZainlessBrombie
Copy link
Collaborator Author

Alright. use_effect is out 👍

Copy link
Member

@jstarry jstarry left a comment

Choose a reason for hiding this comment

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

Great, thanks for splitting out the use_effect code temporarily! It's fine to keep the commented out tests. As soon as you address my last few comments, we can merge this in and work on getting use_effect in!

@jstarry
Copy link
Member

jstarry commented Mar 16, 2020

Also I've removed next_tick and replaced it by making message a Box<FnOnce() -> bool>. This does indeed now rely on the framework to batch renders.

Nice solution! And thanks for writing up #1034!

@ZainlessBrombie
Copy link
Collaborator Author

Yw :)
Alright I addressed your comments and actually also removed the commented out use_effect tests, I'll reintroduce them in the next PR.

@jstarry
Copy link
Member

jstarry commented Mar 16, 2020

Thanks for the cleanup!

@ZainlessBrombie
Copy link
Collaborator Author

You're welcome, I appreciate your dedication to the PR and having everything orderly :)
Looking forward to use_effect

@jstarry jstarry merged commit c33fe73 into yewstack:master Mar 16, 2020
@Tehnix Tehnix mentioned this pull request Apr 14, 2020
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