-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
suggestion/question: withDataService
support for Observables
#85
Comments
@michael-small, I don't see a problem in supporting RxJs. So feel free to contribute your implementation |
Sounds good. I in fact do have some changes to make as I messed some stuff up, but once I have it in a better state I will update this issue and then get to a PR. |
Link to my implementation in a project: https://github.com/michael-small/signal-store-playground/tree/main/src/app/store/withDataService-rxjs Once I have ironed it out a bit more I will make a fork of the toolkit and start adding an RXJS implementation. |
I have been grappling with types and generics when trying to adapt export interface DataService<
E extends Entity,
F extends Filter,
ArrEntityData = Promise<E[]> | Observable<E[]>,
SingleEntityData = Promise<E> | Observable<E>,
VoidEntityData = Promise<void> | Observable<void>>
{
load(filter: F): ArrEntityData;
loadById(id: EntityId): SingleEntityData;
create(entity: E): SingleEntityData;
update(entity: E): SingleEntityData;
updateAll(entity: E[]): ArrEntityData;
delete(entity: E): VoidEntityData ;
} Provided an interface like this one is agreeable, I still have to figure out how each Bottom line: naming aside, would you say that an interface like this is a good starting point? |
@michael-small, what about that alternative Signature? type PromiseOrObservable<Entity> = Promise<Entity> | Observable<Entity>;
export interface DataService<
E extends Entity,
F extends Filter
{
load(filter: F): PromiseOrObservable<Entity[]>;
loadById(id: EntityId): PromiseOrObservable<Entity>;
create(entity: E): PromiseOrObservable<Entity>;
update(entity: E): PromiseOrObservable<Entity>;
updateAll(entity: E[]): PromiseOrObservable<Entity[]>;
delete(entity: E): PromiseOrObservable<void> ;
} |
@rainerhahnekamp that's a lot better, thank you. |
Great, waiting for your PR then 😃 |
Thank you. Once I figure out how I can get each method to either narrow down what to do based on the type, or overload for the top level async or rxMethod signature, then I'll submit the PR. Will you want tests for these? I don't see tests for the promises version, but I can try to make a test suite. |
Yes please. Tests would be great |
@rainerhahnekamp I have a question: since I don't suppose we would make some My approach right now is basically using type guards for telling if the implementing service method returns a promise or observable, so this is a particular edge case that I aught to handle before narrowing down other checks. So handle the logic based on the input first, and then presumably safely assume I use an |
@michael-small I'd say for the first version, it should be fine of you check if the response is of type Promise or Observable. I guess you would do an automatic subscribe. If there's demand, we can later maybe add the |
Sounds good, thanks. It didn't occur to me that the RXJS calls could be an old fashioned subscription. I'm just so I'll proceed with manual subscriptions. I assume in that case I can handle subscriptions with some type of self cleaning up subscription, or perhaps pass in a destroyRef. I'll go with the former to keep it simple. |
My problem
withDataService
is super smart and interesting. Honestly the most boilerplate reducing Angular code I have seen. One limitation for my own use, however, is that I userxMethod
rather thanpromise
.My suggestions/questions
I copied over the relevant files of this library's
withDataService
into a private project full of more signal store experimentation I adapted all the feature methods to userxMethod
. I have not tested it too much yet, but it seems to work good so far. I can make it public if anyone is interested.withDataService
to support RXJS?copies or substantial portions of the Software."?
edit: link to my implementation in one of my projects: https://github.com/michael-small/signal-store-playground/tree/main/src/app/store/withDataService-rxjs
The text was updated successfully, but these errors were encountered: