You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/events.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ type Application model message = {
17
17
}
18
18
```
19
19
20
-
is the `update` function. This is where we define our business logic by matching event `message`s and returning an updated model. So far we have been using the `Update` type alias. Let's expand it:
20
+
is the `update` function. So far we have been using the `Update` type alias. Let's expand it:
21
21
22
22
```haskell
23
23
typeApplicationmodelmessage= {
@@ -28,7 +28,7 @@ type Application model message = {
28
28
}
29
29
```
30
30
31
-
Besides the updated model, `update`also returns an array of side effects to perform. Each entry in the array may optionally raise another `message`, which in turn is handled by `update` as well.
31
+
That means that `update` returns an updated model but also an array of side effects to perform. Each entry in the array may optionally raise another `message`, which is in turn handled by `update` as well.
32
32
33
33
Consider an application to roll dices
34
34
@@ -54,7 +54,7 @@ view model = HE.main "main" [
54
54
55
55
`Roll` returns the model as it is. However, generating random numbers is a side effect so we return it on our array. Flame will run this effect and raise `Update`, which then updates the model with the die number.
56
56
57
-
Likewise, we could define a loading screen to appear before AJAX requests
57
+
Likewise, we could perform some network requests with a loading screen
Here for `Loading`, we return an array of network calls and a final `Finish` message. The effects are run in order, and once we have a response, their events are raised for `update` as well.
103
+
Here for `Perform`, we return an array of network calls and a final `Finish` message. The effects are run in order, and once we have a response their events are raised for `update` as well.
104
104
105
105
You may be wondering: why separate model updating and side effects? The reason is that in this way we are "forced" to keep most of our business logic in pure functions, which are easier to reason and test. Effects become interchangeable, decoupled from what we do with their results.
106
106
@@ -135,7 +135,7 @@ Once a subscription has been defined, the raised `message` will be handled by th
135
135
136
136
*Arbitrary message passing
137
137
138
-
Sometimes, we need to talk to an application from external events handlers or other points in the code away from the mount point.Consider an app that uses web sockets, or a singe page application that uses multiple mount points for lazy loading, or just simple initialization events.For these and other use cases, Flame provides a `mount` (no trailing underscore) function that takes an application id, as well a `send` function to raise messages for application ids
138
+
Sometimes, we need to talk to an application from external events handlers or other points in the code away from the mount point.Consider an app that uses web sockets, or a singe page application that uses multiple mount points for lazy loading, or just some initialization events.For these and other use cases, Flame provides a `mount` (no trailing underscore) function that takes an application id, as well a `send` function to raise messages for application ids
whose events can be handled with `onCustomEven` on your `subscribe` list.Broadcasting events is considered unsafe, as it is user code responsibility to make sure all listeners expect the same `message` payload.
202
+
whose events can be handled with `onCustomEvent` on your `subscribe` list.Broadcasting events is considered unsafe as it is user code responsibility to make sure all listeners expect the same `message` payload.
203
203
204
204
See the [API reference](https://pursuit.purescript.org/packages/purescript-flame) for a complete list of built-in external events.See this [test application](https://github.com/easafe/purescript-flame/tree/master/examples/Subscriptions) for a full example of subscriptions.
0 commit comments