Replies: 2 comments
-
The "bad practice" feeling I get from your withMethods approach is not because it is not updating internal store slices (personally i think its ok to have methods that do this but thats beside the point). My main issue is because you are returning the computed value of a reactive signal not the computed signal itself. For example, if you do I would think you would instead want your method to use the internal state, to build a computed signal based on the users internal signal. Something like:
Then when accessing the value of the computed state, you use the preferences signal like so: To me that does not feel strange, but keeps reactivity. If this does not fit your philosophy, would with props be more appropriate?
But, i think i am in agreement that a wrapper function could reduce some boilerplate, not sure at what cost though (one that comes to mine is it clear that returns of selectors are wrapped inside computed signals or not). Rough idea could be something like:
|
Beta Was this translation helpful? Give feedback.
-
I completely agree, @Devin-Harris. It was a mistake from my side that the withMethods did not return a computed value. I have updated my example. My point is, as you suggest, that with a wrapper function, a clear section in the signal store that focuses on selectors based on external parameters (internal state changes are handled with withComputed). I believe that it will allow for a smoother transition from the ngrx/store to ngrx/signals, since at least at my company, where selectors are heavily used. Alternatively, as suggested, the documentation should be updated to reflect that withProps could be used here. Currently, the documentation showcases how to convert signals to observables and how to inject services when used across multiple sections in the signal store. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Which @ngrx/* package(s) are relevant/related to the feature request?
signals
Information
Currently, using ngrx/store and selectors, a function can be defined to get internal state slice within the store based on external parameters.
With ngrx/signals, an official way is currently not defined.
My current workaround is to add a method in withMethods to get the desired behavior
In my opinion, this is bad practice. The withMethods sole purpose should be to update the stores internal slices.
To create a clear separation, like the selectors in ngrx/store, a new section should be added to the Signal Store called withSelectors (or a better name), that is only used to get internal state based on external parameters
Describe any alternatives/workarounds you're currently using
No response
I would be willing to submit a PR to fix this issue
Beta Was this translation helpful? Give feedback.
All reactions