diff --git a/apps/examples/project.json b/apps/examples/project.json index 32fa70d..e9acf27 100644 --- a/apps/examples/project.json +++ b/apps/examples/project.json @@ -13,7 +13,7 @@ "outputPath": "dist/apps/examples", "index": "apps/examples/src/index.html", "main": "apps/examples/src/main.ts", - "polyfills": ["zone.js"], + "polyfills": [], "tsConfig": "apps/examples/tsconfig.app.json", "assets": ["apps/examples/src/favicon.ico", "apps/examples/src/assets"], "styles": ["apps/examples/src/styles.css"], diff --git a/apps/examples/src/app/app.config.ts b/apps/examples/src/app/app.config.ts index ab1802f..35bcda2 100644 --- a/apps/examples/src/app/app.config.ts +++ b/apps/examples/src/app/app.config.ts @@ -1,4 +1,7 @@ -import { ApplicationConfig } from '@angular/core'; +import { + ApplicationConfig, + provideExperimentalZonelessChangeDetection, +} from '@angular/core'; import { provideRouter, withEnabledBlockingInitialNavigation, @@ -10,5 +13,6 @@ export const appConfig: ApplicationConfig = { providers: [ provideRouter(appRoutes, withEnabledBlockingInitialNavigation()), provideHttpClient(), + provideExperimentalZonelessChangeDetection(), ], }; diff --git a/libs/ngx-http-request-state/package.json b/libs/ngx-http-request-state/package.json index beacddf..b781bc9 100644 --- a/libs/ngx-http-request-state/package.json +++ b/libs/ngx-http-request-state/package.json @@ -9,7 +9,7 @@ "loading", "error" ], - "version": "3.3.0", + "version": "3.4.0", "peerDependencies": { "rxjs": "^6.2.0 || ^7.4.0", "@angular/common": "^14.2.10 || ^15.0.1 || ^16.0.0 || ^17.0.0 || ^18.0.0" diff --git a/libs/ngx-http-request-state/src/lib/model.ts b/libs/ngx-http-request-state/src/lib/model.ts index 452d8bc..aeec2ae 100644 --- a/libs/ngx-http-request-state/src/lib/model.ts +++ b/libs/ngx-http-request-state/src/lib/model.ts @@ -1,28 +1,5 @@ import { HttpErrorResponse } from '@angular/common/http'; -/** - * Representation of the state of a data-loading operation. - * - * The various fields are readonly as this is meant to be used to represent an - * immutable snapshot of the current state in a stream of state change events. - */ -export interface HttpRequestState { - /** - * Whether a request is currently in-flight. true for a "loading" state, - * false otherwise. - */ - readonly isLoading: boolean; - /** - * The response data for a "loaded" state, or optionally the last-known data - * (if any) for a "loading" or "error" state. - */ - readonly value?: T; - /** - * The response error (if any) for an "error" state. - */ - readonly error?: HttpErrorResponse | Error; -} - /** * Represents an in-flight HTTP request to load some data. * @@ -32,7 +9,7 @@ export interface HttpRequestState { * UI). * */ -export interface LoadingState extends HttpRequestState { +export interface LoadingState { readonly isLoading: true; readonly value?: T; readonly error: undefined; @@ -56,7 +33,7 @@ export interface LoadingStateWithValue extends LoadingState { * A value may be omitted if there is no data to display and such * a scenario is not considered an error condition. */ -export interface LoadedState extends HttpRequestState { +export interface LoadedState { readonly isLoading: false; readonly value: T; readonly error: undefined; @@ -68,7 +45,7 @@ export interface LoadedState extends HttpRequestState { * * A value may be set to represent a last-known value, or similar. */ -export interface ErrorState extends HttpRequestState { +export interface ErrorState { readonly isLoading: false; readonly value?: T; readonly error: HttpErrorResponse | Error; @@ -85,3 +62,14 @@ export interface ErrorState extends HttpRequestState { export interface ErrorStateWithValue extends ErrorState { readonly value: T; } + +/** + * Representation of the state of a data-loading operation. + * + * The various fields are readonly as this is meant to be used to represent an + * immutable snapshot of the current state in a stream of state change events. + */ +export type HttpRequestState = + | LoadingState + | LoadedState + | ErrorState; diff --git a/libs/ngx-http-request-state/src/lib/type-guards.ts b/libs/ngx-http-request-state/src/lib/type-guards.ts index 5727a6c..a3b42a2 100644 --- a/libs/ngx-http-request-state/src/lib/type-guards.ts +++ b/libs/ngx-http-request-state/src/lib/type-guards.ts @@ -1,24 +1,19 @@ -import { - ErrorState, - HttpRequestState, - LoadedState, - LoadingState, -} from './model'; +import { ErrorState, LoadedState, LoadingState } from './model'; export function isLoadingState( - state?: HttpRequestState + state?: LoadingState | ErrorState | LoadedState ): state is LoadingState { return !!state && state.isLoading; } export function isLoadedState( - state?: HttpRequestState + state?: LoadedState | LoadingState | ErrorState ): state is LoadedState { return !!state && !state.isLoading && !state.error; } export function isErrorState( - state?: HttpRequestState + state?: ErrorState | LoadedState | LoadingState ): state is ErrorState { return !!state && !state.isLoading && !!state.error; }