Replies: 1 comment 7 replies
-
Have you considered wrapping each of the class PricePair {
constructor(public pair: string, public value: number) {
makeAutoObservable()
}
// add computed's, define unsubscribe functions
} And then store them as |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Given:
an observable dynamic collection like this::
@observable prices: { [pair: string]: number } = {}
manually controlled requests for fetching and cleaning data (cleaning is important because in reality sockets are used, but I simplified it for the demo) like this:
fetch('/prices/${pair}')
anddelete this.prices[pair]
Currently, control over what data should be loaded and what data should be cleared is done manually, externally. This is acceptable, but only as long as everything is stored in one place. As soon as there are two consumers, it becomes more difficult to synchronize data.
The idea on the surface is that it would be great if this process were automated. For example, some
computed
starts usingstore.prices.foo
andstore.prices.bar
. There aren't exist, thecomputed
getsundefined
s. But the requests/prices/foo
and/prices/bar
automatically start and after completion they install the data. Now thecomputed
has received the necessary data.After some time and some reason, the
computed
stops using thebar
andstore.prices.bar
should be automatically cleared.Is it possible to do something like this?
Beta Was this translation helpful? Give feedback.
All reactions