-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMain.purs
More file actions
73 lines (57 loc) · 1.67 KB
/
Copy pathMain.purs
File metadata and controls
73 lines (57 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
module Main where
import Prelude
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import Data.Maybe (Maybe(..))
import Halogen as H
import Halogen.Aff as HA
import Halogen.HTML as HH
import Halogen.HTML.Events as HE
import Halogen.VDom.Driver (runUI)
import Ace.Editor as Editor
import Ace.EditSession as Session
import Ace.Halogen.Component (AceQuery, AceMessage(..), aceComponent)
import Ace.Types (Editor)
data Query a
= HandleMessage AceMessage a
type State =
{ text ∷ String
}
initialState ∷ State
initialState =
{ text : "Name: Ace Editor"
}
type AceSlot = Unit
type MainHtml = H.ParentHTML Query AceQuery AceSlot Aff
type MainDSL = H.ParentDSL State Query AceQuery AceSlot Void Aff
ui ∷ H.Component HH.HTML Query Unit Void Aff
ui =
H.parentComponent
{ initialState: const initialState
, render
, eval
, receiver: const Nothing
}
where
render ∷ State → MainHtml
render state =
HH.div_
[ HH.slot unit (component state) unit (HE.input HandleMessage)
, HH.div_ [ HH.text state.text ]
]
component :: State → H.Component HH.HTML AceQuery Unit AceMessage Aff
component state = aceComponent (initEditor state) Nothing
initEditor ∷ State → Editor → Aff Unit
initEditor state editor = liftEffect $ do
session ← Editor.getSession editor
Session.setMode "ace/mode/yaml" session
_ ← Editor.setValue state.text Nothing editor
pure unit
eval ∷ Query ~> MainDSL
eval = case _ of
HandleMessage (TextChanged text) next → do
_ <- H.modify (_ { text = text })
pure next
main ∷ Effect Unit
main = HA.runHalogenAff (runUI ui unit =<< HA.awaitBody)