Skip to content

Commit

Permalink
refactor: made entity required, removing some unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Guerrero authored and gabrielguerrero committed Apr 29, 2024
1 parent f89f504 commit c6b5b8c
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { ProductsShopStore } from '../../products-shop.store';
(sort)="sortBasket($event)"
></product-basket>
</mat-card-content>
<mat-card-actions [align]="'end'">
<mat-card-actions class="flex gap-4" [align]="'end'">
<button
mat-stroked-button
color="primary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { RouterLink } from '@angular/router';
<mat-list-item [routerLink]="'products-shop'" style="height: 90px;">
<div matListItemTitle>
<b
>Complex example using multi collections and most of the store
>Complex example using two collections and most of the store
features</b
>
</div>
Expand Down
23 changes: 5 additions & 18 deletions libs/ngrx-traits/signals/src/lib/with-calls/with-calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,9 @@ export function withCalls<
(state, environmentInjector = inject(EnvironmentInjector)) => {
const methods = Object.entries(calls).reduce(
(acc, [callName, call]) => {
const {
callStatusKey,
setLoadingKey,
setLoadedKey,
setErrorKey,
} = getWithCallStatusKeys({ prop: callName });
const { callStatusKey } = getWithCallStatusKeys({
prop: callName,
});
const { resultPropKey, callNameKey } = getWithCallKeys({
callName,
resultProp: isCallConfig(call)
Expand All @@ -186,6 +183,7 @@ export function withCalls<
isCallConfig(call) && call.mapPipe
? mapPipes[call.mapPipe]
: exhaustMap;

const setLoading = () =>
patchState(store, {
[callStatusKey]: 'loading',
Expand All @@ -198,18 +196,7 @@ export function withCalls<
patchState(store, {
[callStatusKey]: { error },
} as any);
acc[setLoadingKey] = () =>
patchState(store, {
[callStatusKey]: 'loading',
} as any);
acc[setLoadedKey] = () =>
patchState(store, {
[callStatusKey]: 'loaded',
} as any);
acc[setErrorKey] = (error?: unknown) =>
patchState(store, {
[callStatusKey]: { error },
} as any);

acc[callNameKey] = rxMethod<unknown[]>(
pipe(
mapPipe((params) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function getWithEntitiesFilterKeys(config?: { collection?: string }) {
};
}

export function debounceFilterPipe<Filter, Entity>(
export function debounceFilterPipe<Filter>(
filter: Signal<Filter>,
defaultDebounce = 300,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function withEntitiesLocalFilter<
filterFn: (entity: Entity, filter?: Filter) => boolean;
defaultFilter: Filter;
defaultDebounce?: number;
entity?: Entity;
entity: Entity;
}): SignalStoreFeature<
{
state: EntityState<Entity>;
Expand Down Expand Up @@ -143,7 +143,7 @@ export function withEntitiesLocalFilter<
filterFn: (entity: Entity, filter?: Filter) => boolean;
defaultFilter: Filter;
defaultDebounce?: number;
entity?: Entity;
entity: Entity;
collection?: Collection;
}): SignalStoreFeature<
// TODO: we have a problem with the state property, when set to any
Expand Down Expand Up @@ -175,7 +175,7 @@ export function withEntitiesLocalFilter<
filterFn: (entity: Entity, filter?: Filter) => boolean;
defaultFilter: Filter;
defaultDebounce?: number;
entity?: Entity;
entity: Entity;
collection?: Collection;
}): SignalStoreFeature<any, any> {
const { entityMapKey, idsKey } = getWithEntitiesKeys(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function withEntitiesRemoteFilter<
>(config: {
defaultFilter: Filter;
defaultDebounce?: number;
entity?: Entity;
entity: Entity;
}): SignalStoreFeature<
{
state: EntityState<Entity>;
Expand Down Expand Up @@ -212,7 +212,7 @@ export function withEntitiesRemoteFilter<
>(config: {
defaultFilter: Filter;
defaultDebounce?: number;
entity?: Entity;
entity: Entity;
collection?: Collection;
}): SignalStoreFeature<
{
Expand All @@ -234,7 +234,7 @@ export function withEntitiesRemoteFilter<
defaultFilter,
...config
}: {
entity?: Entity;
entity: Entity;
defaultDebounce?: number;
collection?: Collection;
defaultFilter: Filter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ export function withEntitiesLoadingCall<
Entity extends { id: string | number },
Collection extends string,
>(config: {
// entity?: Entity; // is this needed? entity can come from the method fetchEntities return type
collection: Collection;
fetchEntities: (
store: Prettify<
Expand Down Expand Up @@ -283,7 +282,6 @@ export function withEntitiesLoadingCall<
fetchEntities,
...config
}: {
entity?: Entity; // is this needed? entity can come from the method fetchEntities return type
collection?: Collection;
fetchEntities: (
store: SignalStoreSlices<Input['state']> &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function withEntitiesLocalPagination<
>(config: {
pageSize?: number;
currentPage?: number;
entity?: Entity;
entity: Entity;
}): SignalStoreFeature<
{
state: EntityState<Entity>;
Expand Down Expand Up @@ -118,7 +118,7 @@ export function withEntitiesLocalPagination<
>(config: {
pageSize?: number;
currentPage?: number;
entity?: Entity;
entity: Entity;
collection?: Collection;
}): SignalStoreFeature<
{
Expand All @@ -143,9 +143,9 @@ export function withEntitiesLocalPagination<
}: {
pageSize?: number;
currentPage?: number;
entity?: Entity;
entity: Entity;
collection?: Collection;
} = {}): SignalStoreFeature<any, any> {
}): SignalStoreFeature<any, any> {
const { entitiesKey } = getWithEntitiesKeys(config);
const { loadEntitiesPageKey, entitiesCurrentPageKey, paginationKey } =
getWithEntitiesLocalPaginationKeys(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export function withEntitiesRemotePagination<
pageSize?: number;
currentPage?: number;
pagesToCache?: number;
entity?: Entity;
entity: Entity;
}): SignalStoreFeature<
{
state: EntityState<Entity>;
Expand Down Expand Up @@ -248,7 +248,7 @@ export function withEntitiesRemotePagination<
pageSize?: number;
currentPage?: number;
pagesToCache?: number;
entity?: Entity;
entity: Entity;
collection?: Collection;
}): SignalStoreFeature<
{
Expand Down Expand Up @@ -363,9 +363,9 @@ export function withEntitiesRemotePagination<
pageSize?: number;
currentPage?: number;
pagesToCache?: number;
entity?: Entity;
entity: Entity;
collection?: Collection;
} = {}): SignalStoreFeature<any, any> {
}): SignalStoreFeature<any, any> {
const { loadingKey, setLoadingKey } = getWithCallStatusKeys({
prop: config.collection,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ import {
export function withEntitiesRemoteScrollPagination<
Entity extends { id: string | number },
>(config: {
entity?: Entity;
entity: Entity;
pageSize?: number;
pagesToCache?: number;
}): SignalStoreFeature<
Expand Down Expand Up @@ -273,7 +273,7 @@ export function withEntitiesRemoteScrollPagination<
Entity extends { id: string | number },
Collection extends string,
>(config: {
entity?: Entity;
entity: Entity;
collection?: Collection;
pageSize?: number;
pagesToCache?: number;
Expand All @@ -299,11 +299,11 @@ export function withEntitiesRemoteScrollPagination<
pagesToCache = 3,
...config
}: {
entity?: Entity;
entity: Entity;
collection?: Collection;
pageSize?: number;
pagesToCache?: number;
} = {}): SignalStoreFeature<any, any> {
}): SignalStoreFeature<any, any> {
const { loadingKey, setLoadingKey } = getWithCallStatusKeys({
prop: config.collection,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import { getEntitiesMultiSelectionKeys } from './with-entities-multi-selection.u
export function withEntitiesMultiSelection<
Entity extends { id: string | number },
>(config: {
entity?: Entity;
entity: Entity;
}): SignalStoreFeature<
{
state: EntityState<Entity>;
Expand Down Expand Up @@ -114,7 +114,7 @@ export function withEntitiesMultiSelection<
Entity extends { id: string | number },
Collection extends string,
>(config: {
entity?: Entity;
entity: Entity;
collection?: Collection;
}): SignalStoreFeature<
// TODO: the problem seems be with the state pro, when set to empty
Expand All @@ -135,7 +135,7 @@ export function withEntitiesMultiSelection<
Entity extends { id: string | number },
Collection extends string,
>(config: {
entity?: Entity;
entity: Entity;
collection?: Collection;
}): SignalStoreFeature<
// TODO: the problem seems be with the state pro, when set to empty
Expand All @@ -155,7 +155,7 @@ export function withEntitiesMultiSelection<
Entity extends { id: string | number },
Collection extends string,
>(config: {
entity?: Entity;
entity: Entity;
collection?: Collection;
}): SignalStoreFeature<any, any> {
const { entityMapKey, idsKey } = getWithEntitiesKeys(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import { getEntitiesSingleSelectionKeys } from './with-entities-single-selection
export function withEntitiesSingleSelection<
Entity extends { id: string | number },
>(config?: {
entity?: Entity;
entity: Entity;
}): SignalStoreFeature<
{
state: EntityState<Entity>;
Expand Down Expand Up @@ -117,7 +117,7 @@ export function withEntitiesSingleSelection<
Entity extends { id: string | number },
Collection extends string,
>(config?: {
entity?: Entity;
entity: Entity;
collection?: Collection;
}): SignalStoreFeature<
// TODO: the problem seems be with the state pro, when set to empty
Expand All @@ -137,7 +137,7 @@ export function withEntitiesSingleSelection<
Entity extends { id: string | number },
Collection extends string,
>(config?: {
entity?: Entity;
entity: Entity;
collection?: Collection;
}): SignalStoreFeature<any, any> {
const { entityMapKey } = getWithEntitiesKeys(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function withEntitiesLocalSort<
Entity extends { id: string | number },
>(config: {
defaultSort: Sort<Entity>;
entity?: Entity;
entity: Entity;
}): SignalStoreFeature<
{
state: EntityState<Entity>;
Expand Down Expand Up @@ -109,7 +109,7 @@ export function withEntitiesLocalSort<
Collection extends string,
>(config: {
defaultSort: Sort<Entity>;
entity?: Entity;
entity: Entity;
collection?: Collection;
}): SignalStoreFeature<
// TODO: we have a problem with the state property, when set to any
Expand All @@ -136,7 +136,7 @@ export function withEntitiesLocalSort<
...config
}: {
defaultSort: Sort<Entity>;
entity?: Entity;
entity: Entity;
collection?: Collection;
}): SignalStoreFeature<any, any> {
const { entitiesKey } = getWithEntitiesKeys(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function withEntitiesRemoteSort<
Entity extends { id: string | number },
>(config: {
defaultSort: Sort<Entity>;
entity?: Entity;
entity: Entity;
}): SignalStoreFeature<
{
state: EntityState<Entity>;
Expand Down Expand Up @@ -203,7 +203,7 @@ export function withEntitiesRemoteSort<
Entity extends { id: string | number },
Collection extends string,
>(config: {
entity?: Entity;
entity: Entity;
defaultSort: Sort<Entity>;
collection?: Collection;
}): SignalStoreFeature<
Expand All @@ -225,7 +225,7 @@ export function withEntitiesRemoteSort<
defaultSort,
...config
}: {
entity?: Entity;
entity: Entity;
collection?: Collection;
defaultSort: Sort<Entity>;
}): SignalStoreFeature<any, any> {
Expand Down

0 comments on commit c6b5b8c

Please sign in to comment.