Replies: 6 comments
-
We could take some inspiration from this: |
Beta Was this translation helpful? Give feedback.
-
Sorry I misunderstood what you meant you meant by child querying earlier. We can keep this as is for discussion. |
Beta Was this translation helpful? Give feedback.
-
Ok :) |
Beta Was this translation helpful? Give feedback.
-
Hey, @Boscop, now that minimal futures support exists, lets explore this idea more. So is what you are proposing effectively like: let future_callback = FutureCallback::new(scope, |this: &mut Self, _click_event: ClickEvent| {
this.has_been_clicked = true;
});
html!{
<button onclick=future_callback >{"Button"}</button>
} Add various macro sugar to enable just putting the Internally, it might be possible to have a future (EDIT: are futures even needed to represent this?), which when it gets an event, takes its given callback and the event and sends them both to the component loop via a scope, which then acquires a mutable reference to the component state, and calls the closure with the state and event/message, mutating the component without ever touching the message passing system/ I don't know how event generation might be represented as futures, how this system could coincide with existing Callback infrastructure, and how this would be used within Components. I'm not so sure about this being easily achievable, or practical in light of what existing design decisions have been made, but is this approximately what you are wanting? |
Beta Was this translation helpful? Give feedback.
-
To follow up on this, I think sticking functions to update state inside pub struct State {
counter: usize
// ...
}
pub struct Effect(Rc<Fn(&mut State) -> ShouldRender>);
fn effect<F>(f:F) -> Effect where F: Fn(&mut State) -> ShouldRender {...}
//...
fn update(&mut self, msg: Effect) -> ShouldRender {
(msg.0)(self)
}
fn view(&self) -> Html<State> {
html!{
<button onclick=|_| effect(|state| state.counter += 1) ></button>
}
} I'm going to try this out in the Yewtil crate, and see if it is possible. |
Beta Was this translation helpful? Give feedback.
-
@hgzimmerman Sorry for the late response. This is kinda related to the async inline ajax calls by the fact that both are enabled by monads in PureScript's Halogen framework, thus both things are similarly concise. |
Beta Was this translation helpful? Give feedback.
-
Are there any plans to allow inline async ajax calls and child querying, without going through another
update
call?Similar as PureScript/Halogen allows.
Beta Was this translation helpful? Give feedback.
All reactions