fixed `IntoClass` from not disconnecting from overwritten `Scope`

This commit is contained in:
Jose Quesada 2022-12-06 07:21:14 -06:00
parent 98414ac192
commit d6ef65daf6
2 changed files with 5 additions and 5 deletions

View File

@ -299,7 +299,7 @@ impl<El: IntoElement> HtmlElement<El> {
let class_list = el.class_list();
let value = class.into_class(cx);
match value {
Class::Fn(f) => {
Class::Fn(cx, f) => {
create_render_effect(cx, move |old| {
let new = f();
if old.as_ref() != Some(&new) && (old.is_some() || new) {

View File

@ -11,7 +11,7 @@ pub enum Class {
/// Whether the class is present.
Value(bool),
/// A (presumably reactive) function, which will be run inside an effect to toggle the class.
Fn(Box<dyn Fn() -> bool>),
Fn(Scope, Box<dyn Fn() -> bool>),
}
/// Converts some type into a [Class].
@ -30,9 +30,9 @@ impl<T> IntoClass for T
where
T: Fn() -> bool + 'static,
{
fn into_class(self, _cx: Scope) -> Class {
fn into_class(self, cx: Scope) -> Class {
let modified_fn = Box::new(self);
Class::Fn(modified_fn)
Class::Fn(cx, modified_fn)
}
}
@ -47,7 +47,7 @@ impl Class {
""
}
}
Class::Fn(f) => {
Class::Fn(_, f) => {
let value = f();
if value {
class_name