Replies: 2 comments
-
|
Yes, there is a builtin called Tip: Your version will leak memory, because the subscription is never cleaned up. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
There already exists a solution for this: https://aylur.github.io/gnim/jsx#createcomputed As a side note: I like how many people have trouble understanding Monads, but people keep reinventing them accidentally. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
Perhaps you might have encountered this issue before: you need to listen to two or more different accessors (a.k.a. bindings, signals, ...) to change a single value. Example: I want to create a label showing the volume in percentage, or "Muted" if the sound is muted, so I need to know the current volume and the current mute status of my default speaker, and my label has to update when one of them changes. You might go with something like this:
But this is bad: it will only update the label as the volume changes. As you toggle the
mute, it will not trigger changing the label because it is wrapped in thatvolume.as()(listening to volume changes).Since I couldn't find anything documented about this behavior and how to circumnavigate it, I decided to write a function called
sequence, inspired by the Haskell function of the same name since this wholeAccessorthing reminds me of a monad (not sure if intentional):What it does is it takes an object of multiple accessors, and turns it into an accessor of an object. You can call it like so to fix the above issue with our
label:Please let me know if there's any built-in way to resolve this issue that I am not aware about :)
Beta Was this translation helpful? Give feedback.
All reactions