Side Effects
Curi side effects are permanent router response handlers that are run after those registered using router.observe
and router.once
.
Whenever a new response is generated, all of the side effect functions will be called. They will be given an object with the new response
object, a navigation
object with some extra routing data (the navigation action the previous response), and the router
object.
Adding Side Effects
Side effects are provided to your router with the sideEffects
property of the options object. This is an array of observer functions.
Side effects are always run after observers registered using router.observe
and router.once
. Because those forms of response handler registration are primarily used for rendering the application, this means that the side effects will be called after the application has re-rendered.
@curi/side-effects
Curi's @curi/router
package provides three side effects:
Creating Side Effects
When creating your own side effect, you can write a regular function or a side effect "factory".
A side effect factory lets create a more customizable side effect.
You may want to review the response properties to know which properties you should expect a response to have.