Best practices: which is best 'helper functions' or actions/views/extent functions #2144
-
Both of the solutions below will work, but I'm not sure which is the best practices approach (or if it even matters). Solution 1 (using actions/views/extent functions):
Solution 2 (using helper functions)
I personally like encapsulation and like Solution 2 because...
Thoughts? Bill |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey @guigueb - this is an interesting question. I would probably lean towards the first solution. I think it's more conventional as far as MobX-State-Tree goes because it keeps your computed values in Another issue with solution two is that I don't think we recognize the Even if you could make the syntax work (perhaps I've missed something), you'd have to handle caching yourself. Using getters in the So all that to say, the conventional, best practice in this situation is to keep computed values and actions separate, using the built in That said, there's a case to be made for your second option. I agree the encapsulation is great, and I think writing helper functions inside If you think Last thought on best practicesThis is a gap we have in documentation. If you browse through our discussions forum and issues, you'll find lots of people who really want more guidelines on the "best" or "recommended" way to use MST. In 2024, this is going to be a major focus for us as we improve our docs and community. I'll probably pull from this discussion as some source material. |
Beta Was this translation helpful? Give feedback.
Hey @guigueb - this is an interesting question. I would probably lean towards the first solution. I think it's more conventional as far as MobX-State-Tree goes because it keeps your computed values in
views
, and keeps your actions inactions
.Another issue with solution two is that I don't think we recognize the
getter
syntax inside the actions block. I made a CodeSandbox with a similar code sample, and when I change my helper functions toget [funcitonName]
, I end up with a bunch of errors. Go ahead and fork that if you think you can make it work. I'd love to see a different approach, and it's always great to have code examples in these kinds of discussions.Even if you could make the sy…