@@ -70,7 +70,7 @@ main :: IO ()
70
70
main = rasa $ do
71
71
-- some plugins...
72
72
-- Add the new action here!
73
- onInit helloWorld
73
+ helloWorld
74
74
```
75
75
76
76
Okay let's try again! ` stack build && stack exec rasa ` (you may want to alias
@@ -136,26 +136,26 @@ rasa/rasa-example-config/app/Main.hs:28:10: error:
136
136
with actual type ‘Keypress -> Action ()’
137
137
```
138
138
139
- Hrmm, right! Now that we're listening for keypress events we don't want to use
140
- ` onInit ` anymore, Rasa provides a way to register listeners for different events;
141
- we'll learn how to listen for any arbitrary event later; but for now it's time for
142
- ` onKeypress ` !
139
+ Hrmm, right! Now that we're listening for keypress events we need to set up an
140
+ event-listener! Rasa provides a way to register listeners for different events;
141
+ we'll learn how to listen for any arbitrary event later; but for now it's time
142
+ for ` onKeypress ` !
143
143
144
144
``` haskell
145
145
onKeypress :: (Keypress -> Action () ) -> Action ListenerId
146
146
```
147
147
148
148
So we've got our function from our event type (Keypress ), so let's try
149
- registering it using `onKeypress` ; we'll do all of this within `onInit` so the
150
- listener is registered when Rasa starts. The onKeypress function
151
- returns a reference to the newly created listener so that we could cancel the
152
- listener using `removeListener` later if we wanted to; but since we don't need
153
- to do that; we'll just ignore it.
149
+ registering it using `onKeypress` ; The onKeypress function returns a reference
150
+ to the newly created listener so that we could cancel the listener using
151
+ `removeListener` later if we wanted to; but since we don't need to do that;
152
+ we'll just ignore it by using `void` from `Control. Monad `.
154
153
155
154
```haskell
155
+ import Control.Monad
156
156
main = rasa $ do
157
157
-- other extensions
158
- onInit $ onKeypress helloWorld
158
+ void $ onKeypress helloWorld
159
159
```
160
160
161
161
Okay, let's build that and run it, now in a separate terminal we'll run
@@ -213,7 +213,7 @@ import qualified Yi.Rope as Y
213
213
main = rasa $ do
214
214
-- other extensions
215
215
cursors
216
- onInit $ onKeypress copyPasta
216
+ void $ onKeypress copyPasta
217
217
218
218
copyPasta :: Keypress -> Action ()
219
219
copyPasta (Keypress ' y' _) = focusDo_ $ rangeDo_ copier
@@ -504,7 +504,7 @@ newBuf (BufAdded bufRef) = bufDo_ bufRef (addCopyListener copyListener)
504
504
505
505
main = rasa $ do
506
506
-- other extensions
507
- onInit . onBufAdded $ newBuf
507
+ onBufAdded_ $ newBuf
508
508
```
509
509
510
510
Okay so this works; but there was a bit of boiler-plate to get it going!
@@ -599,7 +599,7 @@ newtype Copied = Copied String
599
599
-- We've renamed things so we can export a single 'Action'
600
600
-- that the user can embed in their config.
601
601
copyPasta :: Action ()
602
- copyPasta = onInit $ onKeypress keyListener
602
+ copyPasta = void $ onKeypress keyListener
603
603
604
604
keyListener :: Keypress -> Action ()
605
605
keyListener (Keypress ' y' _) = do
0 commit comments