1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-24 21:35:06 +03:00

Read server-side state of CategoryDetail (#202)

from client-side
This commit is contained in:
Jens Krause 2017-09-09 20:29:10 +02:00
parent 72d53a7ce0
commit ac6ad91d34
No known key found for this signature in database
GPG Key ID: 3B2FAFBCEFA5906D
2 changed files with 12 additions and 12 deletions

View File

@ -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);

View File

@ -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)