Misc code beautification
This commit is contained in:
parent
488fc08cd6
commit
d882c1a784
@ -1,6 +1,5 @@
|
||||
package org.gerweck.scalafx.akka
|
||||
|
||||
import scala.collection.mutable
|
||||
import scala.concurrent._
|
||||
|
||||
import akka.Done
|
||||
|
@ -15,8 +15,6 @@ import scalafx.application.Platform.runLater
|
||||
import scalafx.beans.Observable
|
||||
import scalafx.beans.property._
|
||||
|
||||
import org.log4s._
|
||||
|
||||
import org.gerweck.scalafx.util.FutureObservable
|
||||
|
||||
trait AkkaFXCollections extends Any {
|
||||
@ -28,7 +26,6 @@ object AkkaFXCollections {
|
||||
(buffer: Observable with Growable[A] with Clearable,
|
||||
clearFirst: Boolean,
|
||||
groupingSize: Int = 50, groupingTimeout: FiniteDuration = 100.milliseconds)
|
||||
(implicit ec: ExecutionContext)
|
||||
: Sink[A, Future[Done]] = {
|
||||
sealed trait PopulateAction
|
||||
case class InsertRows(data: Seq[A]) extends PopulateAction
|
||||
|
@ -1,10 +1,5 @@
|
||||
package org.gerweck.scalafx.util
|
||||
|
||||
import language.existentials
|
||||
|
||||
import scalaz._
|
||||
import Scalaz._
|
||||
|
||||
import shapeless._
|
||||
import shapeless.ops.hlist._
|
||||
import shapeless.ops.function._
|
||||
@ -19,18 +14,20 @@ import scalafx.beans.value.ObservableValue
|
||||
class ObservableTupler
|
||||
[HLObs <: HList, HLParams <: HList, TParams <: Product] private
|
||||
(hlist: HLObs)
|
||||
(implicit unwrapper: Mapper.Aux[ObservableUnwrapper.type, HLObs, HLParams],
|
||||
tupler: Tupler.Aux[HLParams, TParams],
|
||||
lister: ToList[HLObs, Observable[_]]) {
|
||||
(implicit
|
||||
unwrapper: Mapper.Aux[ObservableUnwrapper.type, HLObs, HLParams],
|
||||
tupler: Tupler.Aux[HLParams, TParams],
|
||||
lister: ToList[HLObs, Observable[_]]) {
|
||||
|
||||
def |@|[O, P, Appended <: HList, Unwrapped <: HList, Tupled <: Product, ApList]
|
||||
def |@|[O, P, Appended <: HList, Unwrap <: HList, Tupled <: Product, ApList]
|
||||
(f: ObservableValue[O, P])
|
||||
(implicit prepend: Prepend.Aux[HLObs, ObservableValue[O, P]::HNil, Appended],
|
||||
uw: Mapper.Aux[ObservableUnwrapper.type, Appended, Unwrapped],
|
||||
tplr: Tupler.Aux[Unwrapped, Tupled],
|
||||
lst: ToList[Appended, Observable[_]]): ObservableTupler[Appended, Unwrapped, Tupled] = {
|
||||
(implicit
|
||||
prepend: Prepend.Aux[HLObs, ObservableValue[O, P]::HNil, Appended],
|
||||
uw: Mapper.Aux[ObservableUnwrapper.type, Appended, Unwrap],
|
||||
tplr: Tupler.Aux[Unwrap, Tupled],
|
||||
lst: ToList[Appended, Observable[_]]): ObservableTupler[Appended, Unwrap, Tupled] = {
|
||||
val newHL: Appended = hlist :+ f
|
||||
new ObservableTupler[Appended, Unwrapped, Tupled](newHL)
|
||||
new ObservableTupler[Appended, Unwrap, Tupled](newHL)
|
||||
}
|
||||
|
||||
def hlisted: ObservableValue[HLParams, HLParams] = {
|
||||
@ -64,7 +61,10 @@ class ObservableTupler
|
||||
prop
|
||||
}
|
||||
|
||||
def apply[Func, Result](f: Func)(implicit ffp: FnFromProduct.Aux[HLParams => Result, Func], ftp: FnToProduct.Aux[Func, HLParams => Result]): ObservableValue[Result, Result] = {
|
||||
def apply[Func, Result]
|
||||
(f: Func)
|
||||
(implicit ftp: FnToProduct.Aux[Func, HLParams => Result])
|
||||
: ObservableValue[Result, Result] = {
|
||||
hlisted map ftp(f)
|
||||
}
|
||||
}
|
||||
|
@ -172,29 +172,24 @@ final class RichTuple[A <: Product](val self: A) extends AnyVal {
|
||||
* Shapeless's `tuple` package, but it can't infer the exact output type,
|
||||
* which is far less useful.
|
||||
*/
|
||||
def observe
|
||||
[L <: HList, Unwrapped <: HList, Tupled <: Product]
|
||||
(implicit tohl: Generic.Aux[A, L],
|
||||
lister: ToTraversable.Aux[L, List, Observable[_]],
|
||||
uw: Mapper.Aux[ObservableUnwrapper.type, L, Unwrapped],
|
||||
tplr: Tupler.Aux[Unwrapped, Tupled]): ObservableValue[Tupled, Tupled] = {
|
||||
def observe[L <: HList, Unwrap <: HList, Tupled <: Product]
|
||||
(implicit tohl: Generic.Aux[A, L],
|
||||
lister: ToTraversable.Aux[L, List, Observable[_]],
|
||||
uw: Mapper.Aux[ObservableUnwrapper.type, L, Unwrap],
|
||||
tplr: Tupler.Aux[Unwrap, Tupled]): ObservableValue[Tupled, Tupled] = {
|
||||
val asHList: L = tohl.to(self)
|
||||
def calculate(): Tupled = uw(asHList).tupled
|
||||
|
||||
val original = calculate()
|
||||
val prop = ObjectProperty[Tupled](original)
|
||||
|
||||
for {
|
||||
component <- asHList.to[List]
|
||||
} {
|
||||
for (component <- asHList.to[List]) {
|
||||
component onChange {
|
||||
prop.value = calculate()
|
||||
}
|
||||
}
|
||||
prop
|
||||
}
|
||||
|
||||
// def omap[B]
|
||||
}
|
||||
|
||||
final class RichObservable[A, C](val self: ObservableValue[A, C]) extends AnyVal {
|
||||
@ -247,9 +242,9 @@ final class ObservableOfMapLike[A, B, C](val self: ObservableValue[C, C])(implic
|
||||
}
|
||||
|
||||
final class RichProperty[A, B](val inner: Property[A, B]) extends AnyVal {
|
||||
def biMap[B <: AnyRef](push: A => B, pull: B => A): ObjectProperty[B] = {
|
||||
def biMap[A1 <: AnyRef](push: A => A1, pull: A1 => A): ObjectProperty[A1] = {
|
||||
val original = push(inner.value)
|
||||
val op = ObjectProperty[B](original)
|
||||
val op = ObjectProperty[A1](original)
|
||||
inner onChange {
|
||||
val oldVal = op.value
|
||||
val newVal = push(inner.value)
|
||||
|
@ -1,7 +1,5 @@
|
||||
package org.gerweck.scalafx.util
|
||||
|
||||
import language.implicitConversions
|
||||
|
||||
import scala.compat.java8.FunctionConverters._
|
||||
|
||||
import java.util.function.{ Predicate => JPredicate }
|
||||
|
@ -1,18 +1,12 @@
|
||||
package org.gerweck.scalafx
|
||||
|
||||
import language.implicitConversions
|
||||
import language.existentials
|
||||
|
||||
import scalafx.Includes._
|
||||
import scalafx.beans.property._
|
||||
import scalafx.beans.value._
|
||||
import scalafx.event.subscriptions.Subscription
|
||||
import scalafx.scene.Node
|
||||
import scalafx.scene.control._
|
||||
import scalafx.scene.input._
|
||||
import scalafx.scene.layout.GridPane
|
||||
import scalafx.scene.text.Text
|
||||
import scalafx.util.StringConverter
|
||||
|
||||
import scalaz._
|
||||
|
||||
@ -25,8 +19,8 @@ package object util extends ObservableImplicits with LowPriorityImplicits {
|
||||
type SimpleProperty[A] = Property[A, _]
|
||||
|
||||
object TextDisplay {
|
||||
def apply(text: ObservableValue[String,String]) = {
|
||||
val t = new scalafx.scene.text.Text
|
||||
def apply(text: ObservableValue[String,String]): Text = {
|
||||
val t = new Text
|
||||
t.text <== text
|
||||
t
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user