Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scalafmt-core to 3.8.6 #98

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Scala Steward: Reformat with scalafmt 3.8.6
e1612b6b1c8195337c486fa1094965fffe160e38
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.2.2"
version = "3.8.6"
runner.dialect = scala211
style = defaultWithAlign
assumeStandardLibraryStripMargin = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import org.scalajs.dom
import org.scalajs.dom.raw.MouseEvent

trait JSCallbacks extends Callbacks { self: JSRenderingContext β‡’
type Callback = js.Function
type Callback = js.Function
type ClickElement = dom.html.Element
type InputElement = dom.html.Input
type FormElement = dom.html.Form
type FormElement = dom.html.Form

object Callback extends CallbackFactory {
def onClick(f: ClickElement β‡’ Unit): js.Function = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.scalajs.dom.DOMList

trait JSImplicits {
implicit class DOMListIndexedSeq[T](dl: DOMList[T]) extends IndexedSeq[T] {
override def length: Int = dl.length
override def length: Int = dl.length
override def apply(idx: Int): T = dl.apply(idx)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ trait JSReactiveBinds extends ReactiveBinds {

protected type Event = dom.Event

implicit def rxEventListener[EL <: Element, EV <: Event]: ReactiveRead[EL, EventListener[EL, EV]] = new ReactiveRead[EL, EventListener[EL, EV]] {
def bindRead(element: EL, property: EventListener[EL, EV]): Unit = {
val function = js.ThisFunction.fromFunction2 { (el: EL, ev: EV) β‡’
property.callback(el, ev)
implicit def rxEventListener[EL <: Element, EV <: Event]: ReactiveRead[EL, EventListener[EL, EV]] =
new ReactiveRead[EL, EventListener[EL, EV]] {
def bindRead(element: EL, property: EventListener[EL, EV]): Unit = {
val function = js.ThisFunction.fromFunction2 { (el: EL, ev: EV) β‡’
property.callback(el, ev)
}
element.asInstanceOf[js.Dynamic].addEventListener(property.`type`, function)
}
element.asInstanceOf[js.Dynamic].addEventListener(property.`type`, function)
}
}

implicit def rxModify[E <: Element, T]: ReactiveWrite[E, Modify[E, T]] = new ReactiveWrite[E, Modify[E, T]] {
def bindWrite(element: E, property: Modify[E, T]): Unit = {
Expand All @@ -37,32 +38,39 @@ trait JSReactiveBinds extends ReactiveBinds {
}
}

implicit def rxBindNode[E <: Element, N: Renderable]: ReactiveWrite[E, BindNode[N]] = new ReactiveWrite[E, BindNode[N]] {
def bindWrite(parent: E, property: BindNode[N]): Unit = {
val elRx = property.value.map(identity)
var oldElement = property.value.now.render
elRx.triggerLater({
val element = oldElement
if (isElementAvailable(element) && isElementAvailable(element.parentNode)) {
val newElement = elRx.now.render
oldElement = newElement
element.parentNode.replaceChild(newElement, element)
} else {
elRx.kill()
}
}: Unit)
parent.appendChild(oldElement)
implicit def rxBindNode[E <: Element, N: Renderable]: ReactiveWrite[E, BindNode[N]] =
new ReactiveWrite[E, BindNode[N]] {
def bindWrite(parent: E, property: BindNode[N]): Unit = {
val elRx = property.value.map(identity)
var oldElement = property.value.now.render
elRx.triggerLater({
val element = oldElement
if (isElementAvailable(element) && isElementAvailable(element.parentNode)) {
val newElement = elRx.now.render
oldElement = newElement
element.parentNode.replaceChild(newElement, element)
} else {
elRx.kill()
}
}: Unit)
parent.appendChild(oldElement)
}
}
}

private[this] final case class FormValueRW[E <: Element, T](event: String, read: dom.html.Input β‡’ T, write: (dom.html.Input, T) β‡’ Unit)
extends ReactiveRW[E, FormValue[T]] {
private[this] final case class FormValueRW[E <: Element, T](
event: String,
read: dom.html.Input β‡’ T,
write: (dom.html.Input, T) β‡’ Unit
) extends ReactiveRW[E, FormValue[T]] {

private[this] def safeRead(e: Element): Try[T] =
Try(read(e.asInstanceOf[Input])).filter(v β‡’ v != null && !js.isUndefined(v))

def bindRead(element: E, property: FormValue[T]): Unit = {
rxEventListener[E, Event].bindRead(element, EventListener(event, (e, _) β‡’ safeRead(e).foreach(property.value() = _)))
rxEventListener[E, Event].bindRead(
element,
EventListener(event, (e, _) β‡’ safeRead(e).foreach(property.value() = _))
)
}

def bindWrite(element: E, property: FormValue[T]): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import scalatags.JsDom
import org.scalajs.dom
import org.scalajs.dom.Node

trait JSRenderingContext extends RenderingContext with JSReactiveBinds with JSCallbacks with JSClassModifiers with JSImplicits {
trait JSRenderingContext
extends RenderingContext
with JSReactiveBinds
with JSCallbacks
with JSClassModifiers
with JSImplicits {
type Element = dom.Element
type Output = dom.Element
type FragT = dom.Node
type Output = dom.Element
type FragT = dom.Node

//noinspection TypeAnnotation
// noinspection TypeAnnotation
val scalaTags = JsDom
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import com.karasiq.bootstrap.components.generic.{GenComponent, GenDomComponent,
import com.karasiq.bootstrap.context.RenderingContext

trait BootstrapComponents { self: RenderingContext β‡’
final type ModifierFactory = generic.ModifierFactory[Element]
final type BootstrapComponent = generic.BootstrapComponent[Element]
final type BootstrapDomComponent = generic.BootstrapDomComponent[Element, FragT]
final type ModifierFactory = generic.ModifierFactory[Element]
final type BootstrapComponent = generic.BootstrapComponent[Element]
final type BootstrapDomComponent = generic.BootstrapDomComponent[Element, FragT]
final type BootstrapHtmlComponent = generic.BootstrapHtmlComponent[Element, Output, FragT]

implicit def renderBootstrapHtmlComponent[C](bc: C)(implicit ev: C β‡’ BootstrapHtmlComponent): scalaTags.Tag = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package object generic {
// Context-bound components
trait ModifierFactory[E] extends Modifier[E] {
// Shortcuts
protected type ElementT = E
protected type ElementT = E
protected type ModifierT = Modifier[E]

def createModifier: ModifierT
Expand Down Expand Up @@ -34,7 +34,7 @@ package object generic {
}

final def render(md: ModifierT*): ModifierT = {
renderFrag(md:_*)
renderFrag(md: _*)
}
}

Expand All @@ -44,7 +44,7 @@ package object generic {
def renderTag(md: ModifierT*): TagT

final def renderFrag(md: ModifierT*): FragT = {
renderTag(md:_*)
renderTag(md: _*)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ trait ClassModifiers { self: RenderingContext β‡’
}

case class ClassAdd(className: String) extends ClassModifier {
val classAdded = true
val classRemoved = false
val classAdded = true
val classRemoved = false
def applyTo(t: Element): Unit = addClass(t, className)
}

case class ClassRemove(className: String) extends ClassModifier {
val classAdded = false
val classRemoved = true
val classAdded = false
val classRemoved = true
def applyTo(t: Element): Unit = removeClass(t, className)
}

//noinspection MutatorLikeMethodIsParameterless
// noinspection MutatorLikeMethodIsParameterless
implicit class HtmlClassOps(className: String) {
def addClass: ClassAdd = {
ClassAdd(className)
Expand All @@ -43,13 +43,18 @@ trait ClassModifiers { self: RenderingContext β‡’
}

def classIf(state: Rx[Boolean]): Modifier = {
writeModifier(Modify[Element, Boolean](state, (e, v) β‡’ {
if (v) {
ClassModifiers.this.addClass(e, className)
} else {
ClassModifiers.this.removeClass(e, className)
}
}))
writeModifier(
Modify[Element, Boolean](
state,
(e, v) β‡’ {
if (v) {
ClassModifiers.this.addClass(e, className)
} else {
ClassModifiers.this.removeClass(e, className)
}
}
)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ object ReactiveBinds {
case class Visibility(visible: Rx[Boolean])
}

/**
* Predefined binds
/** Predefined binds
*/
trait ReactiveBinds { self: RenderingContext β‡’
protected type Event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ trait ReactiveImplicits { self: RenderingContext β‡’
}

implicit class RxVariableOps[T](value: Var[T]) {
def reactiveRead[EV](event: String, f: (Element, EV) β‡’ T)(implicit read: ReactiveRead[Element, EventListener[Element, EV]]): Modifier = {
readModifier(EventListener[Element, EV](event, (el, ev) β‡’ value() = f(el,ev)))
def reactiveRead[EV](event: String, f: (Element, EV) β‡’ T)(implicit
read: ReactiveRead[Element, EventListener[Element, EV]]
): Modifier = {
readModifier(EventListener[Element, EV](event, (el, ev) β‡’ value() = f(el, ev)))
}

def reactiveReadWrite[EV](event: String, read: (Element, EV) β‡’ T, write: (Element, T) β‡’ Unit)
(implicit rb: ReactiveRead[Element, EventListener[Element, EV]],
wb: ReactiveWrite[Element, Modify[Element, T]]): Modifier = new Modifier {
def reactiveReadWrite[EV](event: String, read: (Element, EV) β‡’ T, write: (Element, T) β‡’ Unit)(implicit
rb: ReactiveRead[Element, EventListener[Element, EV]],
wb: ReactiveWrite[Element, Modify[Element, T]]
): Modifier = new Modifier {
override def applyTo(t: Element): Unit = {
writeModifier(ReactiveBinds.Modify(value, write)).applyTo(t)
reactiveRead(event, read).applyTo(t)
Expand All @@ -39,8 +42,10 @@ trait ReactiveImplicits { self: RenderingContext β‡’
readModifier(FormValue(value))
}

def reactiveInput(implicit rb: ReactiveRead[Element, FormValue[T]],
wb: ReactiveWrite[Element, FormValue[T]]): Modifier = new Modifier {
def reactiveInput(implicit
rb: ReactiveRead[Element, FormValue[T]],
wb: ReactiveWrite[Element, FormValue[T]]
): Modifier = new Modifier {
def applyTo(t: Element): Unit = {
writeModifier(FormValue(value)).applyTo(t)
readModifier(FormValue(value)).applyTo(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import scalatags.generic

import com.karasiq.bootstrap.components.BootstrapComponents

trait RenderingContext extends ReactiveBinds with ReactiveImplicits with Callbacks
with BootstrapComponents with ClassModifiers {

trait RenderingContext
extends ReactiveBinds
with ReactiveImplicits
with Callbacks
with BootstrapComponents
with ClassModifiers {

type Element
type Output <: FragT
type FragT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ trait TextCallbacks extends Callbacks { self: RenderingContext β‡’

protected type ClickElement = Any
protected type InputElement = Any
protected type FormElement = Any
protected type FormElement = Any

object Callback extends CallbackFactory {
def onClick(f: ClickElement => Unit): Callback = {
def onClick(f: ClickElement β‡’ Unit): Callback = {
()
}

def onInput(f: (InputElement) => Unit): Callback = {
def onInput(f: (InputElement) β‡’ Unit): Callback = {
()
}

def onSubmit(f: (FormElement) => Unit): Callback = {
def onSubmit(f: (FormElement) β‡’ Unit): Callback = {
()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ trait TextClassModifiers extends ClassModifiers { self: TextRenderingContext β‡’

case classIndex β‡’
val (key, value) = e.attrs(classIndex)
val newValue = f(extractClasses(value))
val newValue = f(extractClasses(value))
e.attrs(classIndex) = (key, ClassesValueSource(newValue))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait TextReactiveBinds extends ReactiveBinds { self: TextRenderingContext β‡’

private[this] val NO_OP_BIND: ReactiveRW[Element, Nothing] = new ReactiveRW[Element, Nothing] {
def bindWrite(element: Builder, property: Nothing): Unit = ()
def bindRead(element: Builder, property: Nothing): Unit = ()
def bindRead(element: Builder, property: Nothing): Unit = ()
}

implicit def rxEventListener[EL <: Element, EV <: Event]: ReactiveRead[EL, ReactiveBinds.EventListener[EL, EV]] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import scala.language.postfixOps

trait TextRenderingContext extends RenderingContext with TextReactiveBinds with TextCallbacks with TextClassModifiers {
type Element = scalatags.text.Builder
type Output = String
type FragT = String
type Output = String
type FragT = String

val scalaTags = scalatags.Text
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object BootstrapJQueryContext {
object bootstrap extends js.Object
}

//noinspection ScalaUnusedExpression
// noinspection ScalaUnusedExpression
def useNpmImports(): Unit = {
imports.bootstrap
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package com.karasiq.bootstrap4

import rx._

/**
* Global context
/** Global context
*/
object Bootstrap {
private[this] lazy val _scalaRxContext = Ctx.Owner.safe()

lazy val js: JSBootstrapBundle = JSBootstrapBundle()(_scalaRxContext)
lazy val text: TextBootstrapBundle = TextBootstrapBundle()(_scalaRxContext)
lazy val js: JSBootstrapBundle = JSBootstrapBundle()(_scalaRxContext)
lazy val text: TextBootstrapBundle = TextBootstrapBundle()(_scalaRxContext)
lazy val default: JSBootstrapBundle = js
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ import com.karasiq.bootstrap4.popover.JSPopovers
import com.karasiq.bootstrap4.tooltip.JSTooltips

// JS components implementation
trait JSBootstrapBundle extends UniversalBootstrapBundle with JSRenderingContext with JSModals with JSTooltips
with JSPopovers with JSNavigationBars with JSCarousels with BootstrapJQueryContext
trait JSBootstrapBundle
extends UniversalBootstrapBundle
with JSRenderingContext
with JSModals
with JSTooltips
with JSPopovers
with JSNavigationBars
with JSCarousels
with BootstrapJQueryContext

object JSBootstrapBundle {
def apply()(implicit rx: Ctx.Owner): JSBootstrapBundle = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import scala.scalajs.js

@js.native
trait JSCarouselOptions extends js.Object {
var interval: Int = js.native
var pause: String = js.native
var wrap: Boolean = js.native
var interval: Int = js.native
var pause: String = js.native
var wrap: Boolean = js.native
var keyboard: Boolean = js.native
}
Loading