Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Association decorators should return async promise #2148

Open
hudson-newey opened this issue Oct 14, 2024 · 0 comments
Open

Association decorators should return async promise #2148

hudson-newey opened this issue Oct 14, 2024 · 0 comments
Labels
architecture Architectural changes to the software enhancement New feature or request

Comments

@hudson-newey
Copy link
Member

hudson-newey commented Oct 14, 2024

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.

@hudson-newey hudson-newey added enhancement New feature or request architecture Architectural changes to the software labels Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
architecture Architectural changes to the software enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant