-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
StrictSignal.map returns Signal instead of StrictSignal #134
Comments
Yes, we'll have that eventually. We already have the mechanism to implement this, main issue is that I want to make other map-like operators like So I was planning to do that in 18.0, but if my schedule allows, I could add just the strict This was previously mentioned in #119 but I guess it's good to have a separate issue now that zoomLazy itself is done. |
@raquo thank you. I've end up with the following work-around. Not sure it's fully safe but it works. type Cleanup = Modifier[Base]
extension [A](ss: StrictSignal[A])
def strictMapped[B](f: A => B): (StrictSignal[B], Cleanup) =
val mVar = Var(f(ss.now()))
val owner = new ManualOwner
ss.map(f).addObserver(mVar.writer)(using owner)
(mVar.signal, onUnmountCallback(_ => owner.killSubscriptions())) used like def myFunc(ss: StrictSignal[Int]): HtmlElement = ???
val myVar = Var(42)
val (strictMappedSignal, cleanUp) = myVar.signal.strictMapped(_ * 2)
div(
myFunc(strictMappedSignal),
cleanUp
)
|
If you want a workaround for now, just make your extension method
instantiate and return a LazyStrictSignal. See how Var.zoomLazy method does
it.
…On Sat, Nov 30, 2024, 7:37 AM Ivan Klass ***@***.***> wrote:
@raquo <https://github.com/raquo> thank you. I've end up with the
following work-around. Not sure it's fully safe but it works.
type Cleanup = Modifier[Base]extension [A](ss: StrictSignal[A])
def strictMapped[B](f: A => B): (StrictSignal[B], Cleanup) =
val mVar = Var(f(ss.now()))
val owner = new ManualOwner
ss.map(f).addObserver(mVar.writer)(using owner)
(mVar.signal, onUnmountCallback(_ => owner.killSubscriptions()))
used like
def myFunc(ss: StrictSignal[Int]): HtmlElement = ???
val myVar = Var(42)val (strictMappedSignal, cleanUp) = myVar.signal.strictMapped(_ * 2)
div(
myFunc(strictMappedSignal),
cleanUp
)
—
Reply to this email directly, view it on GitHub
<#134 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAECBME34DR3ZVOPVFHRSHL2DHLUPAVCNFSM6AAAAABSXICYR2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMBZGAYTAOBRGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Implemented in 17.2.0 as A future major version will expand this to more operators, but I can't really create an issue for that yet because I'm not yet sure how it should look technically. I plan to look into that in the coming months. |
The text was updated successfully, but these errors were encountered: