best way to handle delayed fetch of data in a signal store? #4464
-
hello all. I have an ngrx store slice which is responsible for holding global info for my app. One field is called
as we can see the signal store uses the onInit hook to set up an effect against the globalSliceFacade's userId signal and if the userId exists we trigger a call to fetch the data. I could not think of another way for this signal store to know when to fetch the data (unless the global facade has an effect on the setUserId action which doesnt dispatch anything and simply calls this signal store, but i didnt want the global store to know about this signal store) the only reason i dont love this is because it will be the first time that we've had to enable signal writes in our app (we have barely used signals yet). I know that there are valid use cases for enabling it and it is nearly impossible for us to get stuck in an infinite loop here as under no circumstance should this signal store be triggering anything that changes the userId. So my question is: is this a valid time to allowSignalWrites or is there a better way to make this signal store wait before fetching its data? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
I do it in the same way but with It is not a sin to use You could of course create a method with |
Beta Was this translation helpful? Give feedback.
I do it in the same way but with
untracked
.allowSignalWrites
is going to vanish: angular/angular#56501It is not a sin to use
untracked
btw. There is complete discussion of making it the default: angular/angular#56155You could of course create a method with
rxMethod
and call that method via the init hook. That method would at the same time also do the fetching. But I am not sure if it brings that much in terms of readability.