All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scala.reactive.ReactMutable.scala Maven / Gradle / Ivy

The newest version!
package scala.reactive



import collection._



/** Describes reactives that are either mutable, or contain and emit events that are themselves mutable.
 */
trait ReactMutable {

  /** Called internally - binds a subscription to this reactive mutable value.
   */
  def bindSubscription(s: Reactive.Subscription): Reactive.Subscription = s

  /** Called internally - when the mutable reactive or its internal value has been mutated.
   */
  def onMutated(): Unit = {}

}


/** Helper traits and implementations for reactive mutables.
 */
object ReactMutable {

  /** Used internally - holds a list of subscriptions bound to this reactive mutable.
   */
  trait Subscriptions extends ReactMutable {
    val subscriptions = mutable.Set[Reactive.Subscription]()

    def clearSubscriptions() {
      for (s <- subscriptions) s.unsubscribe()
      subscriptions.clear()
    }
    
    override def bindSubscription(s: Reactive.Subscription) = new Reactive.Subscription {
      subscriptions += this
      def unsubscribe() {
        s.unsubscribe()
        subscriptions -= this
      }
    }
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy