sycamore-rs / sycamore

A library for creating reactive web apps in Rust and WebAssembly
https://sycamore-rs.netlify.app
MIT License
2.79k stars 148 forks source link

If a signal is not used in create_effect but a closure, it seems that it's not listened. #525

Closed piaoger closed 1 year ago

piaoger commented 1 year ago

Describe the bug I am not sure if it's really a defect :)

Sync to master branch and below code does not work as before if not adding below line. I wonder if there are any design change. It seems that code inside the closure is not tracked.

  let a = run; // must be added

My code:

let exec = move |event: Event| {
    run.set(true);
};

create_effect(cx, {

    let a = run; // must be added

    move || {

        // will not called if not above line
        // Actions

        run.set(false);
    }
});

view! {cx,

    //  RUN
    div (class="flex flex-row-reverse p-1 w-4/5") {
            div (class="flex-initial pl-3") {
            button (
                type="button",
                on:click=exec
            )
        }
    }
}

Environment

piaoger commented 1 year ago

close it for I still now sure what happened..