Skip to content

Instantly share code, notes, and snippets.

@jamesmacaulay
Last active September 1, 2015 18:16
Show Gist options
  • Save jamesmacaulay/bc0c0f0de458f66c92bf to your computer and use it in GitHub Desktop.
Save jamesmacaulay/bc0c0f0de458f66c92bf to your computer and use it in GitHub Desktop.
// 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