From ac6ad91d34b1b35acad7c21c8d5a727cb195c1c8 Mon Sep 17 00:00:00 2001 From: Jens Krause Date: Sat, 9 Sep 2017 20:29:10 +0200 Subject: [PATCH] Read server-side state of `CategoryDetail` (#202) from client-side --- .../client/Guide/Client/CategoryDetail-entry.js | 14 +++++--------- front-ps/client/Guide/Client/CategoryDetail.purs | 10 +++++++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/front-ps/client/Guide/Client/CategoryDetail-entry.js b/front-ps/client/Guide/Client/CategoryDetail-entry.js index 99ec428..cc76473 100644 --- a/front-ps/client/Guide/Client/CategoryDetail-entry.js +++ b/front-ps/client/Guide/Client/CategoryDetail-entry.js @@ -1,9 +1,5 @@ -// shared js -import '../../shared.js'; -// client app -var Client = require('./CategoryDetail.purs'); -const app = Client.main(window.location.pathname)(window.__puxLastState || Client.initialState)() - -app.state.subscribe(function (state) { - window.__puxLastState = state; -}); +// shared js sources on client side +import { initClient } from '../../shared.js'; +// init client app +const client = require('./CategoryDetail.purs') +initClient(client); diff --git a/front-ps/client/Guide/Client/CategoryDetail.purs b/front-ps/client/Guide/Client/CategoryDetail.purs index f608eb8..87e0aa4 100644 --- a/front-ps/client/Guide/Client/CategoryDetail.purs +++ b/front-ps/client/Guide/Client/CategoryDetail.purs @@ -7,11 +7,14 @@ import Control.Monad.Eff.Console (CONSOLE, log) import DOM (DOM) import DOM.HTML (window) import DOM.HTML.Types (HISTORY) -import Guide.Common.Types (AppEffects) +import Data.Either (either) +import Data.Foreign (Foreign) import Guide.CategoryDetail.Events (Event(..), foldp) import Guide.CategoryDetail.Routes (match) import Guide.CategoryDetail.State (State, init) import Guide.CategoryDetail.View.Layout (view) +import Guide.Common.Api (decodeJson) +import Guide.Common.Types (AppEffects) import Pux (CoreEffects, App, start) import Pux.DOM.Events (DOMEvent) import Pux.DOM.History (sampleURL) @@ -35,5 +38,6 @@ main url state = do log "Heeeelloooo, here is category-detail page rendered on client-side" pure app -initialState :: State -initialState = init "/" +-- | Used to serialize State from JSON in *-.entry.js +readState :: Foreign -> State +readState json = either (\_ -> init "/") id (decodeJson json)