-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
provide injection context to onDestroy
#4201
Comments
Hi 👋 On the other hand, such style doesn't seem to be common within angular ecosystem. For instance, signal My vote is for version 2 which is explicit and slightly more consistent with other cleanup APIs. |
I vote for version 2 |
The thing that I don't like about option 2 is that it leaves some space for 'abuse'/wrong usage: withHooks((store) => {
// init logic can be executed here
return {
onInit() {
// but also here
},
};
}); On the other hand, it is consistent with other base SignalStore features and provides the possibility of potential extension in the future. 👌 withHooks((store, service = inject(MyService)) => ({
onInit() {},
onDestroy() {},
})); |
@markostanimirovic since the API is closure-based anyway, it's kind of natural that you can access the enclosing scope. Perhaps in corner cases someone would need to share a value (ID? token? whatever) in both |
@markostanimirovic what is the problem if somebody does withHooks((store) => {
const service = inject(Service);
return {
onInit() {
service.doInitStuff();
},
};
}); vs withHooks((store) => {
const service = inject(Service);
service.doInitStuff();
return {};
}); It is not consistent but is this such a big thing that we want to enforce it by design? Or are there are thing which might happen, that I am not aware of? |
I just realized that version 2 would include a breaking change as well:
Currently, the hooks get the store as parameter. In the version above, the store is passed on to I am using the non-breaking change version in #4208 which looks like this:
What should we do? If we want to be consequent, the store should be passed to |
I think the We can't prevent everyone from abusing the usage, but we can potentially add some lint rules around certain usage to sway people away from it. |
The PR has been updated with |
Which @ngrx/* package(s) are relevant/related to the feature request?
signals
Information
As discussed in #4196, we have to run
onDestroy
outside of the injection context.At the moment, there are two options on the table:
Version 1: "Svelte style":
Version 2:
I opt for version 2 because
withMethods
&withComputed
, where we have the first part which provides access to the DI and the second contains the implementation.onChange
: @ngrx/signals: Extension Point stateChange #4192onInit
might be more familiar to an Angular developer because of the same hook in the framework.In the end, it is a question of personal style. From a technical perspective, both options are ok.
Describe any alternatives/workarounds you're currently using
No response
I would be willing to submit a PR to fix this issue
The text was updated successfully, but these errors were encountered: