Skip to content

Why not create new observables in computeds? #3136

Answered by urugator
martinslota asked this question in Q&A
Discussion options

You must be logged in to vote

Computed (arguably) represents data that can be derived/reconstructed from your state at any point in time - the cache is just an optimization, not something to design your system around.
You should assume that accessing name 3 times will result in a creation of 3 promises. With this reasoning it doesn't make sense to return anything statefull and therefore observable.
This is because the cache dependents on usage - you assume that your class is used in a particular way, but from the consumer point of view, it's just a field/value as any another.
Eg, in react's concurrent mode, the field can be read during render multiple times, but the component may not ever get committed, so the fetch r…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@martinslota
Comment options

Comment options

You must be logged in to vote
2 replies
@martinslota
Comment options

@urugator
Comment options

Answer selected by martinslota
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants