On Friday, September 16, 2016 at 1:32:06 AM UTC+1, art yerkes wrote:
>
> If your login page can send a message to a parent frame, you can use
> Dom.LowLevel.onWindow to receive it in elm. This appeared in 0.17 and is
> neat.
>
The other part that I am trying to get my head around, is where to put the
current auth state. At the moment I just have one field, token : String,
that holds the logged in state. When the token is set, the application
assumes it is logged in.
How do I put this state somewhere that it can be modified from any
sub-module within the application?
I defined a model for it in the auth module, and hold that state in the
top-level model. When an event that needs to modify that state is fired, it
is mapped to the Auth module, and the resulting state lifted back onto the
top-level model.
LogOut ->
( model, Auth.State.logout |> Cmd.map AuthMsg )
AuthMsg a ->
lift .auth (\m x -> { m | auth = x }) AuthMsg Auth.State.update
a model
This works nicely for the top-level -> Auth interaction, but I also want
interaction from other modules accross to the Auth module.
I ended up doing something clunky to try and get this working:
WelcomeMsg a ->
case a of
Welcome.Types.AuthMsg b ->
lift .welcome (\m x -> { m | welcome = x, auth = x.auth
}) WelcomeMsg Welcome.State.update a model
_ ->
lift .welcome (\m x -> { m | welcome = x }) WelcomeMsg
Welcome.State.update a model
Here, an even on the welcome page that relates to auth (login) is picked
up, and the auth state lifted from the welcome model onto the top-level
model. Doesn't feel right to me, just what I ended up hacking out in
desperation.
Is Dom.LowLevel.onWindow the way to route events back from modules to the
top-level? Then I can route the login event from the welcome page -> top
level -> auth module.
--
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.