ember-async-data
Advanced tools
Changelog
[v0.5.0] (2021-06-01)
Changelog
[v0.4.0] (2021-05-13)
@ember/test-waiters
is now a direct dependency as it's used by app code.
Changelog
[v0.3.0] (2021-04-12)
Following on from 0.2.0's support for narrowing with .isPending
, .isResolved
, and .isRejected
, TrackedAsyncData
instances cab now be "narrowed" by checking the .state
property ([#6]):
import TrackedAsyncData from 'ember-async-data/tracked-async-data';
let data = new TrackedAsyncData(Promise.resolve('string'));
switch (data.state) {
case 'PENDING';
data.value; // null (and a warning for accessing in an invalid state!)
data.error; // null (and a warning for accessing in an invalid state!)
break;
case 'RESOLVED':
data.value; // string
data.error; // null (and a warning for accessing in an invalid state!)
break;
case 'REJECTED':
data.value; // null (and a warning for accessing in an invalid state!)
data.error; // unknown
break;
default:
break;
}
Decorated .state
with @dependentKeyCompat
so it can be used as a dependent key with classic computed properties.
Changelog
[v0.2.0] (2021-03-27)
This is a wholly backwards-compatible change, which just adds one new feature and improves some docs.
TrackedAsyncData
now has the ability to use TypeScript’s type-narrowing functionality via the .isPending
, .isResolved
, and .isRejected
([#2]) checks:
import TrackedAsyncData from 'ember-async-data/tracked-async-data';
let data = new TrackedAsyncData(Promise.resolve('string'));
if (data.isPending) {
data.value; // null (and a warning for accessing in an invalid state!)
data.error; // null (and a warning for accessing in an invalid state!)
} else if (data.isResolved) {
data.value; // string
data.error; // null (and a warning for accessing in an invalid state!)
} else if (data.isRejected) {
data.value; // null (and a warning for accessing in an invalid state!)
data.error; // unknown
}
(Remember that the null
fallbacks for .value
and .error
will be removed in a future version which drops support for Ember Classic computed properties.)