Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to properly bind to ViewModel data that is avaialbe after Awake? #38

Open
robertverdes opened this issue Dec 3, 2019 · 1 comment

Comments

@robertverdes
Copy link

This seems like a a great library, and I might be severely missing the point, but I don't see a way out of the box to support binding to ViewModels that have their data populated after Awake (since initializiation for binders seems to happen on Awake).
e.g.

  • when the ViewModel is created at runtime, and then initialized (since Unity doesn't allow initializing a GameObject before Awake except if it's disabled, and that's an ugly flow for prefabs)
  • or even, using IViewModelProvider to have POCO VMs, as you suggested in previous issue replies: how can GetViewModel return a valid non-MonoBehaviour instance that's somehow injected into the MonoBehaviour (ony way I see is you'd have to call some static singleton-ish provider class from within the method for it to happen before Awake, and I'd like to be able to stick with a DI flow)

Adding [DefaultExecutionOrder(100)] to AbstractMemeberBinding fixes it for VMs already in the scene at lauch, but it doesn't work for those created at runtime.

Any insights welcome! Thanks!

@robertverdes robertverdes changed the title How to properly bind to (View)Models data that is avaialbe after Awake? How to properly bind to ViewModel data that is avaialbe after Awake? Dec 3, 2019
@robertverdes
Copy link
Author

Ok, modifying AbstractMemberBinding to call Init() in "Start" rather than "Awake" seems to do the trick. Are there any pitfalls to this change in the context of the library?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant