diff --git a/02-guides/cmd/index.html b/02-guides/cmd/index.html index b63f88fb..dd34e55a 100644 --- a/02-guides/cmd/index.html +++ b/02-guides/cmd/index.html @@ -153,19 +153,19 @@

Cmd.SideEffect { println(msg) } -

<div id="mdoc-html-run1" data-mdoc-js></div>

+

But commands can also return values in the form of messages. The Random command looks like this:

Random.double[IO]
-

<div id="mdoc-html-run2" data-mdoc-js></div>

+

...and produces an instance of RandomValue, but this leads to a problem since RandomValue is almost certainly not your app's Msg type, and so we must map over the result:

enum MyMsg:
   case MyRandom(d: Double) extends MyMsg
 
 Random.double[IO].map(next => MyMsg.MyRandom(next.value))
-

<div id="mdoc-html-run3" data-mdoc-js></div>

+

These are simple examples, but there are much more complicated uses for commands. One great use of commands is for making HTTP requests where the response is decoded into a Msg. - <script type="text/javascript" src="cmd.md.js" defer></script> - <script type="text/javascript" src="mdoc.js" defer></script>

+ +

diff --git a/02-guides/goodies/index.html b/02-guides/goodies/index.html index 50b818f1..89a2fb7b 100644 --- a/02-guides/goodies/index.html +++ b/02-guides/goodies/index.html @@ -170,7 +170,7 @@

case FileReader.Result.Error(msg) => Msg.Error(msg) case FileReader.Result.File(name, path, contents) => Msg.Read(contents) } -

<div id="mdoc-html-run2" data-mdoc-js></div>

+

Http

Please see Networking for details.

@@ -184,7 +184,7 @@

case ImageLoader.Result.ImageLoadError(msg, path) => Msg.Error(msg) case ImageLoader.Result.Image(imageElement) => Msg.UseImage(imageElement) } -

<div id="mdoc-html-run3" data-mdoc-js></div>

+

LocalStorage

A series of commands that mirror the localstorage interface.

@@ -217,7 +217,7 @@

case LocalStorage.Result.Length(value) => Msg.Read(value.toString) } ) -

<div id="mdoc-html-run4" data-mdoc-js></div>

+

Logger

Allows you to log to your browsers JavaScript console:

@@ -225,13 +225,13 @@

val cmd: Cmd[IO, Msg] = Logger.info("Log this!") -

<div id="mdoc-html-run5" data-mdoc-js></div>

+

If you're app is doing a lot of regular work, you can cut down the noise with the 'once' versions:

import tyrian.cmds.*
 
 val cmd: Cmd[IO, Msg] =
   Logger.debugOnce("Log this exact message only once!")
-

<div id="mdoc-html-run6" data-mdoc-js></div>

+

Random

As you might expect, Random produces random values! Random works slightly differently from other commands, in that it doesn't except a conversion function to turn the result into a message. You do that by mapping over it.

@@ -246,7 +246,7 @@

Random.shuffle[IO, Int](List(1, 2, 3)).map(l => toMessage(l.value.toString)), Random.Seeded(12l).alphaNumeric[IO](5).map(a => toMessage(a.value.mkString)) ) -

<div id="mdoc-html-run7" data-mdoc-js></div>

+

Built-in Cmd + Sub goodies

These tools make use of a combination of commands and subscriptions to achieve a result. Note that unlike in the next section, these entries share nothing apart from, say, a key value, i.e. there is no common state to manage or store in a model.

@@ -274,8 +274,8 @@

  • WebSocket - Allows you to send and receive data to/from a socket server (see Networking).
  • TyrianIndigoBridge - Allows your Tyrian app to communicates with embedded Indigo games. - <script type="text/javascript" src="goodies.md.js" defer></script> - <script type="text/javascript" src="mdoc.js" defer></script>
  • + + diff --git a/02-guides/guided-tour/index.html b/02-guides/guided-tour/index.html index 7088ba63..85a55918 100644 --- a/02-guides/guided-tour/index.html +++ b/02-guides/guided-tour/index.html @@ -156,7 +156,7 @@

    enum Msg: case Increment, Decrement, NoOp -

    <div id="mdoc-html-run0" data-mdoc-js></div>

    +

    Lets go through it...

    TyrianIOApp / TyrianZIOApp

    @@ -167,7 +167,7 @@

    The model

    type Model = Int
    -

    <div id="mdoc-html-run1" data-mdoc-js></div>

    +

    Our app is a counter, so we need a number we can increment and decrement. In this super simple example, an Int is all that we need for our whole model. Normally you'd probably have a case class or something instead. To make it fit nicely, we've allocated our Int to a Model type alias.

    The version in the examples uses an opaque type, but here we've reduced it to a type alias.

    To use our model, we're going to have to initialize it!

    @@ -178,7 +178,7 @@

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

    <div id="mdoc-html-run3" data-mdoc-js></div>

    +

    There's a few things going on here, the only bit we really care about here is the 0 because that is going to be the starting value of our 'model'.

    Some of the other things you can see here: