QutEcoacoustics / workbench-client

workbench-client: a client side browser application for interacting with acoustic workbenches
Other
8 stars 1 forks source link

Association decorators should return async promise #2148

Open hudson-newey opened 1 month ago

hudson-newey commented 1 month ago

At the moment our association decorators return an UnresolvedModel, while the API request is pending.

This has typically not been a problem when using model information inside the angular template, because it will re-render when the model gets resolved.

However, if you want to use an associated model and chain it to another api request, or extract a value (not in the template), you will not be able to use the associated model as it will be an UnresolvedModel.

To fix this, the association decorators should return a promise that we can await while fetching results.

e.g. It would be really nice to do something like

const sites = await project.sites;
const siteNames = sites.map((site) => site.name);

Using an UnresovledModel also subverts the TypeScript type checking, meaning that we will not get a warning if the request is still pending.