|
|
@ -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) |
|
|
|
} |
|
|
|
|
|
|
|
object ExtraObservableImplicits { |
|
|
|
|
|
|
|
implicit final class MyRichObservable[A, C](val self: ObservableValue[A, C]) |
|
|
|
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 |