All Downloads are FREE. Search and download functionalities are using the official Maven repository.

outwatch.dom.Implicits.scala Maven / Gradle / Ivy

The newest version!
package outwatch.dom

import cats.effect.IO
import cats.syntax.apply._
import com.raquo.domtypes.generic.keys
import outwatch.ValueModifier
import outwatch.dom.helpers.BasicStyleBuilder

trait Implicits {

  implicit def valueModifier[T](value: T)(implicit mr: ValueModifier[T]): VDomModifier = mr.asModifier(value)

  implicit def optionIsEmptyModifier(opt: Option[VDomModifier]): VDomModifier = opt getOrElse VDomModifier.empty

  implicit def compositeModifier(modifiers: Seq[VDomModifier]): VDomModifier = VDomModifier.apply(modifiers : _*)

  implicit class ioVTreeMerge(vnode: VNode) {
    def apply(args: VDomModifier*): VNode = for {
      vnode <- vnode
      args <- args.sequence
    } yield vnode(args: _*)
  }

  implicit def StyleIsBuilder[T](style: keys.Style[T]): BasicStyleBuilder[T] = new BasicStyleBuilder[T](style.cssName)

  private[outwatch] implicit class SeqIOSequence[T](args: Seq[IO[T]]) {
    def sequence: IO[Seq[T]] = args.foldRight(IO.pure(List.empty[T]))((a, l) => a.map2(l)(_ :: _))
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy