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

Feat: dynamic_class_signal #44

Open
dakom opened this issue Nov 12, 2020 · 1 comment
Open

Feat: dynamic_class_signal #44

dakom opened this issue Nov 12, 2020 · 1 comment

Comments

@dakom
Copy link

dakom commented Nov 12, 2020

As discussed on Discord, sometimes it's needed to add/remove a class with a dynamic name

@Pauan suggested a fn dynamic_class_signal<S>(self, signal: S) -> Self where S: Signal<Item = Option<String>>

which makes something like this much more ergonomic:

.with_node!(element => {
    .future({
        let mut old = None;

        signal.for_each(move |value| {
            if let Some(old) = old.as_deref() {
                element.class_list().remove_1(old).unwrap();
            }

            let name = ...;
            element.class_list().add_1(name).unwrap();
            old = Some(name);
            ready(())
        })
    })
})
@dakom
Copy link
Author

dakom commented Nov 12, 2020

I've temporarily made a version of this available here

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

No branches or pull requests

1 participant