Skip to content

Commit d70f9de

Browse files
committed
Use the aceConstructor
1 parent 761d1a5 commit d70f9de

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

example/src/Main.purs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import Prelude
44

55
import Ace.Editor as Editor
66
import Ace.EditSession as Session
7-
import Ace.Halogen.Component (AceState (), AceQuery (TextChanged, GetText), initialAceState)
8-
import qualified Ace.Halogen.Component as Ace
7+
import Ace.Halogen.Component (AceState (), AceQuery (TextChanged, GetText), aceConstructor)
98

109
import Control.Monad.Aff (Aff (), runAff)
1110
import Control.Monad.Eff (Eff ())
@@ -23,7 +22,7 @@ import qualified Halogen.HTML.Indexed as H
2322
-- Effects
2423
import Control.Monad.Eff.Random (RANDOM ())
2524
import Control.Monad.Eff.Ref (REF ())
26-
import Ace.Types (ACE ())
25+
import Ace.Types (ACE (), Editor ())
2726
import Data.Date (Now ())
2827

2928

@@ -61,23 +60,18 @@ ui = parentComponent' render eval peek
6160
render :: State -> MainHtml MainAff
6261
render state =
6362
H.div_
64-
[ H.slot AceSlot \_ ->
65-
{ component :
66-
Ace.aceComponent
67-
(\editor -> liftEff $ do
68-
session <- Editor.getSession editor
69-
Session.setMode "ace/mode/yaml" session
70-
Editor.setValue state.text Nothing editor
71-
pure unit
72-
)
73-
Nothing
74-
, initialState :
75-
initialAceState
76-
}
63+
[ H.Slot $ aceConstructor AceSlot (initEditor state) Nothing
7764
, H.div_
7865
[ H.text state.text ]
7966
]
8067

68+
initEditor :: State -> Editor -> MainAff Unit
69+
initEditor state editor = liftEff $ do
70+
session <- Editor.getSession editor
71+
Session.setMode "ace/mode/yaml" session
72+
Editor.setValue state.text Nothing editor
73+
pure unit
74+
8175
eval :: EvalParent Query State AceState Query AceQuery MainAff AceSlot
8276
eval (UpdateText next) = do
8377
pure next

0 commit comments

Comments
 (0)