v6.0.0
Migration
- If you come from
v5.0.0
you probably don't have to do anything. - If you come from
v3.1.0
it's recommended to first install v5.0.0, which is a transitional release that marks old APIs as deprecated. After migrating all deprecations you can safely installv6
.
In this release
- Added
chain()
API. (docs)
Breaking changes
- Removed all APIs that were marked as deprecated and replaced by new ones:
Old API | New API |
---|---|
RemoteDataTags |
- |
AnyRemoteData |
RemoteData<any, any> |
NotAsked.of() |
notAsked() |
InProgress.of() |
inProgress() |
Failure.of() |
failure() |
Success.of() |
success() |
InProgress::value() |
InProgress::value |
Failure::value() |
Failure::value |
Failure::error() |
Failure::error |
Success::value() |
Success::value |
- All
RemoteData
variants are plain JavaScript objects, so you won't be able to useinstanceof
to discriminate between them. Use the type guards or folds instead:
Type guards
type User = { email: string };
const myRemoteData: RemoteData<User> = failure('Something went wrong.', {
email: '[email protected]'
});
// (...)
if (isFailure(myRemoteData)) {
// Here myRemoteData is narrowed to Failure
console.log(`This is the failure: ${myRemoteData.error}`);
console.log(`I have some data: ${myRemoteData.value.email}`);
}
Fold
const rd = success('this is fine!');
const result = fold(
() => 'not asked',
val => 'in progress: ' + val,
(error, value) => `failure: ${error} ${value}`,
value => 'success: ' + value,
rd
);
console.log(result); // success: this is fine!
- If you were using the custom
localStorageSyncReducer
reducer to persist / rehydrate the store now it is not needed anymore, you can use the library without any hacks. Check the ngrx example in the demo app.