This repository has been archived by the owner on Oct 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |