!LtIECwsjkkjinzHTTB:matrix.org

Support/Help

943 Members
6 Servers

Load older messages


SenderMessageTime
24 Jan 2022
@_discord_278291088060710932:t2bot.iokrytain Wondering what the convention is for getting the click event on a child. I have this but not sure it is right
pub enum Msg {
    Click(MouseEvent),
}

#[derive(PartialEq, Properties)]
pub struct Props {
    pub active: bool,
    pub onclick: Callback<MouseEvent>,
}

pub struct CellComponent;

impl Component for CellComponent {
    type Message = Msg;
    type Properties = Props;

    fn create(ctx: &Context<Self>) -> Self {
        CellComponent
    }

    fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
        match msg {
            Msg::Click(m) => {
                ctx.props().onclick.emit(m);
                false
            }
        }
    }

    fn view(&self, ctx: &Context<Self>) -> Html {

        let onclick = ctx.link().callback(Msg::Click);
        html! {
            <td
                {onclick}
            >
            </td>
        }
    }
}
20:35:23
@_discord_278291088060710932:t2bot.iokrytain I looked in the docs for an hour or so and couldn't find any examples 20:36:06
25 Jan 2022
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 i dont see anything wrong with what you wrote
you have a callback to send a message back to your component that then cascaded the event up

I just think in this specific case you can optimize and directly call the prop in the callback, change your line from
let onclick = ctx.link().callback(Msg::Click);

to just
let onclick = ctx.props().onclick;
07:11:36
@_discord_304071534803419138:t2bot.ioenricozb joined the room.08:17:59
@_discord_304071534803419138:t2bot.ioenricozb Hi guys, are there any examples (open source code is fine) of Suspense that fetches data? The official suspense example uses a future that returns nothing (sleep). I'm curious how people have used Suspense for handling data fetches, and using that data when rendering the component. While this might be an obvious extension of the example, I'm not that proficient in rust, so I'm having a hard time routing the data from the future back to the component in a way that will satisfy the borrow checker. Thank you all in advance. 08:18:00
@_discord_434457625996820480:t2bot.ioBrickchef joined the room.10:48:16
@_discord_434457625996820480:t2bot.ioBrickchef Hey, does yew include anything for websockets? I found a websocket service in the docs for an older version but it looks like it has been removed. What would be the way to go to use websockets with yew? 10:48:17
@ctron:dentrassi.dectron joined the room.11:25:23
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 well that async function that sleeps would just need to do feching and tahts it 11:28:38
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 use reqwasm, reqwest or just plain old web_sys fetch 11:29:06
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 as to the problems youre having, i think you just are afraid of cloning 11:29:41
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 in frontned there is a lot of cloning and its something you need to get used to 11:29:56
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 yew itself does not, i think reqwasm already has some support 11:30:20
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 but you can also just do it with plain old web_sys 11:30:31
@_discord_434457625996820480:t2bot.ioBrickchef Yes, looks like reqwasm supports Websockets. However, I don't really understand how I would integrate the websocket stuff in a yew application.
Would it make sense to use an agent for the websocket stuff?
11:37:55
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 honestly no 11:46:50
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 well but im biased 11:46:58
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 i dont see why use agent anywhere 😄 11:47:07
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 rust+wasm and js both have good enough async loop 11:47:38
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 together with yew without agents 11:47:47
@_discord_434457625996820480:t2bot.ioBrickchef I was just looking foa a way to consume the websocket and translate it's messages to Messages on which my Components can react.
Maybe I am missing something in the Docs or the examples but I don't know how I would do something like this.
12:01:04
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 you should be able to do everything using callbacks 12:01:34
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 https://yew.rs/docs/concepts/components/callbacks 12:01:57
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 of if you are wondering how to read the received messeges 12:02:22
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 then deserialize your received data (lets say JSON) using serde 12:02:46
@_discord_434457625996820480:t2bot.ioBrickchef I know how to handle messages of a websocket but I don't understand how I can get yew to trigger a callback when a message comes in. 12:05:47
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 drop a code snippet i might be able to help you then 12:06:13
@_discord_141600911725166593:t2bot.ioBrunkel#2646 If you use a callback the component gets rendered right? 12:13:17
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 not really 12:14:09
@_discord_134721610165780481:t2bot.ioVoidpumpkin#8396 your callback would need to change state to cause a rerender 12:14:29

There are no newer messages yet.


Back to Room ListRoom Version: 6