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

StrictSignal.map returns Signal instead of StrictSignal #134

Closed
ivan-klass opened this issue Nov 29, 2024 · 4 comments
Closed

StrictSignal.map returns Signal instead of StrictSignal #134

ivan-klass opened this issue Nov 29, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@ivan-klass
Copy link

val myVar = Var(42)


def myFunc(ss: StrictSignal[Int]) = ???

myFunc(myVar.signal) // ok
myFunc(myVar.signal.map(_ * 2)) // compile error

@raquo raquo added the enhancement New feature or request label Nov 29, 2024
@raquo
Copy link
Owner

raquo commented Nov 30, 2024

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 mapSome to work similarly, but that's a lot bigger task, as I need to figure out a new abstraction to implement that without massive repetition.

So I was planning to do that in 18.0, but if my schedule allows, I could add just the strict map to 17.2, and the rest later.

This was previously mentioned in #119 but I guess it's good to have a separate issue now that zoomLazy itself is done.

@ivan-klass
Copy link
Author

@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
)

@raquo
Copy link
Owner

raquo commented Nov 30, 2024 via email

@raquo
Copy link
Owner

raquo commented Dec 14, 2024

Implemented in 17.2.0 as mapLazy. Can't really change map return type of an open trait without a major release.

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.

@raquo raquo closed this as completed Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants