Skip to content
This repository has been archived by the owner on Oct 23, 2019. It is now read-only.

Commit

Permalink
[more counter examples]
Browse files Browse the repository at this point in the history
  • Loading branch information
fisx committed Jan 4, 2016
1 parent 12f110d commit bf3c403
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
45 changes: 45 additions & 0 deletions thentos-purescript/src/Broken0.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- build like this:
-- pulp browserify -m Broken0.purs --to ../static/thentos.js
module Broken0 where

import Control.Monad.Aff.Class (MonadAff)
import Control.Monad.Aff (Aff())
import Data.Maybe
import DOM.HTML.Types (HTMLElement())
import Halogen (Component(), ComponentHTML(), ComponentDSL(), HalogenEffects(), Natural(), runUI, component, modify)
import Network.HTTP.Affjax (AJAX(), AffjaxResponse(), affjax, defaultRequest)
import Prelude

import qualified Data.ArrayBuffer.Types as AB
import qualified Halogen.HTML.Indexed as H
import qualified Halogen.Query as Q

type Effs eff = HalogenEffects (ajax :: AJAX | eff)

type State = { stCaptchaQ :: Maybe (AffjaxResponse AB.ArrayBuffer) }

data Query a = NewCaptchaReceived (AffjaxResponse AB.ArrayBuffer) a

initialState :: State
initialState = { stCaptchaQ: Nothing }

render :: State -> ComponentHTML Query
render st = H.div_ []

-- fetchCaptcha :: forall eff. Natural Query (Aff (Effs eff)) -> Aff (Effs eff) Unit
fetchCaptcha driver = do
response <- affjax defaultRequest
driver (Q.action (NewCaptchaReceived response))

eval :: forall eff g. (MonadAff (Effs eff) g) => Natural Query (ComponentDSL State Query g)
eval e@(NewCaptchaReceived resp next) = do
modify (_ { stCaptchaQ = Just resp })
pure next

ui :: forall eff g. (MonadAff (Effs eff) g) => Component State Query g
ui = component render eval

main' :: forall eff a. (HTMLElement -> Aff (Effs eff) a) -> Aff (Effs eff) Unit
main' addToDOM = do
{ node: node, driver: driver } <- runUI ui initialState
fetchCaptcha driver
26 changes: 26 additions & 0 deletions thentos-purescript/src/Broken1.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- build like this:
-- pulp browserify -m Broken1.purs --to ../static/thentos.js
module Broken1 where

import Control.Monad.Aff.Class (MonadAff)
import Control.Monad.Aff (Aff())
import DOM.HTML.Types (HTMLElement())
import Halogen (Component(), HalogenEffects(), Natural(), runUI, component)
import Prelude

import qualified Halogen.HTML.Indexed as H

data State = State
data Query a = Query a

ui :: forall eff g. (MonadAff (HalogenEffects eff) g) => Component State Query g
ui = component (\_ -> H.div_ []) (\(Query next) -> pure next)

main' :: forall eff a. (HTMLElement -> Aff (HalogenEffects eff) a) -> Aff (HalogenEffects eff) Unit
main' addToDOM = do
{ node: node, driver: driver } <- runUI ui State

let driver' :: Natural Query (Aff (HalogenEffects eff))
driver' = driver

return unit

0 comments on commit bf3c403

Please sign in to comment.