-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update to ngrx 18 and refactorings
- upgrade to ngrx18 (toolkit compatibility to rc-1 and rc2) - switch from `signals` to `computed` for internal representation of computeds - upgrade nx to 19 - clone internal ngrx types to avoid breaking the encapsulation - remove SSR from demo app - increase bundle budget for demo app - remove test and eslint and only verify for build target in GitHub actions
- Loading branch information
1 parent
3e8e17b
commit 80ccc52
Showing
23 changed files
with
10,675 additions
and
21,536 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { filter, interval, Observable, pipe, switchMap, tap } from 'rxjs'; | ||
import { | ||
patchState, | ||
signalStore, | ||
signalStoreFeature, | ||
type, | ||
withHooks, | ||
withMethods, | ||
withState, | ||
} from '@ngrx/signals'; | ||
import { rxMethod } from '@ngrx/signals/rxjs-interop'; | ||
import { inject } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
|
||
interface Person { | ||
firstname: string; | ||
lastname: string; | ||
} | ||
|
||
function withEntityVersioner<Entity>() { | ||
return signalStoreFeature( | ||
{ methods: type<{ loader: () => Observable<Entity[]> }>() }, | ||
withState({ version: 1, entities: new Array<Entity>() }), | ||
withMethods((store) => { | ||
return { | ||
update: rxMethod<unknown>( | ||
pipe( | ||
switchMap(() => store.loader()), | ||
filter((entities) => entities !== store.entities()), | ||
tap((entities) => | ||
patchState(store, (value) => ({ | ||
entities, | ||
version: value.version + 1, | ||
})) | ||
) | ||
) | ||
), | ||
}; | ||
}), | ||
withHooks((store) => ({ onInit: () => store.update(interval(1000)) })) | ||
); | ||
} | ||
|
||
signalStore( | ||
withMethods(() => { | ||
const httpClient = inject(HttpClient); | ||
return { | ||
loader() { | ||
return httpClient.get<Person[]>('someUrl'); | ||
}, | ||
}; | ||
}), | ||
withEntityVersioner() // does not compile | ||
); |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
export type Emtpy = {}; | ||
export type Empty = {}; |
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,3 @@ | ||
export type Prettify<Type extends {}> = { | ||
[Key in keyof Type]: Type[Key]; | ||
}; |
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,42 @@ | ||
/** | ||
* This file contains copies of types of the Signal Store which are not public. | ||
* | ||
* Since certain features depend on them, if we don't want to break | ||
* the encapsulation of @ngrx/signals, we decided to copy them. | ||
* | ||
* Since TypeScript is based on structural typing, we can get away with it. | ||
* | ||
* If @ngrx/signals changes its internal types, we catch them via integration | ||
* tests. | ||
* | ||
* Because of the "tight coupling", the toolkit doesn't have version range | ||
* to @ngrx/signal, but is very precise. | ||
*/ | ||
import { Signal } from '@angular/core'; | ||
import { EntityId } from '@ngrx/signals/entities'; | ||
|
||
export type SignalStoreFeatureResult = { | ||
state: object; | ||
computed: Record<string, Signal<unknown>>; | ||
methods: Record<string, Function>; | ||
}; | ||
|
||
export type EmptyFeatureResult = { | ||
state: {}; | ||
computed: {}; | ||
methods: {}; | ||
}; | ||
|
||
// withEntites models | ||
export type EntityState<Entity> = { | ||
entityMap: Record<EntityId, Entity>; | ||
ids: EntityId[]; | ||
}; | ||
|
||
export type EntityComputed<Entity> = { | ||
entities: Signal<Entity[]>; | ||
}; | ||
|
||
export type NamedEntityComputed<Entity, Collection extends string> = { | ||
[K in keyof EntityComputed<Entity> as `${Collection}${Capitalize<K>}`]: EntityComputed<Entity>[K]; | ||
}; |
Oops, something went wrong.