Skip to content

Instantly share code, notes, and snippets.

@mostalive
Created June 30, 2016 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mostalive/da94d021b9ab8d257c0e2f955dbe4c78 to your computer and use it in GitHub Desktop.
Save mostalive/da94d021b9ab8d257c0e2f955dbe4c78 to your computer and use it in GitHub Desktop.
module Client where
import Prelude (bind, return)
import Pux (App, Config, CoreEffects, start, renderToDOM)
import Control.Bind ((=<<))
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE)
import DOM (DOM)
import Pux.Router (sampleUrl)
import Signal ((~>), Signal)
import Signal.Channel (subscribe)
import State (update)
import State.Types (Action(..), State)
import UReview.Routes (match)
import View.Layout (layout)
import Web.Firebase.Types (FirebaseEff)
-- split into main and config, see pux-starter-app
-- we need an init somewhere that creates a state out of nothing, to be used from JS
-- this should initialize the rootRef and channel, if we want to put it in state
-- a JS caller will (hopefully) not care about the side effects in initialState
config :: forall eff. State -> Eff
( dom :: DOM | eff)
(Config State Action (dom :: DOM, firebase :: FirebaseEff, console :: CONSOLE ))
config state = do
-- | Create a signal of URL changes.
urlSignal <- sampleUrl
-- | Map a signal of URL changes to PageView actions.
let routeSignal = urlSignal ~> \r -> PageView (match r)
let firebaseSignal = subscribe state.channel :: Signal Action
return
{ initialState: state
, update: update
, view: layout
, inputs: [routeSignal, firebaseSignal] }
main :: State -> Eff (CoreEffects (dom :: DOM, firebase :: FirebaseEff, console :: CONSOLE) ) (App State Action)
main state = do
app <- start =<< (config state)
renderToDOM "#app" app.html
-- return for hot reloading from index.js
return app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment