Skip to content

Commit 945044c

Browse files
committed
Update the text below the ace component with the current text
To show how one can listen to updates in the ace component
1 parent 9ed07ec commit 945044c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

example/src/Main.purs

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

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

1010
import Control.Monad.Aff (Aff (), runAff)
@@ -14,7 +14,7 @@ import Control.Monad.Eff.Exception (throwException)
1414
import Control.Plus (Plus)
1515

1616
import Data.Functor.Coproduct (Coproduct())
17-
import Data.Maybe (Maybe (..))
17+
import Data.Maybe (Maybe (..), fromMaybe)
1818

1919
import Halogen
2020
import Halogen.Util (appendToBody, onLoad)
@@ -55,7 +55,7 @@ type MainEffects = HalogenEffects (random :: RANDOM, now :: Now, ref :: REF, ace
5555
type MainAff = Aff MainEffects
5656

5757
ui :: Component (StateP MainAff) QueryP MainAff
58-
ui = parentComponent render eval
58+
ui = parentComponent' render eval peek
5959
where
6060

6161
render :: State -> MainHtml MainAff
@@ -82,6 +82,16 @@ ui = parentComponent render eval
8282
eval (UpdateText next) = do
8383
pure next
8484

85+
peek :: Peek (ChildF AceSlot AceQuery) State AceState Query AceQuery MainAff AceSlot
86+
peek (ChildF p q) =
87+
case q of
88+
TextChanged _ -> do
89+
text <- query AceSlot $ request GetText
90+
modify (_ { text = fromMaybe "" text })
91+
pure unit
92+
_ ->
93+
pure unit
94+
8595
main :: Eff MainEffects Unit
8696
main = runAff throwException (const (pure unit)) $ do
8797
app <- runUI ui (installedState initialState)

0 commit comments

Comments
 (0)