-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Components implementation #91
Conversation
Am I mistaken or are props and state both represented by the component struct's properties? What happens if a prop changes both as state and as a prop (from the inside and from the outside)? |
Thanks @deniskolodin, this is great! I also have some similar questions about props vs state, how they're treated within a component. Right now it seems they're one and same, wondering if it might we worth separating them into two models or separate structs, one internally managed per component, one externally provided, much like React. But perhaps I'm missing something that works better in the Elm model... |
According to the upgrading of counter demo
This PR still experimental and I will improve ergonomics of API. Also I want to add properties and events. Apparently it will not fields of the model, but I haven't chosen the implementation yet. I continue to experiment. |
Thanks @deniskolodin, great to see your experimental work so far, let us know if there's anything we can do to help |
Method new expects ownership to a unwrapped context instance
Models were not split into multiple small components
And remove Default trait requirement.
It works on component initialization only.
Also PartialEq implementation was added
Properties work not so fast because we should use pool of calls for components update (now `setTimeout` used which is throttled)
I've been playing with your latest commits, thanks for your hard work! One thing I've noticed is when I render a component, it's getting wrapped in a Here's an example: I'm using a component to generate table rows, and the Thanks again for all the time you're putting into Yew, I'm excited to see the components API coming together! |
var task = null; | ||
var pool = []; | ||
var routine = function() { }; | ||
var schedule_routine = function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of having routine start as a noop, as opposed to defining it at the top?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a tradition to pass no-use-before-define
lint. Is it safe to take advantage of var
behaviour when everything actually defines at top? Will it work in the future? I saw that let
doesn't work this way. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having two functions that call each other can get a little hairy. Is there a reason that schedule_routine
is a different function? My immediate thoughts on this are that you could just inline that function and avoid the two functions referencing each other. Alternatively, the schedule_routine
function can take routine
as an argument, if you want it to be a general purpose utility to avoid code reuse. Another options is to pull the if block that calls schedule_routine into another funciton that is put into the setTimeout, so it would be something like:
...
task = setTimeout(() => {
routine();
if (pool.length > 0) {
schedule_routine();
}
});
...
@machineloop Thank you for the review! You are right, enclosing
|
Thanks @deniskolodin, great work, looking forward to the next steps after merge! |
9bd4679
to
aefe098
Compare
aefe098
to
da54bd5
Compare
This PR is ready to merge. I've tested components and them work fine 🎉 Still need to fix some imperfections after merging (remove redundant enclosing |
This is the first draft of components implementation. It breaks backward-compatibility and nominated to 0.3 version.
For demonstration I created example with 1'000 components which work independently. I broke contexts and services (because isolated loop of
App
used for every component), but I'll repair them.