Skip to content

Commit

Permalink
Improving examples and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Nov 2, 2024
1 parent 94cb086 commit dc13ec7
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 9 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- uses: coursier/cache-action@v6
- uses: olafurpg/setup-scala@v11
- uses: coursier/setup-action@v1
with:
java-version: [email protected]
- name: Indigo Compile & Test
run: ./mill __.compile
- name: Compile & Test
run: bash ci.sh
12 changes: 12 additions & 0 deletions ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# This script is used to everything basically builds correctly in a CI environment.

set -e

./mill __.compile
./mill __.fastLinkJS

cd integration-examples
bash ci.sh
cd ..
1 change: 1 addition & 0 deletions examples/effects/cats-effect/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Cats Effect
19 changes: 18 additions & 1 deletion examples/effects/cats-effect/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,33 @@ import tyrian.*

import scala.scalajs.js.annotation.*

/** To use Tyrian with Cats Effect, we need to bring in the tyrian-io library.
*
* ```
* ivy"io.indigoengine::tyrian-io::x.y.z" // Mill
* libraryDependencies += "io.indigoengine" %%% "tyrian-io" % "x.y.z" // SBT
* ```
*
* Then we can bring in the `TyrianIOApp` trait to create our application.
*/
//```scala
@JSExportTopLevel("TyrianApp")
object Counter extends TyrianIOApp[Msg, Model]:
//```

def router: Location => Msg = Routing.none(Msg.NoOp)

def init(flags: Map[String, String]): (Model, Cmd[IO, Msg]) =
(Model.init, Cmd.None)

/** `Cmd`s and `Sub`s then make use of the `IO` type to perform side effects.
*/
// ```scala
def update(model: Model): Msg => (Model, Cmd[IO, Msg]) =
case Msg.Increment => (model + 1, Cmd.None)
case Msg.Decrement => (model - 1, Cmd.None)
case Msg.NoOp => (model, Cmd.None)
// ```

def view(model: Model): Html[Msg] =
div(
Expand All @@ -26,8 +41,10 @@ object Counter extends TyrianIOApp[Msg, Model]:
button(onClick(Msg.Increment))("+")
)

// ```scala
def subscriptions(model: Model): Sub[IO, Msg] =
Sub.None
// ```

opaque type Model = Int
object Model:
Expand All @@ -38,4 +55,4 @@ object Model:
def -(other: Int): Model = i - other

enum Msg:
case Increment, Decrement, NoOp
case Increment, Decrement, NoOp
1 change: 1 addition & 0 deletions examples/effects/fs2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# FS2
1 change: 1 addition & 0 deletions examples/effects/zio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# ZIO
17 changes: 17 additions & 0 deletions examples/effects/zio/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,33 @@ import zio.interop.catz.*

import scala.scalajs.js.annotation.*

/** To use Tyrian with ZIO, we need to bring in the tyrian-zio library.
*
* ```
* ivy"io.indigoengine::tyrian-zio::x.y.z" // Mill
* libraryDependencies += "io.indigoengine" %%% "tyrian-zio" % "x.y.z" // SBT
* ```
*
* Then we can bring in the `TyrianZIOApp` trait to create our application.
*/
//```scala
@JSExportTopLevel("TyrianApp")
object Main extends TyrianZIOApp[Msg, Model]:
//```

def router: Location => Msg = Routing.none(Msg.NoOp)

def init(flags: Map[String, String]): (Model, Cmd[Task, Msg]) =
(Model.init, Cmd.None)

/** `Cmd`s and `Sub`s then make use of ZIO's `Task` type to perform side effects.
*/
// ```scala
def update(model: Model): Msg => (Model, Cmd[Task, Msg]) =
case Msg.Increment => (model + 1, Cmd.None)
case Msg.Decrement => (model - 1, Cmd.None)
case Msg.NoOp => (model, Cmd.None)
// ```

def view(model: Model): Html[Msg] =
div(
Expand All @@ -27,8 +42,10 @@ object Main extends TyrianZIOApp[Msg, Model]:
button(onClick(Msg.Increment))("+")
)

// ```scala
def subscriptions(model: Model): Sub[Task, Msg] =
Sub.None
// ```

opaque type Model = Int
object Model:
Expand Down
1 change: 1 addition & 0 deletions examples/getting-started/minimal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Minimal Setup
1 change: 1 addition & 0 deletions examples/getting-started/subcomponents/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Sub-Components
1 change: 1 addition & 0 deletions examples/networking/http/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Http
1 change: 1 addition & 0 deletions examples/networking/http4s-dom/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Http4s-Dom
1 change: 1 addition & 0 deletions examples/networking/websockets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# WebSockets
3 changes: 0 additions & 3 deletions examples/networking/websockets/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ object Model:
val init: Model =
Model(EchoSocket.init, Nil)

/** Encapsulates and manages our socket connection, cleanly proxies methods, and knows how to draw the right
* connnect/disconnect button.
*/
final case class EchoSocket(socketUrl: String, socket: Option[WebSocket[IO]]):

def connectDisconnectButton =
Expand Down
1 change: 1 addition & 0 deletions examples/svg/clock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Clock SVG
1 change: 1 addition & 0 deletions examples/ui/debouncing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Debouncing
1 change: 1 addition & 0 deletions examples/ui/field/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Input Field
1 change: 1 addition & 0 deletions website/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tyrian.indigoengine.io
1 change: 1 addition & 0 deletions website/documentation/directory.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ laika.navigationOrder = [
architecture
information
guides
integration-examples.md
]
7 changes: 7 additions & 0 deletions website/documentation/integration-examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Integration-Examples

The 'feature examples' available on this website try to cover how to use Tyrian, but not the various ways that it can be setup and integrated with different build tools, services, networking protocols, and css frameworks.

Some examples of those kinds of integrations can be found in the [integrated-examples](https://github.com/PurpleKingdomGames/tyrian-docs/tree/main/integrated-examples) folder of the tyrian-docs repo.

> Note: The networking examples are duplicated in both example areas. In the feature examples they compile and are viewable, but may not work. In the integrated examples, if run correctly, they should work.
2 changes: 1 addition & 1 deletion website/examples/directory.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
laika.title = "Examples"
laika.title = "Feature Examples"

0 comments on commit dc13ec7

Please sign in to comment.