Software engineer, I've been working with Angular for 6 years now and strive to work more full stack. I publish on dev.to about topics I love around open source, frontend, data privacy, automations.
How do you deal with this when you receive an array of values? And how do you deal with it when you remap an array to another array? The reference will change even if the array contains the same references. Therefore any selectors based on one like that will be fired again.
Also, while this post is nice and the idea is good, I'd point out that it's probably not worth doing that for very simple like adding 2 numbers. This is stupid fast in the first place and anything that's not an object will give a value that can be cached/memoized for the next selectors. If you're doing heavy computation in a selector though, that'd be a good use case.
I am not 100% clear which function you are referring to that is receiving the array? If its the selector then yes if it results in a new array or a different reference then it will fire a new value. I would argue that if the array is changing then it should be recalculated. If its within our control then we should check that we are not updating the array references when we know its contents will not be changing.
If that is outside of our control then we would have to decide what is more performant. To apply a custom distinctUntilChanged to the selector or just run the calculation again.
And yes I totally agree this is overkill for adding 2 numbers! I tried to make that clear in the post and that this technique is only required when you are running expensive computations based off your state.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
How do you deal with this when you receive an array of values? And how do you deal with it when you remap an array to another array? The reference will change even if the array contains the same references. Therefore any selectors based on one like that will be fired again.
Also, while this post is nice and the idea is good, I'd point out that it's probably not worth doing that for very simple like adding 2 numbers. This is stupid fast in the first place and anything that's not an object will give a value that can be cached/memoized for the next selectors. If you're doing heavy computation in a selector though, that'd be a good use case.
I am not 100% clear which function you are referring to that is receiving the array? If its the selector then yes if it results in a new array or a different reference then it will fire a new value. I would argue that if the array is changing then it should be recalculated. If its within our control then we should check that we are not updating the array references when we know its contents will not be changing.
If that is outside of our control then we would have to decide what is more performant. To apply a custom
distinctUntilChanged
to the selector or just run the calculation again.And yes I totally agree this is overkill for adding 2 numbers! I tried to make that clear in the post and that this technique is only required when you are running expensive computations based off your state.