A better way to this is to use Maybe_s:
main : Program (Maybe Flags)
main =
App.programWithFlags
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}
init : Maybe Flags -> ( AppState, Cmd Msg )
init maybeFlags =
let
appStateInit =
case maybeFlags of
Nothing ->
defaultAppState
Maybe.Just flags ->
appStateFromFlags flags
in
( appStateInit, Layout.sub0 Mdl )
On Friday, July 29, 2016 at 1:29:58 PM UTC+2, Robert Walter wrote:
>
> Oh man, I just found that out as well. Thank you.
>
> So, I changed it like so:
>
> type alias AppState =
> { mdl : Material.Model
> , viewSelected : Int
> , ...
> , titleEditable : Bool
> , refreshEditorContent : Bool
> }
>
> type alias Flags =
> { viewSelected : Int
> , ...
> , titleEditable : Bool
> , refreshEditorContent : Bool
> }
>
> init : Flags -> ( AppState, Cmd Msg )
> init flags =
> ( defaultOrFromFlags flags, Layout.sub0 Mdl )
>
> Thanks again!
>
>
> On Friday, July 29, 2016 at 1:25:48 PM UTC+2, Sergey Skrynnikov wrote:
>>
>> Hi Robert,
>>
>> your flags don't have to be of the same type as the model - try modifying
>> your 'init' function to take only your partial state and return (Model, Cmd
>> Msg).
>>
>> пятница, 29 июля 2016 г., 14:14:39 UTC+3 пользователь Robert Walter
>> написал:
>>>
>>> Hello,
>>>
>>> I try to initialize my elm application using programWithFlags.
>>>
>>> My app makes use of elm-mdl, so my model looks something like this:
>>>
>>> type alias AppState =
>>> { mdl : Material.Model
>>> , viewSelected : Int
>>> , ...
>>> , titleEditable : Bool
>>> , refreshEditorContent : Bool
>>> }
>>>
>>> In other words, it contains a Material.Model that I need to make proper
>>> use of elm-mdl.
>>>
>>> When I try to use App.programWithFlags, however, having Material.Model
>>> in my AppState leads to the following error:
>>>
>>>
>>> -- BAD FLAGS -------------------------------------------------------
>>> src/App.elm
>>> Your `main` is demanding an unsupported type as a flag.
>>> 68| main =
>>> ^^^^
>>> The specific unsupported type is:
>>> Dict.Dict
>>> (List Int)
>>> { animation : Material.Ripple.Animation
>>> , ignoringMouseDown : Bool
>>> , metrics :
>>> Maybe
>>> { rect :
>>> { height : Float
>>> , left : Float
>>> , top : Float
>>> , width : Float
>>> }
>>> , x : Float
>>> , y : Float
>>> }
>>> }
>>> The types of values that can flow through in and out of Elm include:
>>> Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, Tuples,
>>> Json.Values,
>>> and concrete records.
>>>
>>>
>>> Currently, I use localStorage to store my AppState partially (I do not
>>> encode 'mdl'). I don't see how I can make this work, however, since I
>>> assume that programWithFlags can only decode the types mentioned in the BAD
>>> FLAGS message and it expects to receive a completely serialized AppState.
>>>
>>> Any suggestions from the coomunity?
>>>
>>> Thanks,
>>> Robert
>>>
>>>
>>>
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.