Skip to content

Commit

Permalink
Merge pull request #38 from buntec/crossbuild-for-scala-3
Browse files Browse the repository at this point in the history
add cross-build to Scala 3; minor changes to make Scala 3 compiler happy
  • Loading branch information
buntec authored May 24, 2022
2 parents 7528ba8 + ab0c39a commit cdea869
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 27 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.8]
scala: [2.13.8, 3.1.2]
java: [temurin@8]
project: [rootJS]
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -157,6 +157,16 @@ jobs:
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.1.2, rootJS)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3.1.2-rootJS

- name: Inflate target directories (3.1.2, rootJS)
run: |
tar xf targets.tar
rm targets.tar
- name: Import signing key
if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE == ''
run: echo $PGP_SECRET | base64 -di | gpg --import
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ serving the `index.html` using a simple development server, e.g.,
There is also an implementation of [todomvc](https://github.com/tastejs/todomvc)
in the `todo-mvc` folder.

To use ff4s in your own project, add this to your `build.sbt`:
```scala
enablePlugins(ScalaJSPlugin)
libraryDependencies += "io.github.buntec.ff4s" %%% "ff4s" % "0.2.0"
libraryDependencies += "io.github.buntec" %%% "ff4s" % "0.3.0"
```
18 changes: 8 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Global / onChangedBuildSource := ReloadOnSourceChanges
// Global / resolvers += "Sonatype S01 OSS Snapshots" at "https://s01.oss.sonatype.org/content/repositories/snapshots"

ThisBuild / tlBaseVersion := "0.2"
ThisBuild / tlBaseVersion := "0.3"

ThisBuild / crossScalaVersions := Seq("2.13.8")
lazy val scala213 = "2.13.8"
ThisBuild / scalaVersion := scala213
ThisBuild / crossScalaVersions := Seq(scala213, "3.1.2")

ThisBuild / organization := "io.github.buntec"
ThisBuild / organizationName := "buntec"
Expand All @@ -18,18 +20,17 @@ ThisBuild / tlFatalWarningsInCi := false

lazy val scalajsDomVersion = "2.2.0"
lazy val domtypesVersion = "0.15.1"
lazy val circeVersion = "0.15.0-M1"
lazy val circeVersion = "0.14.2"
lazy val catsVersion = "2.7.0"
lazy val catsEffectVersion = "3.3.12"
lazy val fs2Version = "3.2.7"
lazy val kindProjectorVersion = "0.13.2"
lazy val http4sDomVersion = "0.2.1"
lazy val http4sVersion = "0.23.11"
lazy val http4sVersion = "0.23.12"
lazy val betterMonadicForVersion = "0.3.1"

lazy val scalaJsSnabbdomVersion = "0.1.0-M2"

lazy val root = tlCrossRootProject.aggregate(ff4s, examples)
lazy val root = tlCrossRootProject.aggregate(ff4s, examples, todoMvc)

lazy val ff4s = (project in file("ff4s"))
.enablePlugins(ScalaJSPlugin)
Expand Down Expand Up @@ -72,10 +73,7 @@ lazy val todoMvc = (project in file("todo-mvc"))
.settings(
scalaJSUseMainModuleInitializer := true,
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % scalajsDomVersion,
"io.circe" %%% "circe-generic" % circeVersion,
"io.circe" %%% "circe-literal" % circeVersion,
"io.circe" %%% "circe-parser" % circeVersion
"org.scala-js" %%% "scalajs-dom" % scalajsDomVersion
)
)
.dependsOn(ff4s)
8 changes: 5 additions & 3 deletions examples/src/main/scala/ff4s/examples/example1/App.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package ff4s.examples.example1

import org.scalajs.dom
import cats.effect.kernel.Async
import cats.effect.kernel.Resource
import ff4s.Store

// The obligatory to-do list app.
class App[F[_]: Async] {
Expand All @@ -37,8 +39,8 @@ class App[F[_]: Async] {
case class SetTodoInput(what: String) extends Action

// Build our store by assigning actions to effects.
implicit val store = ff4s.Store[F, State, Action](State()) {
ref => (a: Action) =>
implicit val store: Resource[F, Store[F, State, Action]] =
ff4s.Store[F, State, Action](State()) { ref => (a: Action) =>
a match {
case AddTodo =>
ref.update { state =>
Expand All @@ -59,7 +61,7 @@ class App[F[_]: Async] {
}
case SetTodoInput(what) => ref.update(_.copy(todoInput = Some(what)))
}
}
}

// Create the DSL for our model.
val dsl = new ff4s.Dsl[F, State, Action]
Expand Down
3 changes: 2 additions & 1 deletion examples/src/main/scala/ff4s/examples/example2/App.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import io.circe.parser._
import io.circe.generic.auto._

import cats.effect.kernel.Fiber
import ff4s.Store

// This is a small demo application so show off the basic functionality of ff4s.
// It uses tailwindcss for simple styling.
Expand Down Expand Up @@ -100,7 +101,7 @@ class App[F[_]: Async] {
case object StopWebsocket extends Action

// Create a store by assigning actions to effects in F.
implicit val store = for {
implicit val store: Resource[F, Store[F, State, Action]] = for {
store <- ff4s.Store[F, State, Action](State()) { ref => (a: Action) =>
a match {
case StopWebsocket =>
Expand Down
2 changes: 1 addition & 1 deletion ff4s/src/main/scala/ff4s/EventPropsDsl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.raquo.domtypes.generic.builders.canonical.CanonicalEventPropBuilder
import com.raquo.domtypes.generic.keys.EventProp

trait EventPropsDsl[F[_], State, Action] {
self: ModifierDsl[F, State, Action] =>
self: ModifierDsl[F, State, Action] with Dsl[F, State, Action] =>

trait EventPropsSyntax
extends CanonicalEventPropBuilder[dom.Event]
Expand Down
3 changes: 2 additions & 1 deletion ff4s/src/main/scala/ff4s/HtmlAttrsDsl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import com.raquo.domtypes.generic.builders.PropBuilder
import com.raquo.domtypes.generic.builders.canonical.CanonicalHtmlAttrBuilder
import com.raquo.domtypes.generic.builders.canonical.CanonicalReflectedHtmlAttrBuilder

trait HtmlAttrsDsl[F[_], State, Action] { self: ModifierDsl[F, State, Action] =>
trait HtmlAttrsDsl[F[_], State, Action] {
self: ModifierDsl[F, State, Action] with Dsl[F, State, Action] =>

trait HtmlAttrsSyntax
extends HtmlAttrs[HtmlAttr]
Expand Down
3 changes: 2 additions & 1 deletion ff4s/src/main/scala/ff4s/PropDsl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import com.raquo.domtypes.generic.defs.props.Props
import com.raquo.domtypes.generic.keys.Prop
import com.raquo.domtypes.generic.builders.canonical.CanonicalPropBuilder

trait PropDsl[F[_], State, Action] { self: ModifierDsl[F, State, Action] =>
trait PropDsl[F[_], State, Action] {
self: ModifierDsl[F, State, Action] with Dsl[F, State, Action] =>

trait PropsSyntax extends Props[Prop] with CanonicalPropBuilder {

Expand Down
3 changes: 2 additions & 1 deletion ff4s/src/main/scala/ff4s/StyleDsl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import com.raquo.domtypes.generic.keys.Style
import com.raquo.domtypes.generic.defs.styles.{Styles, Styles2}
import com.raquo.domtypes.generic.builders.StyleBuilders

trait StyleDsl[F[_], State, Action] { self: ModifierDsl[F, State, Action] =>
trait StyleDsl[F[_], State, Action] {
self: ModifierDsl[F, State, Action] with Dsl[F, State, Action] =>

trait StylesSyntax
extends Styles[Modifier]
Expand Down
3 changes: 2 additions & 1 deletion ff4s/src/main/scala/ff4s/SvgAttrsDsl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import com.raquo.domtypes.generic.keys.SvgAttr
import com.raquo.domtypes.generic.builders.canonical.CanonicalSvgAttrBuilder
import com.raquo.domtypes.generic.defs.attrs.SvgAttrs

trait SvgAttrsDsl[F[_], State, Action] { self: ModifierDsl[F, State, Action] =>
trait SvgAttrsDsl[F[_], State, Action] {
self: ModifierDsl[F, State, Action] with Dsl[F, State, Action] =>

trait SvgAttrsSyntax extends SvgAttrs[SvgAttr] with CanonicalSvgAttrBuilder {

Expand Down
2 changes: 1 addition & 1 deletion ff4s/src/main/scala/ff4s/VNode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private[ff4s] object VNode {
key = key,
hook = Some(snabbdom.Hooks(insert = insertHook, destroy = destroyHook)),
on = handlers.map { case (eventName, handler) =>
(eventName -> ((e: dom.Event) =>
(eventName -> snabbdom.EventHandler((e: dom.Event) =>
handler(e).fold(())(action =>
dispatcher.unsafeRunAndForget(actionDispatch(action))
)
Expand Down
24 changes: 21 additions & 3 deletions todo-mvc/src/main/scala/ff4s/todomvc/App.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
/*
* Copyright 2022 buntec
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ff4s.todomvc

import org.scalajs.dom
import cats.effect.kernel.Async
import scala.collection.immutable.IntMap
import cats.effect.kernel.Resource
import ff4s.Store

class App[F[_]: Async] {

Expand Down Expand Up @@ -42,8 +60,8 @@ class App[F[_]: Async] {
case class RemoveTodo(id: Int) extends Action
case class SetTodoInput(what: String) extends Action

implicit val store = ff4s.Store[F, State, Action](State()) {
ref => (a: Action) =>
implicit val store: Resource[F, Store[F, State, Action]] =
ff4s.Store[F, State, Action](State()) { ref => (a: Action) =>
a match {
case SetFilter(filter) => ref.update(_.copy(filter = filter))
case UpdateTodo(todo) =>
Expand All @@ -68,7 +86,7 @@ class App[F[_]: Async] {
ref.update { state => state.copy(todos = state.todos - id) }
case SetTodoInput(what) => ref.update(_.copy(todoInput = Some(what)))
}
}
}

val dsl = new ff4s.Dsl[F, State, Action]

Expand Down
16 changes: 16 additions & 0 deletions todo-mvc/src/main/scala/ff4s/todomvc/Main.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2022 buntec
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ff4s.todomvc

import cats.effect.{IO, IOApp}
Expand Down

0 comments on commit cdea869

Please sign in to comment.