Last active
September 1, 2015 18:16
-
-
Save jamesmacaulay/bc0c0f0de458f66c92bf to your computer and use it in GitHub Desktop.
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
// Elm code from https://github.com/evancz/elm-architecture-tutorial#example-5-random-gif-viewer | |
// | |
// type Action | |
// = RequestMore | |
// | NewGif (Maybe String) | |
// | |
// | |
// update : Action -> Model -> (Model, Effects Action) | |
// update msg model = | |
// case msg of | |
// RequestMore -> | |
// ( model | |
// , getRandomGif model.topic | |
// ) | |
// | |
// NewGif maybeUrl -> | |
// ( Model model.topic (Maybe.withDefault model.gifUrl maybeUrl) | |
// , Effects.none | |
// ) | |
// | |
// -- getRandomGif : String -> Effects Action | |
/* | |
* @flow | |
* | |
* translation to pseudo-redux: | |
*/ | |
function reducer(state: Model, action: Action): [Model, Effects] { | |
switch(action.type) { | |
case RequestMore: | |
return [state, getRandomGif(state.topic)]; | |
case NewGif: | |
if (action.gifUrl) { | |
return [{...state, gifUrl: action.gifUrl}, null]; | |
} else { | |
return state; | |
} | |
default: | |
return state; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment