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

reactify.standard.StandardReactions.scala Maven / Gradle / Ivy

The newest version!
package reactify.standard

import reactify.reaction.{Reaction, Reactions}

class StandardReactions[T] extends Reactions[T] {
  var list = List.empty[Reaction[T]]

  def apply(): List[Reaction[T]] = list

  def +=(reaction: Reaction[T]): Reaction[T] = synchronized {
    list = (list ::: List(reaction)).sorted.distinct
    reaction
  }

  def -=(reaction: Reaction[T]): Boolean = synchronized {
    val previous = list
    list = list.filterNot(_ eq reaction)
    previous != list
  }

  def clear(): Unit = synchronized {
    list = Nil
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy