Minor additions jfx monix implicits
Added implicit conversion from os.relpath to string for more convenient css path dsl Fixed some property sinks not using onchange previously Added one sample property source binding that uses an implicit composite cancelable
This commit is contained in:
parent
2f63119c6c
commit
b0b914424b
@ -11,6 +11,7 @@ import monix.eval.Coeval
|
||||
import monix.execution.Ack
|
||||
import monix.execution.Cancelable
|
||||
import monix.execution.Scheduler
|
||||
import monix.execution.cancelables.CompositeCancelable
|
||||
import monix.execution.cancelables.SingleAssignCancelable
|
||||
import monix.reactive.Observable
|
||||
import monix.reactive.Observer
|
||||
@ -43,11 +44,17 @@ trait JavaFXMonixObservables {
|
||||
implicit def extendedObservableList[A](
|
||||
list: ObservableList[A]
|
||||
) = new ObservableListExt(list)
|
||||
implicit def extendedStringObservableList(
|
||||
list: ObservableList[String]
|
||||
) = new StringObservableListExt(list)
|
||||
implicit def extendedObjectPropertyObservableList[A](
|
||||
prop: ObjectProperty[ObservableList[A]]
|
||||
) = new ObjectPropertyObservableListExt(prop)
|
||||
implicit def extendedButton(button: ButtonBase) = new ButtonBaseExt(button)
|
||||
implicit def extendedMenuItem(item: MenuItem) = new MenuItemExt(item)
|
||||
|
||||
// implicit val implShowForOsRelPath = Show.fromToString[os.Path]
|
||||
implicit def osRelPath2String(path: os.RelPath): String = path.toString()
|
||||
}
|
||||
|
||||
object JavaFXMonixObservables {
|
||||
@ -99,16 +106,18 @@ object JavaFXMonixObservables {
|
||||
|
||||
final class PropertyExt[T, J](private val prop: Property[T, J])
|
||||
extends AnyVal {
|
||||
def -->(op: Observer[T]) = {
|
||||
op.onNext(prop.value)
|
||||
def -->[J1 >: J](sub: Observer[J1]) = {
|
||||
prop.onChange((a, b, c) => if (c != null) sub.onNext(c))
|
||||
}
|
||||
|
||||
def ==>(op: Property[T, J]) = {
|
||||
op <== prop
|
||||
}
|
||||
|
||||
def <--(obs: Observable[T])(implicit s: Scheduler) = {
|
||||
obs.doOnNextF(v => Coeval(prop.value = v)).subscribe()
|
||||
def <--(
|
||||
obs: Observable[_ <: T]
|
||||
)(implicit s: Scheduler, c: CompositeCancelable): Unit = {
|
||||
c += obs.doOnNextF(v => Coeval(prop.value = v)).subscribe()
|
||||
}
|
||||
|
||||
def asOption = prop.map(Option(_))
|
||||
@ -211,11 +220,20 @@ object JavaFXMonixObservables {
|
||||
} else Task.unit
|
||||
}
|
||||
|
||||
final class StringObservableListExt(
|
||||
private val buffer: ObservableList[String]
|
||||
) extends AnyVal {
|
||||
// def ++=[T](that: Seq[T])(implicit S: Show[T]): Unit =
|
||||
// buffer ++= that.map(S.show)
|
||||
// def ++=[T](that: Seq[T])(implicit C: CssPath[T]): Unit =
|
||||
// buffer ++= that.map(C.path)
|
||||
}
|
||||
|
||||
final class ReadOnlyPropertyExt[T, J](
|
||||
private val prop: ReadOnlyProperty[T, J]
|
||||
) extends AnyVal {
|
||||
def -->(op: Observer[T]) = {
|
||||
op.onNext(prop.value)
|
||||
def -->[J1 >: J](sub: Observer[J1]) = {
|
||||
prop.onChange((a, b, c) => if (c != null) sub.onNext(c))
|
||||
}
|
||||
|
||||
def ==>(op: Property[T, J]) = {
|
||||
|
Loading…
Reference in New Issue
Block a user