Added implicit conversion for fx obs filter
methods
This commit is contained in:
parent
a905c5efaf
commit
80b32b063e
@ -1,21 +1,42 @@
|
||||
package nova.monadic_sfx.util
|
||||
package nova.monadic_sfx.implicits
|
||||
|
||||
import scalafx.beans.property.ObjectProperty
|
||||
import scalafx.beans.property.ReadOnlyObjectProperty
|
||||
import scalafx.beans.value.ObservableValue
|
||||
|
||||
object Misc {
|
||||
/**
|
||||
* experimental implicits to be incorporated better later
|
||||
*/
|
||||
trait MySfxObservableImplicits {
|
||||
import nova.monadic_sfx.implicits.ExtraObservableImplicits._
|
||||
implicit def myRichObservable[A, C](
|
||||
observable: ObservableValue[A, C]
|
||||
): MyRichObservable[A, C] = new MyRichObservable(observable)
|
||||
}
|
||||
|
||||
implicit final class MyRichObservable[A, C](val self: ObservableValue[A, C])
|
||||
object ExtraObservableImplicits {
|
||||
|
||||
final class MyRichObservable[A, C](val self: ObservableValue[A, C])
|
||||
extends AnyVal {
|
||||
def filter(f: A => Boolean): ReadOnlyObjectProperty[A] =
|
||||
Method.filter(self)(f)
|
||||
def filterNull: ReadOnlyObjectProperty[A] = Method.filterNull(self)
|
||||
Methods.filter(self)(f)
|
||||
|
||||
/**
|
||||
* Simply creates a new observable that mirrors the source observable but
|
||||
* doesn't emit null values. JavaFX likes to work with null values in scene
|
||||
* nodes/properties (shrugs) and observables by default emit null values
|
||||
* that can cause crashes if you forget to null check. ScalaFX does not
|
||||
* offer any *fixes* for this.
|
||||
*/
|
||||
def filterNull: ReadOnlyObjectProperty[A] = Methods.filterNull(self)
|
||||
}
|
||||
|
||||
}
|
||||
object Method {
|
||||
object Types {
|
||||
type Observable[A] = ObservableValue[A, _]
|
||||
}
|
||||
object Methods {
|
||||
import Types._
|
||||
|
||||
def filter[B](
|
||||
a: Observable[B]
|
||||
@ -38,7 +59,8 @@ object Method {
|
||||
* Simply creates a new observable that mirrors the source observable but
|
||||
* doesn't emit null values. JavaFX likes to work with null values in scene
|
||||
* nodes/properties (shrugs) and observables by default emit null values
|
||||
* that can cause crashes. ScalaFX does not offer any *fixes* for this
|
||||
* that can cause crashes if you forget to null check. ScalaFX does not
|
||||
* offer any *fixes* for this.
|
||||
*
|
||||
* @param a
|
||||
* @return
|
@ -7,7 +7,7 @@ import monix.reactive.Observable
|
||||
import monix.reactive.OverflowStrategy
|
||||
import scalafx.scene.control._
|
||||
|
||||
package object implicits {
|
||||
package object implicits extends MySfxObservableImplicits {
|
||||
|
||||
implicit class MyButtonExt(val button: Button) extends AnyVal {
|
||||
def observableAction(): Observable[ActionEvent] = {
|
||||
|
Loading…
Reference in New Issue
Block a user