Skip to content

Commit 3928e4e

Browse files
committed
Something. RUNS. !!!!!!!!!!!!!!!!!!
1 parent 181c0f4 commit 3928e4e

File tree

5 files changed

+78
-4
lines changed

5 files changed

+78
-4
lines changed

DeclarativeGraphics-JS.cabal

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,18 @@ library
1818
exposed-modules: Lib
1919
build-depends: base >= 4.7 && < 5
2020
, jsaddle-dom
21+
, ghcjs-dom
2122
, DeclarativeGraphics
2223
default-language: Haskell2010
2324

25+
executable main
26+
main-is: Main.hs
27+
build-depends: base >=4.2 && <5
28+
, ghcjs-dom
29+
, DeclarativeGraphics-JS
30+
hs-source-dirs: app
31+
ghc-options: -threaded
32+
2433
test-suite DeclarativeGraphics-JS-test
2534
type: exitcode-stdio-1.0
2635
hs-source-dirs: test

app/Main.hs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
module Main where
2+
3+
4+
import Control.Monad.IO.Class (MonadIO(..))
5+
import Control.Concurrent.MVar (takeMVar, putMVar, newEmptyMVar)
6+
7+
import GHCJS.DOM
8+
import GHCJS.DOM.Types
9+
import GHCJS.DOM.Document
10+
import GHCJS.DOM.Element
11+
import GHCJS.DOM.Node
12+
import GHCJS.DOM.EventM
13+
import GHCJS.DOM.GlobalEventHandlers
14+
import GHCJS.DOM.HTMLHyperlinkElementUtils
15+
16+
17+
main :: IO ()
18+
main = liftDOM helloMain
19+
20+
helloMain :: JSM ()
21+
helloMain = do
22+
doc <- currentDocumentUnchecked
23+
body <- getBodyUnchecked doc
24+
setInnerHTML body "<h1>Kia ora (Hi)</h1>"
25+
26+
-- Add a mouse click event handler to the document
27+
_ <- on doc click $ do
28+
(x, y) <- mouseClientXY
29+
newParagraph <- uncheckedCastTo HTMLParagraphElement <$> createElement doc "p"
30+
text <- createTextNode doc $ "Click " ++ show (x, y)
31+
appendChild_ newParagraph text
32+
appendChild_ body newParagraph
33+
34+
-- Make an exit link
35+
exitMVar <- liftIO newEmptyMVar
36+
exit <- uncheckedCastTo HTMLAnchorElement <$> createElement doc "a"
37+
text <- createTextNode doc "Click here to exit"
38+
appendChild_ exit text
39+
appendChild_ body exit
40+
41+
-- Set an href for the link, but use preventDefault to stop it working
42+
-- (demonstraights synchronous callbacks into haskell, as preventDefault
43+
-- must be called inside the JavaScript event handler function).
44+
setHref exit "https://github.com/ghcjs/ghcjs-dom-hello"
45+
_ <- on exit click $ preventDefault >> liftIO (putMVar exitMVar ())
46+
47+
-- Force all all the lazy JSaddle evaluation to be executed
48+
syncPoint
49+
50+
-- Wait until the user clicks exit.
51+
liftIO $ takeMVar exitMVar
52+
setInnerHTML body "<h1>Ka kite ano (See you later)</h1>"

stack.yaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@
1515
# resolver:
1616
# name: custom-snapshot
1717
# location: "./custom-snapshot.yaml"
18-
resolver: lts-8.22
18+
resolver: lts-7.19
19+
compiler: ghcjs-0.2.1.9007019_ghc-8.0.1 # ghcjs wohoo
20+
compiler-check: match-exact
21+
22+
setup-info:
23+
ghcjs:
24+
source:
25+
ghcjs-0.2.1.9007019_ghc-8.0.1:
26+
url: http://ghcjs.tolysz.org/ghc-8.0-2017-02-05-lts-7.19-9007019.tar.gz
27+
sha1: d2cfc25f9cda32a25a87d9af68891b2186ee52f9
1928

2029
# User packages to be built.
2130
# Various formats can be used as shown in the example below.
@@ -41,7 +50,11 @@ packages:
4150

4251
# Dependency packages to be pulled from upstream that are not in the resolver
4352
# (e.g., acme-missiles-0.3)
44-
extra-deps: []
53+
extra-deps:
54+
- jsaddle-0.9.0.0
55+
- jsaddle-dom-0.9.0.0
56+
- ghcjs-dom-0.9.1.1
57+
- ghcjs-dom-jsffi-0.9.1.1
4558

4659
# Override default flag values for local packages and extra-deps
4760
flags: {}

test/Spec.hs

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/Test.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main :: IO ()
2+
main = putStrLn "test"

0 commit comments

Comments
 (0)