-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: movel types for each trait to a .model.ts file
- Loading branch information
Gabriel Guerrero
committed
Apr 17, 2024
1 parent
10a867d
commit 4dc592b
Showing
24 changed files
with
562 additions
and
443 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
libs/ngrx-traits/signals/src/lib/with-call-status/with-call-status.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Signal } from '@angular/core'; | ||
|
||
export type CallStatus = 'init' | 'loading' | 'loaded' | { error: unknown }; | ||
export type CallState = { | ||
callStatus: CallStatus; | ||
}; | ||
export type CallStateComputed = { | ||
isLoading: Signal<boolean>; | ||
} & { | ||
isLoaded: Signal<boolean>; | ||
} & { | ||
error: Signal<string | null>; | ||
}; | ||
export type CallStateMethods = { | ||
setLoading: () => void; | ||
} & { | ||
setLoaded: () => void; | ||
} & { | ||
setError: (error?: unknown) => void; | ||
}; | ||
export type NamedCallState<Prop extends string> = { | ||
[K in Prop as `${K}CallStatus`]: CallStatus; | ||
}; | ||
export type NamedCallStateComputed<Prop extends string> = { | ||
[K in Prop as `is${Capitalize<string & K>}Loading`]: Signal<boolean>; | ||
} & { | ||
[K in Prop as `is${Capitalize<string & K>}Loaded`]: Signal<boolean>; | ||
} & { | ||
[K in Prop as `${K}Error`]: Signal<string | null>; | ||
}; | ||
export type NamedCallStateMethods<Prop extends string> = { | ||
[K in Prop as `set${Capitalize<string & K>}Loading`]: () => void; | ||
} & { | ||
[K in Prop as `set${Capitalize<string & K>}Loaded`]: () => void; | ||
} & { | ||
[K in Prop as `set${Capitalize<string & K>}Error`]: (error?: unknown) => void; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
libs/ngrx-traits/signals/src/lib/with-calls/with-calls.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Observable } from 'rxjs'; | ||
|
||
export type Call<Params extends readonly any[] = any[], Result = any> = ( | ||
...args: Params | ||
) => Observable<Result> | Promise<Result>; | ||
export type CallConfig< | ||
Params extends readonly any[] = any[], | ||
Result = any, | ||
PropName extends string = string, | ||
> = { | ||
call: Call<Params, Result>; | ||
resultProp?: PropName; | ||
mapPipe?: 'switchMap' | 'concatMap' | 'exhaustMap'; | ||
}; | ||
export type ExtractCallResultType<T extends Call | CallConfig> = | ||
T extends Call<any, infer R> | ||
? R | ||
: T extends CallConfig<any, infer R> | ||
? R | ||
: never; | ||
export type ExtractCallParams<T extends Call | CallConfig> = | ||
T extends Call<infer P> ? P : T extends CallConfig<infer P> ? P : never; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
libs/ngrx-traits/signals/src/lib/with-entities-filter/with-entities-local-filter.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Signal } from '@angular/core'; | ||
|
||
export type EntitiesFilterState<Filter> = { entitiesFilter: Filter }; | ||
export type NamedEntitiesFilterState<Collection extends string, Filter> = { | ||
[K in Collection as `${K}Filter`]: Filter; | ||
}; | ||
export type EntitiesFilterComputed = { | ||
isEntitiesFilterChanged: Signal<boolean>; | ||
}; | ||
export type NamedEntitiesFilterComputed<Collection extends string> = { | ||
[K in Collection as `is${Capitalize<string & K>}FilterChanged`]: Signal<boolean>; | ||
}; | ||
export type EntitiesFilterMethods<Filter> = { | ||
filterEntities: ( | ||
options: | ||
| { | ||
filter: Filter; | ||
debounce?: number; | ||
patch?: false | undefined; | ||
forceLoad?: boolean; | ||
} | ||
| { | ||
filter: Partial<Filter>; | ||
debounce?: number; | ||
patch: true; | ||
forceLoad?: boolean; | ||
}, | ||
) => void; | ||
resetEntitiesFilter: () => void; | ||
}; | ||
export type NamedEntitiesFilterMethods<Collection extends string, Filter> = { | ||
[K in Collection as `filter${Capitalize<string & K>}Entities`]: ( | ||
options: | ||
| { | ||
filter: Filter; | ||
debounce?: number; | ||
patch?: false | undefined; | ||
forceLoad?: boolean; | ||
} | ||
| { | ||
filter: Partial<Filter>; | ||
debounce?: number; | ||
patch: true; | ||
forceLoad?: boolean; | ||
}, | ||
) => void; | ||
} & { | ||
[K in Collection as `reset${Capitalize<string & K>}Filter`]: () => void; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.