-
Notifications
You must be signed in to change notification settings - Fork 155
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
Control flow in template! #18
Comments
Hi, I just saw this project and I really like it. I tried to implement this by implementing nested effects, but it was much harder than expected and I couldn't get it to work. Do you have a better idea for how this can be accomplished? |
First off, for the design, there are two potential ways to implement this. The most obvious one would be to introduce I am personally in favor of the first option, that is, adding control flow directly to Arguments for favoring the second option, that is, using components, would include a simpler and smaller API. We would just need to build these components. In any case, for the actual logic for rendering templates with control flow, it should just use template! {
@if condition()
p { # "true" }
} else {
p { # "false" }
}
}
// expands to
{
let node = /* unintialized_placeholder */;
create_effect(move || {
if condition() {
let element = create_element("p");
append(&element, text("true");
element
} else {
let element = create_element("p");
append(&element, text("false");
element
}
});
node.unwrap()
} |
@TheRawMeatball I saw you're work here TheRawMeatball@f1a4ede and new code was pushed over in #20 so you might want to try rebasing. I think it would be better if you created a PR for nested effects first, if you want of course. If not, let me know and I'll be happy to do it. About that, I think the easiest way to implement it would simply be to store Over here, we would need to set I believe this would have the correct behavior, which is dependencies in the inner effect should not also be dependencies of the outer effect. |
Implement control flow constructs (
if/else
andfor
) intemplate!
macro.The text was updated successfully, but these errors were encountered: