angular-architects / ngrx-toolkit

Various Extensions for the NgRx Signal Store
MIT License
98 stars 16 forks source link

Compat NgRx Store #8

Open rainerhahnekamp opened 6 months ago

rainerhahnekamp commented 6 months ago

Check if it is possible to integrate an existing NgRx Store into withRedux.

Coming from NgRx Store

const flightsFeature = createFeature({
  name: 'flights', 
  reducer: createReducer(initialState, on(flightActions.searched, (state, {flights}) => ({...state, flights})))
})

@Injectable()
class FlightEffects {
  search$ = createEffect(() => ofType(flightActions.search));
}

Could be integrated like

signalStore(
  {providedIn: 'root'},
  withReduxCompat(flightsFeature, FlightEffects)
);
rosostolato commented 6 months ago

According to my tests while I was developing this lib, if you inject the effects in the store, you will have circular dependency injections if you try to inject the store on your effects class.

The best solution I found was to create this provider function that would inject the Effects when you use it with the EffectsDirective.

rainerhahnekamp commented 6 months ago

In that case, the FlightEffect still goes against the @ngrx/store Store service and not against the SignalStore. I guess with your provider function, one could replace it under the hood.

So the effect would think it is working with the Store service although it runs against an adapter which uses the SignalStore.