reduxjs / angular-redux

Official Angular bindings for Redux
MIT License
71 stars 7 forks source link

how to provide injection context in createAsyncThunk #12

Closed spider9375 closed 1 month ago

spider9375 commented 1 month ago

basically the title. Trying to find a way to create an abstraction of createAsyncThunk that has angular's injection context inside, so i can inject services and make api calls

crutchcorn commented 1 month ago

This can be done using Angular's runInInjectionContext API.

I demonstrated it here:

https://github.com/reduxjs/angular-redux/pull/13

But explicitly included a demo for reference here:

https://github.com/reduxjs/angular-redux/tree/main/projects/angular-redux-injector-demo/src

I know this API isn't super ideal, but it's stable and type-safe, so it should be fine for now. If anyone has any ideas for an API that improves on this, let me know and I'll happily consider it 😊