on develop help sign in
Merge pull request #137 from dalaing/quickref-updates

Adjusts Quickref.md to reflect recent changes

commite610225d98a7fd4a0e5d5732b924b989ab0b8271 authorRyan Trinkle <ryan.trinkle@gmail.com> dateMon 30 Oct 2017, 22:19 (9 years ago) parent36db89484a9606
1 file changed+102−1
Quickref.md+102−1
Quickref.md+102−1
@@ -13,7 +13,6 @@ Some of these functions are *pure*: They operate on Events, Behaviors, or Dynam
1313[S] -- Function runs in any monad supporting MonadSample
1414[H] -- Function runs in any monad supporting MonadHold
1515```
16−
1716Since MonadHold depends on MonadSample, any [S] function also runs in [H] context.
1817
1918## Functions producing Event
@@ -46,6 +45,8 @@ Since MonadHold depends on MonadSample, any [S] function also runs in [H] contex
4645[ ] attachPromptlyDynWith :: (a -> b -> c) -> Dynamic a -> Event b -> Event c
4746[ ] attachWithMaybe :: (a -> b -> Maybe c) -> Behavior a -> Event b -> Event c
4847[ ] attachPromptlyDynWithMaybe :: (a -> b -> Maybe c) -> Dynamic a -> Event b -> Event c
48+[ ] <@> :: Behavior (a -> b) -> Event a -> Event b
49+[ ] <@ :: Behavior b -> Event a -> Event b
4950
5051-- Combine multiple Events
5152[ ] <> :: Semigroup a => Event a -> Event a -> Event a
@@ -181,3 +182,103 @@ For Events, the returned Event fires whenever the latest Event supplied by the w
181182-- At switchover, the output Event immediately tracks the new Event.
182183[H] switchPromptly :: Event a -> Event (Event a) -> m (Event a)
183184```
185+
186+## Typeclasses to introspect and modify an FRP network.
187+
188+The functions mentioned above are used to create a static FRP network.
189+There are additional typeclasses that can be used to modify the FRP network, to have it interact with IO action, or to introspect the building of the network.
190+
191+Th typeclasses and their associated annotations include:
192+
193+- `PostBuild`
194+ Fire an Event when an FRP network has been set up.
195+ ```haskell
196+ [B] -- Function runs in any monad supporting PostBuild
197+ ```
198+
199+- `Adjustable`
200+ Use Events to add or remove pieces of an FRP network.
201+ ```haskell
202+ [A] -- Function runs in any monad supporting Adjustable
203+ ```
204+
205+- `TriggerEvent`
206+ Create new externally-fired Events from within an FRP network.
207+ ```haskell
208+ [T] -- Function runs in any monad supporting TriggerEvent
209+ ```
210+
211+- `PerformEvent`
212+ Use Events to trigger IO actions and to collect their results.
213+ ```haskell
214+ [P] -- Function runs in any monad supporting PerformEvent
215+ ```
216+
217+## Startup
218+
219+```haskell
220+-- One-shot Event that is triggered once the FRP network has been built
221+[B] getPostBuild :: m (Event ())
222+```
223+
224+## Collection management functions
225+
226+```haskell
227+-- Turn a Dynamic key/value map into a set of dynamically-changing widgets.
228+[H,A,B] listWithKey :: Ord k =>
229+ Dynamic (Map k v) -> (k -> Dynamic v -> m a ) -> m (Dynamic (Map k a))
230+
231+-- Same as above where the widget constructor doesn't care about the key.
232+[H,A,B] list :: Ord k =>
233+ Dynamic (Map k v) -> ( Dynamic v -> m a ) -> m (Dynamic (Map k a))
234+
235+-- Even simpler version where there are no keys and we just use a list.
236+[H,A,B] simpleList ::
237+ Dynamic [v] -> ( Dynamic v -> m a ) -> m (Dynamic [a])
238+
239+-- Like listWithKey specialized for widgets returning (Event a).
240+[H,A,B] listViewWithKey :: Ord k =>
241+ Dynamic (Map k v) -> (k -> Dynamic v -> m (Event a)) -> m (Event (Map k a))
242+
243+-- Create a dynamically-changing set of widgets, one of which is selected at any time.
244+[H,A,B] selectViewListWithKey_ :: Ord k => Dynamic k ->
245+ Dynamic (Map k v) -> (k -> Dynamic v -> Dynamic Bool -> m (Event a)) -> m (Event k)
246+
247+-- Same as listWithKey, but takes initial values and an updates Event instead of a Dynamic.
248+[H,A,B] listWithKey' :: Ord k =>
249+ Map k v -> Event (Map k (Maybe v)) -> (k -> v -> Event v -> m a) -> m (Dynamic (Map k a))
250+```
251+
252+## Creating new events from within an FRP network.
253+
254+```haskell
255+-- Create a new Event and a function that will cause the Event to fire, from within an FRP network
256+[T] newTriggerEvent :: m (Event a, a -> IO ())
257+```
258+
259+## Connecting to the real world (I/O)
260+
261+```haskell
262+-- Run side-effecting actions in Event when it occurs; returned Event contains
263+-- results. Side effects run in the (Performable m) monad which is associated with
264+-- the (PerformEvent t m) typeclass constraint.
265+-- This allows for working with IO when a ((MonadIO (Performable m)) constraint is available.
266+[P] performEvent :: Event (Performable m a ) -> m (Event a)
267+
268+-- Just run side-effects; no return Event
269+[P] performEvent_ :: Event (Performable m ()) -> m ()
270+
271+-- Actions run asynchronously; actions are given a callback to send return values
272+[P,T] performEventAsync :: Event ((a -> IO ()) -> Performable m ()) -> m (Event a)
273+```
274+
275+### Time
276+
277+```haskell
278+-- Create Event at given interval with given basis time.
279+[P,T] tickLossy :: NominalDiffTime -> UTCTime -> m (Event t TickInfo)
280+
281+-- Delay an Event's occurrences by a given amount in seconds.
282+[P,T] delay :: NominalDiffTime -> Event t a -> m (Event t a)
283+```
284+