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

Consider a more general key toggle method #90

Open
raquo opened this issue Mar 1, 2021 · 1 comment
Open

Consider a more general key toggle method #90

raquo opened this issue Mar 1, 2021 · 1 comment
Labels
design enhancement ergonomics need to find time https://falseknees.com/297.html needs design The solution is not clear, or I am not very happy with it

Comments

@raquo
Copy link
Owner

raquo commented Mar 1, 2021

In line with #89...

Currently we can toggle only composite attributes like cls:

cls.toggle("class1 class2")(myBoolean)
cls.toggle("class1 class2") := myBoolean
cls.toggle("class1", "class2") <-- myBooleanStream

Would be nice to be able to use similar pattern with other types of keys, but there's a challenge with styles – they use constants like display.none, the existing cls syntax doesn't have an equivalent in this case.

Maybe we should change it to be a postfix:

cls("class1 class2").when(myBoolean)
cls("class1 class2").when := myBoolean
cls("class1", "class2").when <-- myBooleanStream

colSpan(2).when(myBoolean)
colSpan(2).when <-- myBooleanStream

display.none.when(myBoolean)
display.none.when <-- myBooleanStream

Same question as in #89 regarding using default value vs prior value:

  • Should when(false) do nothing, or set an "empty" / "default" value?
  • What about if when <-- $bool emits false, what should happen then?
  • Seems like it's going to be either weird or not super consistent...
@raquo raquo added the need to find time https://falseknees.com/297.html label Jan 6, 2023
@Lasering
Copy link

I have this in my codebase:

val active: Signal[Boolean] = ...
aria.current <-- active.map(if _ then "page" else "")

Using when it would probably become:

aria.current("page").when <-- active

In this scenario I would expect that when active emits false the aria-current should be removed from the element. Setting an empty/default value would also be appropriate.

@raquo raquo added the needs design The solution is not clear, or I am not very happy with it label Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design enhancement ergonomics need to find time https://falseknees.com/297.html needs design The solution is not clear, or I am not very happy with it
Projects
None yet
Development

No branches or pull requests

2 participants