forked from angular-architects/ngrx-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: devtools integration, demo app
- Loading branch information
Showing
21 changed files
with
310 additions
and
38 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
4 changes: 2 additions & 2 deletions
4
projects/shell/src/app/booking/flight/+state/ngrx-signals/tickets.signal.store.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
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
30 changes: 30 additions & 0 deletions
30
projects/shell/src/app/booking/passenger/+state/passenger.signal.store.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,30 @@ | ||
import { createReduxState, mapAction, withActionMappers } from '@angular-architects/ngrx-toolkit'; | ||
import { patchState, signalStore, type, withMethods } from '@ngrx/signals'; | ||
import { setAllEntities, withEntities } from '@ngrx/signals/entities'; | ||
import { createActionGroup, props } from '@ngrx/store'; | ||
import { Passenger } from './../logic/model/passenger'; | ||
|
||
|
||
export const PassengerStore = signalStore( | ||
{ providedIn: 'root' }, | ||
// State | ||
withEntities({ entity: type<Passenger>(), collection: 'passenger' }), | ||
// Updater | ||
withMethods(store => ({ | ||
setPassengers: (state: { passengers: Passenger[] }) => patchState(store, | ||
setAllEntities(state.passengers, { collection: 'passenger' })), | ||
})), | ||
); | ||
|
||
export const passengerActions = createActionGroup({ | ||
source: 'passenger', | ||
events: { | ||
'passengers loaded': props<{ passengers: Passenger[] }>() | ||
} | ||
}); | ||
|
||
export const { providePassengerStore, injectPassengerStore } = | ||
createReduxState('passenger', PassengerStore, store => withActionMappers( | ||
mapAction(passengerActions.passengersLoaded, store.setPassengers) | ||
) | ||
); |
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
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
26 changes: 26 additions & 0 deletions
26
projects/shell/src/app/shared/redux-devtools/devtools-connect.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,26 @@ | ||
import { getConnection, getRootState, initDevtools, setUntrackedStore, updateStoreRegistry } from "./devtools-core"; | ||
import { Action } from "./model"; | ||
import { getStoreSignal } from "./util"; | ||
|
||
|
||
/** | ||
* Devtools Public API: Add Store, Dispatch Action | ||
*/ | ||
export function addStoreToReduxDevtools(store: unknown, name: string, live = true): boolean { | ||
if (!initDevtools()) { | ||
return false; | ||
} | ||
|
||
!live && setUntrackedStore(name); | ||
const storeSignal = getStoreSignal(store); | ||
updateStoreRegistry((value) => ({ | ||
...value, | ||
[name]: storeSignal | ||
})); | ||
|
||
return true; | ||
} | ||
|
||
export function dispatchActionToReduxDevtools(action: Action): void { | ||
getConnection()?.send(action, getRootState()); | ||
} |
Oops, something went wrong.