|
Last change
on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
958 bytes
|
| Line | |
|---|
| 1 | import type {
|
|---|
| 2 | EntityId,
|
|---|
| 3 | EntityState,
|
|---|
| 4 | EntityStateAdapter,
|
|---|
| 5 | EntityStateFactory,
|
|---|
| 6 | } from './models'
|
|---|
| 7 |
|
|---|
| 8 | export function getInitialEntityState<T, Id extends EntityId>(): EntityState<
|
|---|
| 9 | T,
|
|---|
| 10 | Id
|
|---|
| 11 | > {
|
|---|
| 12 | return {
|
|---|
| 13 | ids: [],
|
|---|
| 14 | entities: {} as Record<Id, T>,
|
|---|
| 15 | }
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | export function createInitialStateFactory<T, Id extends EntityId>(
|
|---|
| 19 | stateAdapter: EntityStateAdapter<T, Id>,
|
|---|
| 20 | ): EntityStateFactory<T, Id> {
|
|---|
| 21 | function getInitialState(
|
|---|
| 22 | state?: undefined,
|
|---|
| 23 | entities?: readonly T[] | Record<Id, T>,
|
|---|
| 24 | ): EntityState<T, Id>
|
|---|
| 25 | function getInitialState<S extends object>(
|
|---|
| 26 | additionalState: S,
|
|---|
| 27 | entities?: readonly T[] | Record<Id, T>,
|
|---|
| 28 | ): EntityState<T, Id> & S
|
|---|
| 29 | function getInitialState(
|
|---|
| 30 | additionalState: any = {},
|
|---|
| 31 | entities?: readonly T[] | Record<Id, T>,
|
|---|
| 32 | ): any {
|
|---|
| 33 | const state = Object.assign(getInitialEntityState(), additionalState)
|
|---|
| 34 | return entities ? stateAdapter.setAll(state, entities) : state
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | return { getInitialState }
|
|---|
| 38 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.