Skip to content
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

Add a way to clear the value of an action #2364

Open
ChocolateLoverRaj opened this issue Feb 24, 2024 · 5 comments
Open

Add a way to clear the value of an action #2364

ChocolateLoverRaj opened this issue Feb 24, 2024 · 5 comments
Labels

Comments

@ChocolateLoverRaj
Copy link

Is your feature request related to a problem? Please describe.
I have a web page which connects to a USB or BLE device using an action:

let connect = create_action(|connection_type: &ConnectionType| {
        let connection_type = connection_type.to_owned();
        async move {
            let result = match connection_type {
                ConnectionType::Usb => UsbConnectionBuilder::connect().await,
                ConnectionType::Ble => BleConnectionBuilder::connect().await,
            }
            .map(|b| Rc::new(b));
            if let Err(e) = result.as_ref() {
                console_log!("Error connecting with {:#?}: {:#?}", connection_type, e);
            }
            result
        }
    });

    let connection = connect.value();

I want a way of clearing the value of an action when a "Disconnect" button is clicked.

Describe the solution you'd like
A Action::clear_value function or something similar

Describe alternatives you've considered
Create a signal that is a number. If the number is greater than the action version, it means that the action's result should be ignored. When the "Disconnect" button is pressed, increase the number.

Additional context
My project that uses Leptos: https://github.com/ChocolateLoverRaj/rust-esp32c3-examples/tree/sensor-connect-web/sensor-connect

@gbj
Copy link
Collaborator

gbj commented Feb 28, 2024

PR welcome to add it. Another possibility is to use a resource, which does allow mutation.

@ChocolateLoverRaj
Copy link
Author

In my case I can't use a resource because resources will execute the async function right away, but I want it to execute when a button is clicked.

@caioluis
Copy link

@leorsousa05 and I will have a look at it in pair programming. Let us know if there was any progress since your last comment, @ChocolateLoverRaj.

@ChocolateLoverRaj
Copy link
Author

I didn't start making a PR at all. I'm working on other programming projects rn. You don't need to wait for me.

@leorsousa05
Copy link

I didn't start making a PR at all. I'm working on other programming projects rn. You don't need to wait for me.

We will probably start on monday. Good projects by the way!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants