Comment on page
Async handling
ConanJs gives you a few mechanisms to announce within your actions that you are performing asynchronous operations.
These are the benefits:
- NO boiler plate code to update your state asynchronously.
- Automatically updates the Monitor Thread to reflect all the async operations running and their details. Allowing you to subscribe to these updates, to easily add loading screens, block buttons etc.
Check our Todos - Async for an example without boiler plate code and which displays the status of the async operations
- Allows accessing the underlying ASAPs running at the moment. Note this combined with the ASAPs being cancellable, makes complex scenarios like optimistic updates much simpler
There are two mechanisms to declare async actions: auto-bind and monitor actions.
When you describe your actions, you can access the monitor from the provided thread and the framework will update the Monitor Async thread all the way through the life cycle of the ASAP
return thread.monitor(
//An Asap
diContext.issuesService.fetch(repo, org, page).catch(() => thread.reducers.$fetch([])),
//What to do when the asap resolves
(issues, reducers) => reducers.$fetch(issues as Issue[]),
//Next two params are for logging purposes
// - Description of the async operation
'fetch',
// - Payload (also shown on the logging)
[repo, org, page]
)