Skip to content

Best way to "wrap" a signal? #1684

Answered by gbj
sambonbonne asked this question in Q&A
Sep 9, 2023 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

Cool! This looks like a good practice to me. No, you don't need to implement any of the traits you don't need, and this should work out of the box.

However, the following logic is wrong:

    pub fn toggle(&self) {
        // this should be .set(!self.0())
        // more efficiently, self.o.update(|n| *n = !*n);
        self.0.set(self.0()); 
    }

    pub fn open(&self) {
        self.0.set(true);
    }

    pub fn close(&self) {
        // should be self.0.set(false);
        self.0.set(true);
    }

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@sambonbonne
Comment options

@gbj
Comment options

@sambonbonne
Comment options

Answer selected by sambonbonne
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants