-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e436ac
commit a3b9a39
Showing
4 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Tyrian counter example - No NPM Version! | ||
|
||
This is yet another version of the Counter example, but this one is just plain old HTML + JavaScript. No NPM, no bundlers, nothing. | ||
|
||
You will need a static http server unfortunately, you can install one globally with ...npm (there are others, I like this one): | ||
|
||
```npm install -g http-server``` | ||
|
||
To run your http server, `cd` into this directory (`tyrian/examples/no-npm`) using your terminal, and then run: | ||
|
||
```http-server -c-1``` | ||
|
||
Then navigate to [http://localhost:8080/](http://localhost:8080/) in your browser of choice. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Tyrian Counter Example (No NPM)</title> | ||
</head> | ||
|
||
<body> | ||
<div id="myapp"></div> | ||
<script type="text/javascript" src="./target/scala-3.1.2/no-npm-fastopt.js"></script> | ||
<script type="text/javascript"> | ||
TyrianApp.launch("myapp"); | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package example | ||
|
||
import cats.effect.IO | ||
import tyrian.Html.* | ||
import tyrian.* | ||
|
||
import scala.scalajs.js.annotation.* | ||
|
||
@JSExportTopLevel("TyrianApp") | ||
object Main extends TyrianApp[Msg, Model]: | ||
|
||
def init(flags: Map[String, String]): (Model, Cmd[IO, Msg]) = | ||
(Model.init, Cmd.None) | ||
|
||
def update(model: Model): Msg => (Model, Cmd[IO, Msg]) = | ||
case Msg.Increment => (model + 1, Cmd.None) | ||
case Msg.Decrement => (model - 1, Cmd.None) | ||
|
||
def view(model: Model): Html[Msg] = | ||
div( | ||
button(onClick(Msg.Decrement))("-"), | ||
div(model.toString), | ||
button(onClick(Msg.Increment))("+") | ||
) | ||
|
||
def subscriptions(model: Model): Sub[IO, Msg] = | ||
Sub.None | ||
|
||
opaque type Model = Int | ||
object Model: | ||
def init: Model = 0 | ||
|
||
extension (i: Model) | ||
def +(other: Int): Model = i + other | ||
def -(other: Int): Model = i - other | ||
|
||
enum Msg: | ||
case Increment, Decrement |