Skip to content

Commit

Permalink
Make a Signal forget its internal memory when stopped.
Browse files Browse the repository at this point in the history
This branch changes Signal.onStop to make it forget its
internal memory when all observers have been removed. Causing it
to re-compute its "initialValue" again if the Signal is re-started.

This way, dependent signals (eg, MapSignal) can ask their parent
signal for the latest value upon restarting, and elements that read
these dependent signals can now observe the correct state when re-mounted.

Fixes raquo#43
  • Loading branch information
vic committed Jan 27, 2021
1 parent 084bfb1 commit 5c204a5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/scala/com/raquo/airstream/signal/Signal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ trait Signal[+A] extends Observable[A] {
super.onStart()
}

override protected[this] def onStop(): Unit = {
super.onStop()
maybeLastSeenCurrentValue = js.undefined
}

// @TODO[API] Use pattern match instead when isInstanceOf performance is fixed: https://github.com/scala-js/scala-js/issues/2066
override protected def onAddedExternalObserver(observer: Observer[A]): Unit = {
super.onAddedExternalObserver(observer)
Expand Down

0 comments on commit 5c204a5

Please sign in to comment.