New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@angular-architects/ngrx-toolkit

Package Overview
Dependencies
Maintainers
4
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@angular-architects/ngrx-toolkit - npm Package Compare versions

Comparing version 0.0.4 to 0.0.6

esm2022/lib/redux-connector/create-redux.mjs

2

index.d.ts

@@ -6,1 +6,3 @@ export { withDevtools, patchState, Action } from './lib/with-devtools';

export * from './lib/with-data-service';
export * from './lib/redux-connector';
export * from './lib/redux-connector/rxjs-interop';
{
"name": "@angular-architects/ngrx-toolkit",
"version": "0.0.4",
"version": "0.0.6",
"license": "MIT",
"repository": {
"type": "GitHub",
"url": "https://github.com/angular-architects/ngrx-toolkit"
},
"peerDependencies": {

@@ -5,0 +10,0 @@ "@angular/common": "^17.0.0",

# NgRx Toolkit
[![npm](https://img.shields.io/npm/v/%40angular-architects%2Fngrx-toolkit.svg)](https://www.npmjs.com/package/%40angular-architects%2Fngrx-toolkit)
<p align="center">

@@ -11,2 +13,3 @@ <img src="https://raw.githubusercontent.com/angular-architects/ngrx-toolkit/main/logo.png" width="320" style="text-align: center">

- Redux: Possibility to use the Redux Pattern (Reducer, Actions, Effects)
- Redux Connector: Map NgRx Store Actions to a present Signal Store

@@ -19,2 +22,16 @@ To install it, run

- [NgRx Toolkit](#ngrx-toolkit)
- [Devtools: `withDevtools()`](#devtools-withdevtools)
- [Redux: `withRedux()`](#redux-withredux)
- [DataService `withDataService()`](#dataservice-withdataservice)
- [DataService with Dynamic Properties](#dataservice-with-dynamic-properties)
- [Redux Connector for the NgRx Signal Store `createReduxState()`](#redux-connector-for-the-ngrx-signal-store-createreduxstate)
- [Use a present Signal Store](#use-a-present-signal-store)
- [Use well-known NgRx Store Actions](#use-well-known-ngrx-store-actions)
- [Map Actions to Methods](#map-actions-to-methods)
- [Register an Angular Dependency Injection Provider](#register-an-angular-dependency-injection-provider)
- [Use the Store in your Component](#use-the-store-in-your-component)
## Devtools: `withDevtools()`

@@ -222,2 +239,134 @@

}
```
```
## Redux Connector for the NgRx Signal Store `createReduxState()`
The Redux Connector turns any `signalStore()` into a Gobal State Management Slice following the Redux pattern.
It supports:
✅ Well-known NgRx Store Actions \
✅ Global Action `dispatch()` \
✅ Angular Lazy Loading \
✅ Auto-generated `provideNamedStore()` & `injectNamedStore()` Functions \
✅ Global Action to Store Method Mappers \
### Use a present Signal Store
```typescript
export const FlightStore = signalStore(
// 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))),
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' })),
})),
// 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),
})),
);
```
### Use well-known NgRx Store Actions
```typescript
export const ticketActions = createActionGroup({
source: 'tickets',
events: {
'flights load': props<FlightFilter>(),
'flights loaded': props<{ flights: Flight[] }>(),
'flights loaded by passenger': props<{ flights: Flight[] }>(),
'flight update': props<{ flight: Flight }>(),
'flights clear': emptyProps()
}
});
```
### Map Actions to Methods
```typescript
export const { provideFlightStore, injectFlightStore } =
createReduxState('flight', FlightStore, store => withActionMappers(
mapAction(
// Filtered Action
ticketActions.flightsLoad,
// Side-Effect
store.loadFlights,
// Result Action
ticketActions.flightsLoaded),
mapAction(
// Filtered Actions
ticketActions.flightsLoaded, ticketActions.flightsLoadedByPassenger,
// State Updater Method (like Reducers)
store.setFlights
),
mapAction(ticketActions.flightUpdate, store.updateFlight),
mapAction(ticketActions.flightsClear, store.clearFlights),
)
);
```
### Register an Angular Dependency Injection Provider
```typescript
export const appRoutes: Route[] = [
{
path: 'flight-search-redux-connector',
providers: [provideFlightStore()],
component: FlightSearchReducConnectorComponent
},
];
```
### Use the Store in your Component
```typescript
@Component({
standalone: true,
imports: [
JsonPipe,
RouterLink,
FormsModule,
FlightCardComponent
],
selector: 'demo-flight-search-redux-connector',
templateUrl: './flight-search.component.html',
})
export class FlightSearchReducConnectorComponent {
private store = injectFlightStore();
protected flights = this.store.flightEntities;
protected search() {
this.store.dispatch(
ticketActions.flightsLoad({
from: this.localState.filter.from(),
to: this.localState.filter.to()
})
);
}
protected reset(): void {
this.store.dispatch(ticketActions.flightsClear());
}
}
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc