Would a new lifecycle method be apt/possible: beforeAttachedToRootStore #315
justin-hackin
started this conversation in
Ideas
Replies: 1 comment
-
To give some context into my use case I made a code snippet to demonstrate my experiments with the new context apply feature here: https://codesandbox.io/s/poc-referencedropdownprop-wp0mp?file=/src/index.ts . Aside from this little hiccup, I'm pretty happy with this solution. I'm creating a whole collection of prop factories wired to material UI components that make creating a data structure + control panel a breeze. The usefulness of generics and contexts are really wowing me 🤯🤩 Feedback welcome, I might make the concept into a package eventually. |
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
-
I think it would be useful to be able to have a beforeAttachedToRootStore in order to initialize model properties based on a context applied to the model before it is attached to the tree. Having a node show up in the tree without its property initialized forces me to an existence check at the beginning of a very long chain of function calls which makes my code hard to reason about.
In my use case, I've created a generic prop factory function that takes a type ref and a path relative to the root store and by default sets the reference to be the first item in the array of items specified by the path. I can't perform the initialization of the property onInit because the path to the items to be reference is resolved relative the root store.
Beta Was this translation helpful? Give feedback.
All reactions