Skip to content

Commit

Permalink
Made Tyrian-Tags, Tyrian module now JS only
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Apr 11, 2024
1 parent aab783f commit f7b5753
Show file tree
Hide file tree
Showing 53 changed files with 71 additions and 51 deletions.
29 changes: 23 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ lazy val tyrianProject =
logoSettings(version)
)
.aggregate(
tyrianTags.js,
tyrianTags.jvm,
tyrian.js,
tyrian.jvm,
tyrianIO.js,
tyrianZIO.js,
sandbox.js,
Expand All @@ -134,16 +135,32 @@ lazy val tyrianProject =
sandboxSSR.jvm
)

lazy val tyrian =
lazy val tyrianTags =
crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Full)
.in(file("tyrian-tags"))
.settings(
name := "tyrian",
name := "tyrian-tags",
commonSettings ++ publishSettings,
Compile / sourceGenerators += codeGen("tyrian", TagGen.gen).taskValue,
Compile / sourceGenerators += codeGen("tyrian", AttributeGen.gen).taskValue,
Compile / sourceGenerators += codeGen("CSS", "tyrian", CSSGen.gen).taskValue
)
.jsSettings(
commonJsSettings,
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % Dependencies.scalajsDomVersion
)
)

lazy val tyrian =
crossProject(JSPlatform)
.crossType(CrossType.Pure)
.withoutSuffixFor(JSPlatform)
.settings(
name := "tyrian",
commonSettings ++ publishSettings
)
.jsSettings(
commonJsSettings,
libraryDependencies ++= Seq(
Expand All @@ -152,6 +169,7 @@ lazy val tyrian =
"io.github.buntec" %%% "scala-js-snabbdom" % Dependencies.scalajsSnabbdom
)
)
.dependsOn(tyrianTags)

lazy val tyrianIO =
crossProject(JSPlatform)
Expand Down Expand Up @@ -223,7 +241,7 @@ lazy val sandboxZIO =
lazy val sandboxSSR =
crossProject(JVMPlatform)
.crossType(CrossType.Pure)
.dependsOn(tyrian, tyrianHtmx)
.dependsOn(tyrianTags, tyrianHtmx)
.in(file("sandbox-ssr"))
.settings(
neverPublish,
Expand All @@ -244,7 +262,6 @@ lazy val unidocs =
name := "Tyrian",
neverPublish,
ScalaUnidoc / unidoc / unidocProjectFilter := inAnyProject -- inProjects(
tyrian.jvm,
sandboxZIO.js,
sandbox.js,
docs,
Expand Down Expand Up @@ -344,7 +361,7 @@ lazy val tyrianHtmx =
.jsSettings(
commonJsSettings
)
.dependsOn(tyrian)
.dependsOn(tyrianTags)

addCommandAlias(
"sandboxBuild",
Expand Down
8 changes: 8 additions & 0 deletions tyrian-tags/js/src/main/scala/tyrian/Tyrian.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package tyrian

object Tyrian:

type Event = org.scalajs.dom.Event
type KeyboardEvent = org.scalajs.dom.KeyboardEvent
type MouseEvent = org.scalajs.dom.MouseEvent
type HTMLInputElement = org.scalajs.dom.HTMLInputElement
5 changes: 5 additions & 0 deletions tyrian-tags/js/src/main/scala/tyrian/syntax.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package tyrian

object syntax:

extension [M](oa: Option[Elem[M]]) def orEmpty: Elem[M] = oa.getOrElse(tyrian.Empty)
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package tyrian

trait LocationPlatform

44 changes: 0 additions & 44 deletions tyrian/js/src/main/scala/tyrian/Tyrian.scala

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.scalajs.dom.Element
import org.scalajs.dom.HTMLElement
import org.scalajs.dom.document
import org.scalajs.dom.window
import tyrian.runtime.TyrianRuntime

import scala.annotation.nowarn
import scala.scalajs.js.Promise
Expand Down Expand Up @@ -110,7 +111,7 @@ trait TyrianAppF[F[_]: Async, Msg, Model]:

def ready(node: Element, flags: Map[String, String]): Unit =
run(
Tyrian.start[F, Model, Msg](
TyrianAppF.start[F, Model, Msg](
node,
router,
_init(flags),
Expand Down Expand Up @@ -165,3 +166,35 @@ object TyrianAppF:
case (dataAttr, attrValue) if dataAttr.startsWith("tyrianFlag") =>
dataAttr.replaceFirst("^tyrianFlag", "") -> attrValue
}.toMap

/** Directly starts the app. Computes the initial state of the given application, renders it on the given DOM element,
* and listens to user actions
* @param init
* initial state
* @param update
* state transition function
* @param view
* view function
* @param subscriptions
* subscriptions function
* @param node
* the DOM element to mount the app to
* @param runner
* the function that runs the program. Has a type of `F[Option[Msg]] => (Either[Throwable, Option[Msg]] => Unit) =>
* Unit`, essentially: `task.unsafeRunAsync(callback)`
* @tparam F
* The effect type to use, e.g. `IO`
* @tparam Model
* Type of model
* @tparam Msg
* Type of messages
*/
def start[F[_]: Async, Model, Msg](
node: Element,
router: Location => Msg,
init: (Model, Cmd[F, Msg]),
update: Model => Msg => (Model, Cmd[F, Msg]),
view: Model => Html[Msg],
subscriptions: Model => Sub[F, Msg]
): F[Nothing] =
TyrianRuntime[F, Model, Msg](router, node, init._1, init._2, update, view, subscriptions)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit f7b5753

Please sign in to comment.