Skip to content

Commit 5a9efd8

Browse files
committed
example/app: update example with references
1 parent b4d01ee commit 5a9efd8

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

example/app/app.purs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
module Main where
22

3+
import Control.Monad.Eff
34
import Debug.Trace
45
import React
56
import qualified React.DOM as DOM
67

8+
foreign import interval
9+
"function interval(ms) { \
10+
\ return function(action) { \
11+
\ return function() { return setInterval(action, ms); } \
12+
\ } \
13+
\}"
14+
:: forall eff r. Number -> Eff (trace :: Trace) r -> Eff (eff) {}
15+
716
helloInConsole = do
817
props <- getProps
918
trace ("Hello, " ++ props.name ++ "!")
@@ -22,7 +31,14 @@ incrementCounter = do
2231
val <- readState
2332
writeState (val + 1)
2433

25-
counter = mkUI spec { getInitialState = return 0 } do
34+
counter = mkUI spec {
35+
getInitialState = return 0,
36+
componentDidMount = do
37+
self <- getSelf
38+
interval 1000 $ runUI self do
39+
val <- readState
40+
print val
41+
} do
2642
val <- readState
2743
return $ DOM.p {
2844
className: "Counter",

0 commit comments

Comments
 (0)