Home | Hello world | Component | Pursx 1 | Events 1 | Effects | Pursx 2 | Events 2 | Portals | SSR |

Effects

Let's make a network call

This example is similar to the previous one in its design: the looping function is called in response to an event. The difference is that the response isn't immediate. Instead, we wait for the result of a network call.

And here's what it produces:

Arbitrary effects

Because all event listeners execute in the Effect monad, you can do more or less whatever you want. Make a network call, run a monad transformer stack just for fun, play music using purescript-wags. The sky's the limit!

Another useful pattern when working with effects is to throttle input. For example, if we are making a network call, we may want to show a loading indicator and prevent additional network calls. This can be achieved by setting the callback to a no-op while the network call is executing, as shown in the example above.

Next steps

It is also possible to handle events (and by extension effectful actions in events, like network calls) in Pursx. Let's see how in the second Pursx section.