This file contains hidden or 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
I have an Effect that is called from my `update` function (e.g. `Effects.batch [someEffect, getDataFromServer]`) | |
The result of this effect should be piped back as an action, however I was able to do it only using this ugly work around: | |
getDataFromServer : Effects Action | |
getDataFromServer = | |
-- @todo: Get rid of Task.sleep | |
Task.sleep (0) | |
|> Task.map (\_ -> GetDataFromServer) | |
|> Effects.task |
This file contains hidden or 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
update : Action -> Model -> (Model, Effects Action) | |
update action model = | |
case action of | |
UpdateDataFromServer result -> | |
case result of | |
Ok (id, name) -> ({nodel | id <- id}, Effects.none) | |
Err msg -> (newModel, Effects.none) | |
getJson : String -> Effects Action | |
getJson url = |
This file contains hidden or 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
import Graphics.Element exposing (show) | |
import Json.Decode as Json exposing ((:=)) | |
-- MODEL | |
type alias Model = | |
{ id: Int | |
, label: String | |
} |
This file contains hidden or 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
decodeUrl : Json.Decoder (List Item) | |
decodeUrl = | |
Json.at ["data"] | |
<| Json.list | |
<| Json.object2 Item | |
("id" := Json.int) | |
("title" := Json.string) |
This file contains hidden or 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
import Graphics.Element exposing (show) | |
import Json.Decode as Json exposing ((:=)) | |
import Http | |
import Task exposing (Task, andThen, onError) | |
import TaskTutorial exposing (print) | |
type alias Id = Int | |
type alias Article = |
This file contains hidden or 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
module EventLog where | |
import Html exposing (..) | |
import Html.Events exposing (..) | |
import Html.Attributes exposing (..) | |
import Signal exposing (..) | |
import StartApp.Simple exposing (..) | |
type alias Model = | |
{ events: List String } |
This file contains hidden or 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
import TaskTutorial exposing (getCurrentTime, print) | |
import Task exposing (Task, andThen) | |
import Graphics.Element exposing (show) | |
port runner : Task x () | |
port runner = | |
getCurrentTime `andThen` print | |
main = | |
show "Open the Developer Console to see the current timestamp." |
This file contains hidden or 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
import Signal exposing (foldp, (<~)) | |
import Mouse | |
import Time exposing (Time, fps) | |
import Graphics.Element exposing (..) | |
import Debug exposing (watch) | |
timeSoFar : Signal Time | |
timeSoFar = | |
let | |
d = Debug.watch "foo" "bar" |
This file contains hidden or 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
import Effects exposing (Never) | |
import RandomGif exposing (init, update, view) | |
import StartApp | |
import Task | |
app = | |
StartApp.start | |
{ init = init "funny cats" |
This file contains hidden or 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
import Effects exposing (Never) | |
import RandomGif exposing (init, update, view) | |
import StartApp | |
import Task | |
app = | |
StartApp.start | |
{ init = init "funny cats" |