Skip to content

Instantly share code, notes, and snippets.

View amitaibu's full-sized avatar

Amitai Burstein amitaibu

View GitHub Profile
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
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 =
import Graphics.Element exposing (show)
import Json.Decode as Json exposing ((:=))
-- MODEL
type alias Model =
{ id: Int
, label: String
}
decodeUrl : Json.Decoder (List Item)
decodeUrl =
Json.at ["data"]
<| Json.list
<| Json.object2 Item
("id" := Json.int)
("title" := Json.string)
@amitaibu
amitaibu / Main.elm
Last active September 2, 2015 11:25
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 =
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 }
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."
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"
@amitaibu
amitaibu / Main.elm
Last active September 2, 2015 19:57
import Effects exposing (Never)
import RandomGif exposing (init, update, view)
import StartApp
import Task
app =
StartApp.start
{ init = init "funny cats"
import Effects exposing (Never)
import RandomGif exposing (init, update, view)
import StartApp
import Task
app =
StartApp.start
{ init = init "funny cats"