Converted implicit classes to implicit methods
This commit is contained in:
parent
80b32b063e
commit
7aa80f54f7
@ -12,7 +12,7 @@ import monix.eval.Coeval
|
|||||||
import monix.{eval => me}
|
import monix.{eval => me}
|
||||||
import nova.monadic_sfx.executors.Schedulers
|
import nova.monadic_sfx.executors.Schedulers
|
||||||
import nova.monadic_sfx.implicits.JFXButton
|
import nova.monadic_sfx.implicits.JFXButton
|
||||||
import nova.monadic_sfx.implicits.JavaFXMonixObservables._
|
import nova.monadic_sfx.implicits._
|
||||||
import nova.monadic_sfx.ui.MyFxApp
|
import nova.monadic_sfx.ui.MyFxApp
|
||||||
import nova.monadic_sfx.ui.components.router.FXRouter
|
import nova.monadic_sfx.ui.components.router.FXRouter
|
||||||
import nova.monadic_sfx.ui.components.router.Page
|
import nova.monadic_sfx.ui.components.router.Page
|
||||||
|
@ -37,6 +37,6 @@ class JFXButton(
|
|||||||
}
|
}
|
||||||
|
|
||||||
def obsAction =
|
def obsAction =
|
||||||
new ActionObservableBuilder(this.observableAction())
|
new ActionObservableBuilder(this.observableAction)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,10 +27,32 @@ import scalafx.scene.Scene
|
|||||||
import scalafx.scene.control.ButtonBase
|
import scalafx.scene.control.ButtonBase
|
||||||
import scalafx.scene.control.MenuItem
|
import scalafx.scene.control.MenuItem
|
||||||
|
|
||||||
|
trait JavaFXMonixObservables {
|
||||||
|
import JavaFXMonixObservables._
|
||||||
|
implicit def extendedScene(scene: Scene) = new SceneExt(scene)
|
||||||
|
implicit def extendedProperty[T, J](
|
||||||
|
propery: Property[T, J]
|
||||||
|
): PropertyExt[T, J] =
|
||||||
|
new PropertyExt(propery)
|
||||||
|
implicit def extendedObjectPropety[A](prop: ObjectProperty[A]) =
|
||||||
|
new ObjectPropertyExt[A](prop)
|
||||||
|
implicit def extendedReadOnlyObjectPropety[T, J](
|
||||||
|
prop: ReadOnlyProperty[T, J]
|
||||||
|
) =
|
||||||
|
new ReadOnlyPropertyExt[T, J](prop)
|
||||||
|
implicit def extendedObservableList[A](
|
||||||
|
list: ObservableList[A]
|
||||||
|
) = new ObservableListExt(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)
|
||||||
|
}
|
||||||
|
|
||||||
object JavaFXMonixObservables {
|
object JavaFXMonixObservables {
|
||||||
|
|
||||||
implicit final class SceneObservables(private val scene: Scene)
|
final class SceneExt(private val scene: Scene) extends AnyVal {
|
||||||
extends AnyVal {
|
|
||||||
|
|
||||||
def observableMousePressed(): Observable[jfxsi.MouseEvent] = {
|
def observableMousePressed(): Observable[jfxsi.MouseEvent] = {
|
||||||
import monix.execution.cancelables.SingleAssignCancelable
|
import monix.execution.cancelables.SingleAssignCancelable
|
||||||
@ -75,7 +97,7 @@ object JavaFXMonixObservables {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
implicit final class BindObs[T, J](private val prop: Property[T, J])
|
final class PropertyExt[T, J](private val prop: Property[T, J])
|
||||||
extends AnyVal {
|
extends AnyVal {
|
||||||
def -->(op: Observer[T]) = {
|
def -->(op: Observer[T]) = {
|
||||||
op.onNext(prop.value)
|
op.onNext(prop.value)
|
||||||
@ -107,7 +129,7 @@ object JavaFXMonixObservables {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
implicit final class BindObs2[A](private val prop: ObjectProperty[A])
|
final class ObjectPropertyExt[A](private val prop: ObjectProperty[A])
|
||||||
extends AnyVal {
|
extends AnyVal {
|
||||||
|
|
||||||
def -->(sub: Observer[A]) =
|
def -->(sub: Observer[A]) =
|
||||||
@ -136,7 +158,7 @@ object JavaFXMonixObservables {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
implicit final class ObservableListExt[A](
|
final class ObservableListExt[A](
|
||||||
private val buffer: ObservableList[A]
|
private val buffer: ObservableList[A]
|
||||||
) extends AnyVal {
|
) extends AnyVal {
|
||||||
|
|
||||||
@ -189,8 +211,9 @@ object JavaFXMonixObservables {
|
|||||||
} else Task.unit
|
} else Task.unit
|
||||||
}
|
}
|
||||||
|
|
||||||
implicit final class BindObs3[T, J](private val prop: ReadOnlyProperty[T, J])
|
final class ReadOnlyPropertyExt[T, J](
|
||||||
extends AnyVal {
|
private val prop: ReadOnlyProperty[T, J]
|
||||||
|
) extends AnyVal {
|
||||||
def -->(op: Observer[T]) = {
|
def -->(op: Observer[T]) = {
|
||||||
op.onNext(prop.value)
|
op.onNext(prop.value)
|
||||||
}
|
}
|
||||||
@ -214,7 +237,7 @@ object JavaFXMonixObservables {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
implicit final class ObjectPropertyObservableListExt[A](
|
final class ObjectPropertyObservableListExt[A](
|
||||||
private val prop: ObjectProperty[ObservableList[A]]
|
private val prop: ObjectProperty[ObservableList[A]]
|
||||||
) extends AnyVal {
|
) extends AnyVal {
|
||||||
def <--(obs: Observable[Seq[A]])(implicit s: Scheduler) = {
|
def <--(obs: Observable[Seq[A]])(implicit s: Scheduler) = {
|
||||||
@ -259,7 +282,7 @@ object JavaFXMonixObservables {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
implicit final class ObjectPropertyActionEvent(
|
final class ObjectPropertyActionEvent(
|
||||||
private val prop: ObjectProperty[EventHandler[ActionEvent]]
|
private val prop: ObjectProperty[EventHandler[ActionEvent]]
|
||||||
) extends AnyVal {
|
) extends AnyVal {
|
||||||
// def <--(obs: Observable[ActionEvent])(implicit s: Scheduler) = {
|
// def <--(obs: Observable[ActionEvent])(implicit s: Scheduler) = {
|
||||||
@ -273,7 +296,7 @@ object JavaFXMonixObservables {
|
|||||||
|
|
||||||
// def emit(prop: ObjectProperty[EventHandler[ActionEvent]]) =
|
// def emit(prop: ObjectProperty[EventHandler[ActionEvent]]) =
|
||||||
|
|
||||||
implicit final class OnActionObservable(
|
final class ButtonBaseExt(
|
||||||
private val button: ButtonBase
|
private val button: ButtonBase
|
||||||
) extends AnyVal {
|
) extends AnyVal {
|
||||||
|
|
||||||
@ -299,7 +322,7 @@ object JavaFXMonixObservables {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
implicit final class MenuItemActionObservable(
|
final class MenuItemExt(
|
||||||
private val item: MenuItem
|
private val item: MenuItem
|
||||||
) extends AnyVal {
|
) extends AnyVal {
|
||||||
|
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package nova.monadic_sfx.implicits
|
package nova.monadic_sfx.implicits
|
||||||
|
|
||||||
|
import nova.monadic_sfx.implicits._
|
||||||
import scalafx.scene.{control => sfxc}
|
import scalafx.scene.{control => sfxc}
|
||||||
|
|
||||||
import JavaFXMonixObservables._
|
|
||||||
|
|
||||||
class MenuItem extends sfxc.MenuItem {
|
class MenuItem extends sfxc.MenuItem {
|
||||||
def obsAction = new ActionObservableBuilder(this.observableAction)
|
def obsAction = new ActionObservableBuilder(this.observableAction)
|
||||||
}
|
}
|
||||||
|
@ -1,50 +1,20 @@
|
|||||||
package nova.monadic_sfx
|
package nova.monadic_sfx
|
||||||
|
|
||||||
import javafx.event.ActionEvent
|
package object implicits
|
||||||
import monix.execution.Ack
|
extends MySfxObservableImplicits
|
||||||
import monix.execution.Cancelable
|
with JavaFXMonixObservables
|
||||||
import monix.reactive.Observable
|
|
||||||
import monix.reactive.OverflowStrategy
|
|
||||||
import scalafx.scene.control._
|
|
||||||
|
|
||||||
package object implicits extends MySfxObservableImplicits {
|
// implicit class NodeExt(val node: Node) {
|
||||||
|
// def lookup2[T <: SFXDelegate[_]](
|
||||||
|
// selector: String
|
||||||
|
// )(implicit c: ClassTag[T]) = {
|
||||||
|
// val t = c.runtimeClass
|
||||||
|
// Option(node.delegate.lookup(selector)) match {
|
||||||
|
// case Some(value) =>
|
||||||
|
// if (value.getClass == t) Some(value) else None
|
||||||
|
// case None => None
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
implicit class MyButtonExt(val button: Button) extends AnyVal {
|
// val x = node.lookup2("")
|
||||||
def observableAction(): Observable[ActionEvent] = {
|
// }
|
||||||
import monix.execution.cancelables.SingleAssignCancelable
|
|
||||||
Observable.create(OverflowStrategy.Unbounded) { sub =>
|
|
||||||
val c = SingleAssignCancelable()
|
|
||||||
val l = new javafx.event.EventHandler[ActionEvent] {
|
|
||||||
override def handle(event: ActionEvent): Unit = {
|
|
||||||
if (sub.onNext(event) == Ack.Stop) c.cancel()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
button.onAction = l
|
|
||||||
c := Cancelable(() =>
|
|
||||||
button.removeEventHandler(
|
|
||||||
ActionEvent.ACTION,
|
|
||||||
l
|
|
||||||
)
|
|
||||||
)
|
|
||||||
c
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// implicit class NodeExt(val node: Node) {
|
|
||||||
// def lookup2[T <: SFXDelegate[_]](
|
|
||||||
// selector: String
|
|
||||||
// )(implicit c: ClassTag[T]) = {
|
|
||||||
// val t = c.runtimeClass
|
|
||||||
// Option(node.delegate.lookup(selector)) match {
|
|
||||||
// case Some(value) =>
|
|
||||||
// if (value.getClass == t) Some(value) else None
|
|
||||||
// case None => None
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// val x = node.lookup2("")
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -13,7 +13,7 @@ import monix.reactive.Observer
|
|||||||
import nova.monadic_sfx.implicits.FontIcon
|
import nova.monadic_sfx.implicits.FontIcon
|
||||||
import nova.monadic_sfx.implicits.IconLiteral
|
import nova.monadic_sfx.implicits.IconLiteral
|
||||||
import nova.monadic_sfx.implicits.JFXListView
|
import nova.monadic_sfx.implicits.JFXListView
|
||||||
import nova.monadic_sfx.implicits.JavaFXMonixObservables._
|
import nova.monadic_sfx.implicits._
|
||||||
import nova.monadic_sfx.util.reactive._
|
import nova.monadic_sfx.util.reactive._
|
||||||
import scalafx.Includes._
|
import scalafx.Includes._
|
||||||
import scalafx.beans.property.StringProperty
|
import scalafx.beans.property.StringProperty
|
||||||
|
@ -8,8 +8,8 @@ import nova.monadic_sfx.implicits.IconLiteral
|
|||||||
import nova.monadic_sfx.implicits.JFXButton
|
import nova.monadic_sfx.implicits.JFXButton
|
||||||
import nova.monadic_sfx.implicits.JFXListView
|
import nova.monadic_sfx.implicits.JFXListView
|
||||||
import nova.monadic_sfx.implicits.JFXTextField
|
import nova.monadic_sfx.implicits.JFXTextField
|
||||||
import nova.monadic_sfx.implicits.JavaFXMonixObservables._
|
|
||||||
import nova.monadic_sfx.implicits.MenuItem
|
import nova.monadic_sfx.implicits.MenuItem
|
||||||
|
import nova.monadic_sfx.implicits._
|
||||||
import nova.monadic_sfx.util.reactive._
|
import nova.monadic_sfx.util.reactive._
|
||||||
import org.gerweck.scalafx.util._
|
import org.gerweck.scalafx.util._
|
||||||
import scalafx.Includes._
|
import scalafx.Includes._
|
||||||
|
@ -19,7 +19,7 @@ class HomeScreen(
|
|||||||
// onAction = () => Action.asyncT(onLogout())
|
// onAction = () => Action.asyncT(onLogout())
|
||||||
}
|
}
|
||||||
|
|
||||||
val myObs = myButton.observableAction()
|
val myObs = myButton.observableAction
|
||||||
// myObs.foreachL(_ => ())
|
// myObs.foreachL(_ => ())
|
||||||
private lazy val root = Task.deferAction { implicit s =>
|
private lazy val root = Task.deferAction { implicit s =>
|
||||||
Task {
|
Task {
|
||||||
|
Loading…
Reference in New Issue
Block a user