Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redux state should be initialized by init #103

Open
ahstro opened this issue Mar 30, 2017 · 4 comments
Open

Redux state should be initialized by init #103

ahstro opened this issue Mar 30, 2017 · 4 comments

Comments

@ahstro
Copy link
Contributor

ahstro commented Mar 30, 2017

Redux state should be initialized with defaults, as specified by init, e.g., in this example app (basically the same as in the README), the Redux state should be { ..., elm: 0, ...} before any actions, but it's { ..., elm: {}, ...} until @@elm/increment, at which point it turns into { ..., elm: 1, ...}.

port module Reducer exposing (..)

import Redux
import Json.Encode
import Json.Decode

port increment : ({} -> msg) -> Sub msg

subscriptions : Model -> Sub Msg
subscriptions _ =
    Sub.batch
        [ increment <| always Increment
        ]

encode : Model -> Json.Encode.Value
encode model =
    Json.Encode.int model

init : ( Model, Cmd msg )
init =
    ( 0, Cmd.none )

type alias Model =
    Int

type Msg
    = Increment

update : Msg -> Model -> ( Model, Cmd msg )
update msg model =
    case msg of
        Increment ->
            ( model   1, Cmd.none )

main =
    Redux.program
        { init = init
        , update = update
        , encode = encode
        , subscriptions = subscriptions
        }
@stoeffel
Copy link
Owner

stoeffel commented Jul 5, 2017

published with v4.0.0. sorry that this took so long.

@stoeffel stoeffel closed this as completed Jul 5, 2017
@ahstro
Copy link
Contributor Author

ahstro commented Jul 5, 2017

That PR unfortunately doesn't solve this issue, just part of it. Look at this comment for more info 🙂

@stoeffel stoeffel reopened this Jul 5, 2017
@stoeffel
Copy link
Owner

stoeffel commented Jul 5, 2017

Oups, sorry. We could use programWithFlags like you mentioned, but then we need something like

decode : Json.Encode.Value -> Model
decode flags =
    -- ...

@ahstro
Copy link
Contributor Author

ahstro commented Jul 5, 2017

It's been a while since I dug into the code and we're unfortunately not using this in our project anymore, so I'd have a hard time looking into the proper solution :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants