-
Notifications
You must be signed in to change notification settings - Fork 37
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
Change the implementation of trackedFunction
such that loading/error state are revealed
#363
Comments
Better yet, just use and re-export |
v2 addon soon? |
I would happily review and merge a PR converting it! I just don't have time right now to tackle that myself! |
excellent :D I'm still trying to figure out how to properly wrangle TS + Rollup + addon-dev tho 😅 Link fof reference: https://github.com/chriskrycho/ember-async-data |
Just want to confirm that this would allow me to easily test a component doing API request with new{{#if this.dataset.isPending}}
<LoadingIndicator data-test-loading-indicator />
{{else}}
{{this.dataset.value}}
{{/if}} existing{{#if this.dataset.value}}
{{this.dataset.value}}
{{else}}
<LoadingIndicator data-test-loading-indicator />
{{/if}} test test(
'it displays a loading indicator while the dataset is loading',
async function (assert) {
this.server.timing = 5000; // exaggerated for observability
await render(hbs`<DatasetInfo />`);
assert
.dom('[data-test-loading-indicator]')
.exists('should render the loading indicator at component render');
}
); With the current approach the test waits for the whole 5000ms before running the assertion. |
It would, except i wan only considering this change for |
(I'm on 3.2.1) How would you represent that there is an async operation to the user? I'm curious if the behavior of It looks like the proper way of doing this is to rely on a Resource / useResource and have internal state. Would you agree? I guess I could do this: {{#if this.isLoading}}
<LoadingIndicator />
{{/if}}
{{#if this.dataset.value}}
{{this.dataset.value}}
{{/if}} @tracked isLoading = true;
useFunction(() => {
const response = await fetch(`/characters/`) ;
this.isLoading = false;
return response;
}) but I have the impression that changing component tracked properties like this is not what one would want to do. |
correct, this is a side effect, which can be pretty spooky beyond simple examples. and, this is also why resources and derived state are such good patterns for encapsulating this kind of state.
the way you were doing previously is sufficient for most cases.
yeah, most of what I like using those abstractions for is for building other resources that are nicer in actual app code.
|
🎉 This issue has been resolved in version 4.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Gonna copy @chriskrycho's https://v5.chriskrycho.com/journal/async-data-and-autotracking-in-ember-octane/
(but without the assertions for now, cause that's a breaking change).
userland API would be the same as
trackedFunction
is today, but in addition to.value
, there would be.isPending
,.isError
and.error
properties addedThe text was updated successfully, but these errors were encountered: