How should a Cacheable model be handled #2038
Unanswered
garrettg123
asked this question in
Q&A
Replies: 1 comment
-
Hey @garrettg123 - I don't have a great answer for you at the moment, but I am going move this over to GitHub discussions and either revisit it myself or have others chime in. Sorry it took so long for anyone to get back to you, and I'd definitely be curious to hear if you came up with a good answer on your own or after consulting elsewhere. Thanks! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Question
Below is my
Cacheable
model, which automatically caches other models it iscompose
d into.Tldr; it updates the cache in
onSnapshot
and clears the cache inbeforeDestroy
. Optionally, it loads itself from cache inafterCreate
.An example to use it would be:
The problem is in resetting the data. When I call
destroy(self.myModel)
, for example, it should clear the cache and remove it from state.However, because
beforeDestroy
is asynchronous, and the model type is set asmyModel: types.optional(MyModel, () => MyModel.create())
, before it is removed from cache, it is recreated and loaded from cache, which isn't empty.I'm wondering how to approach this issue. Should I use
types.maybe(MyModel)
and have aninitialize: () => self.myModel = MyModel.create()
or is there another way?Thanks
Beta Was this translation helpful? Give feedback.
All reactions