docs(@ngrx/signals
): add a mention of restructuring withComputed
or withMethods
for re-use in those features
#4669
Labels
Information
The first major stumbling point I had with using features like
withComputed
orwithMethods
was the need to reference other computeds or methods in those features. For example, if I wanted awithComputed
to expose be able to return afullName
that was a store'sfirstName
and store'slastName
, and then also expose aallCapsFullName
that was the full name computed inside another computed. But do to what I thought was a limitation of how to return an object likewithComputed(({ firstName, lastName }) => ({...})
, I had to make a secondwithComputed
However, someone pointed out that the first
withComputed
could be restructured to have a return block, with helperconst
s or functions.In retrospect this is fairly obvious, but I see the former approach all the time and was stuck in that mindset myself. I think partially because most examples of things like
withComputed
have those returns without areturn
block, and because there is a lot of little syntax nuances with functions and objects in the signal store to become comfortable with that add up.I think something like an FAQ page point on this is warranted with how often this little nuance turns into what is perceived as a bigger problem than it is with an easy solution. Or some examples of the second syntax baked into other pages. Willing to formalize/condense this language to make a PR.
Documentation page
https://ngrx.io/guide/signals/faq
I would be willing to submit a PR to fix this issue
The text was updated successfully, but these errors were encountered: