-
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: add secondary entry point for redux connector
The redux-connector is the only extension that requires the @ngrx/store. By making it a secondary entry point, the @ngrx/store dependency is not applied to the other extensions. This fixes issue #79
- Loading branch information
1 parent
42d098b
commit 48f9d95
Showing
24 changed files
with
147 additions
and
524 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
18 changes: 10 additions & 8 deletions
18
apps/demo/src/app/flight-search-data-service-dynamic/flight-booking.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 |
---|---|---|
@@ -1,28 +1,30 @@ | ||
import { FlightService } from '../shared/flight.service'; | ||
|
||
import { | ||
signalStore, type, | ||
} from '@ngrx/signals'; | ||
import { signalStore, type } from '@ngrx/signals'; | ||
|
||
import { withEntities } from '@ngrx/signals/entities'; | ||
import { withCallState, withDataService, withUndoRedo } from 'ngrx-toolkit'; | ||
import { | ||
withCallState, | ||
withDataService, | ||
withUndoRedo, | ||
} from '@angular-architects/ngrx-toolkit'; | ||
import { Flight } from '../shared/flight'; | ||
|
||
export const FlightBookingStore = signalStore( | ||
{ providedIn: 'root' }, | ||
withCallState({ | ||
collection: 'flight' | ||
collection: 'flight', | ||
}), | ||
withEntities({ | ||
entity: type<Flight>(), | ||
collection: 'flight' | ||
collection: 'flight', | ||
}), | ||
withDataService({ | ||
dataServiceType: FlightService, | ||
filter: { from: 'Paris', to: 'New York' }, | ||
collection: 'flight' | ||
collection: 'flight', | ||
}), | ||
withUndoRedo({ | ||
collections: ['flight'], | ||
}), | ||
}) | ||
); |
16 changes: 9 additions & 7 deletions
16
apps/demo/src/app/flight-search-data-service-simple/flight-booking-simple.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 |
---|---|---|
@@ -1,20 +1,22 @@ | ||
import { FlightService } from '../shared/flight.service'; | ||
|
||
import { | ||
signalStore, | ||
} from '@ngrx/signals'; | ||
import { signalStore } from '@ngrx/signals'; | ||
|
||
import { withEntities } from '@ngrx/signals/entities'; | ||
import { withCallState, withDataService, withUndoRedo } from 'ngrx-toolkit'; | ||
import { | ||
withCallState, | ||
withDataService, | ||
withUndoRedo, | ||
} from '@angular-architects/ngrx-toolkit'; | ||
import { Flight } from '../shared/flight'; | ||
|
||
export const SimpleFlightBookingStore = signalStore( | ||
{ providedIn: 'root' }, | ||
withCallState(), | ||
withEntities<Flight>(), | ||
withDataService({ | ||
dataServiceType: FlightService, | ||
dataServiceType: FlightService, | ||
filter: { from: 'Paris', to: 'New York' }, | ||
}), | ||
withUndoRedo(), | ||
); | ||
withUndoRedo() | ||
); |
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
63 changes: 43 additions & 20 deletions
63
apps/demo/src/app/flight-search-redux-connector/+state/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 |
---|---|---|
@@ -1,39 +1,62 @@ | ||
import { computed, inject } from '@angular/core'; | ||
import { patchState, signalStore, type, withComputed, withMethods } from '@ngrx/signals'; | ||
import { removeAllEntities, setAllEntities, updateEntity, withEntities } from '@ngrx/signals/entities'; | ||
import { reduxMethod } from 'ngrx-toolkit'; | ||
import { | ||
patchState, | ||
signalStore, | ||
type, | ||
withComputed, | ||
withMethods, | ||
} from '@ngrx/signals'; | ||
import { | ||
removeAllEntities, | ||
setAllEntities, | ||
updateEntity, | ||
withEntities, | ||
} from '@ngrx/signals/entities'; | ||
import { reduxMethod } from '@angular-architects/ngrx-toolkit/redux-connector'; | ||
import { from, map, pipe, switchMap } from 'rxjs'; | ||
import { Flight } from '../../shared/flight'; | ||
import { FlightFilter, FlightService } from '../../shared/flight.service'; | ||
|
||
|
||
export const FlightStore = signalStore( | ||
{ providedIn: 'root' }, | ||
// State | ||
withEntities({ entity: type<Flight>(), collection: 'flight' }), | ||
withEntities({ entity: type<number>(), collection: 'hide' }), | ||
// Selectors | ||
withComputed(({ flightEntities, hideEntities }) => ({ | ||
filteredFlights: computed(() => flightEntities() | ||
.filter(flight => !hideEntities().includes(flight.id))), | ||
filteredFlights: computed(() => | ||
flightEntities().filter((flight) => !hideEntities().includes(flight.id)) | ||
), | ||
flightCount: computed(() => flightEntities().length), | ||
})), | ||
// Updater | ||
withMethods(store => ({ | ||
setFlights: (state: { flights: Flight[] }) => patchState(store, | ||
setAllEntities(state.flights, { collection: 'flight' })), | ||
updateFlight: (state: { flight: Flight }) => patchState(store, | ||
updateEntity({ id: state.flight.id, changes: state.flight }, { collection: 'flight' })), | ||
clearFlights: () => patchState(store, | ||
removeAllEntities({ collection: 'flight' })), | ||
withMethods((store) => ({ | ||
setFlights: (state: { flights: Flight[] }) => | ||
patchState( | ||
store, | ||
setAllEntities(state.flights, { collection: 'flight' }) | ||
), | ||
updateFlight: (state: { flight: Flight }) => | ||
patchState( | ||
store, | ||
updateEntity( | ||
{ id: state.flight.id, changes: state.flight }, | ||
{ collection: 'flight' } | ||
) | ||
), | ||
clearFlights: () => | ||
patchState(store, removeAllEntities({ collection: 'flight' })), | ||
})), | ||
// Effects | ||
withMethods((store, flightService = inject(FlightService)) => ({ | ||
loadFlights: reduxMethod<FlightFilter, { flights: Flight[] }>(pipe( | ||
switchMap(filter => from( | ||
flightService.load({ from: filter.from, to: filter.to }) | ||
)), | ||
map(flights => ({ flights })), | ||
), store.setFlights), | ||
})), | ||
loadFlights: reduxMethod<FlightFilter, { flights: Flight[] }>( | ||
pipe( | ||
switchMap((filter) => | ||
from(flightService.load({ from: filter.from, to: filter.to })) | ||
), | ||
map((flights) => ({ flights })) | ||
), | ||
store.setFlights | ||
), | ||
})) | ||
); |
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.