Store Features
Generates necessary state, computed and methods for call progress status but map by a key, allowing to implement calls of the same type that run on parallel each with its own status
Kind: global function
Import the withCallStatus trait from @ngrx-traits/signals
.
import { withCallStatusMap } from '@ngrx-traits/signals';
Use this when the you need a special way to call you backend that is not handle by withEntitiesCall
const store = signalStore(withCallStatusMap());
const orderEntity = entityConfig({
entity: type<OrderSummary & { items?: OrderDetail['items'] }>(),
collection: 'orders',
});
export const ProductsRemoteStore = signalStore(
{ providedIn: 'root' },
withEntities(orderEntity),
withCallStatusMap({ prop: 'loadDetails' }),
withMethods((store) => ({
loadProducts: rxMethod<{ orderId: string }>(
pipe(
switchMap((params) => {
store.setLoadDetailsLoading(params.orderId);
return inject(OrderService)
.getOrderDetail(params.orderId)
.pipe(
tap((res) =>
patchState(
store,
updateEntity(
{
id: params.orderId,
changes: { items: res.items },
},
orderEntity,
),
),
),
catchError((error) => {
store.setLoadDetailsError(params.orderId, error);
return EMPTY;
}),
);
}),
),
),
})),
);
This trait receives an object to allow specific configurations:
Property | Description | Value |
---|---|---|
prop | The name of the property for which this represents the call status. | string |
initialValue | The initial value of the call status. Record<string | number, CallStatus> |
errorType | The type of the error | T |
Generates the following signals, with prop = test
testCallStatus: Record<string | number, CallStatus>;
Generates the following computed signals
areAllTestLoaded: Signal<boolean>
isAnyTestLoading: Signal<boolean>
testErrors: Signal<Error[]>
Generates the following methods
isTestLoading: (id: string) => boolean;
isTestLoaded: (id: string) => boolean;
testError: (id: string) => Error | undefined;
setTestLoaded: (id: string) => void;
setTestLoading: (id: string) => void;
setTestError: (id: string, error?: unknown) => void;