From 34d3b7e6eceda878985d567dec8f12c3044d3a9e Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 14 Aug 2018 02:44:03 -0400 Subject: [PATCH] Solution for intro/part9 --- intro/part9/src/Session.elm | 38 +++++-------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/intro/part9/src/Session.elm b/intro/part9/src/Session.elm index ea2023a..ee70a0c 100644 --- a/intro/part9/src/Session.elm +++ b/intro/part9/src/Session.elm @@ -72,7 +72,7 @@ login newViewer = Viewer.encode newViewer |> Encode.encode 0 |> Just - |> sendSessionToJavaScript + |> storeSession @@ -81,24 +81,10 @@ login newViewer = logout : Cmd msg logout = - sendSessionToJavaScript Nothing + storeSession Nothing -{-| 👉 TODO 1 of 2: Replace this do-nothing function with a port that sends the -authentication token to JavaScript. - - 💡 HINT 1: When you convert it to a port, the port's name _must_ match - the name JavaScript expects in `intro/server/public/index.html`. - That name is not `sendSessionToJavaScript`, so you will need to - rename it to match what JS expects! - - 💡 HINT 2: After you rename it, some code in this file will break because - it was depending on the old name. Follow the compiler errors to fix them! - --} -sendSessionToJavaScript : Maybe String -> Cmd msg -sendSessionToJavaScript maybeAuthenticationToken = - Cmd.none +port storeSession : Maybe String -> Cmd msg @@ -107,24 +93,10 @@ sendSessionToJavaScript maybeAuthenticationToken = changes : (Session -> msg) -> Nav.Key -> Sub msg changes toMsg key = - receiveSessionFromJavaScript (\val -> toMsg (decode key val)) + onSessionChange (\val -> toMsg (decode key val)) -{-| 👉 TODO 2 of 2: Replace this do-nothing function with a port that receives the -authentication token from JavaScript. - - 💡 HINT 1: When you convert it to a port, the port's name _must_ match - the name JavaScript expects in `intro/server/public/index.html`. - That name is not `receiveSessionFromJavaScript`, so you will need to - rename it to match what JS expects! - - 💡 HINT 2: After you rename it, some code in this file will break because - it was depending on the old name. Follow the compiler errors to fix them! - --} -receiveSessionFromJavaScript : (Value -> msg) -> Sub msg -receiveSessionFromJavaScript toMsg = - Sub.none +port onSessionChange : (Value -> msg) -> Sub msg decode : Nav.Key -> Value -> Session