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

Add support for promise resolution in createViewModel function of components #77

Open
rposener opened this issue Jun 24, 2018 · 3 comments
Open

Comments

@rposener
Copy link

@rposener rposener commented Jun 24, 2018

I find that it would be really helpful in a few situations if I could inject a promise (which maybe doing ajax and/or indexeddb work) just before my component is displayed. This is somewhat supported by the AMD/require syntax, but does not seem to be simple/straightforward. It would be helpful if we could return a promise from createViewModel, that is awaited before the component is created and instantiated.

What I see the team always doing instead is creating some "loaded" Observable that is set after the component initialization finishes. This creates extra paints in some cases that just seem unnecessary - especially when working with indexeddb, or just a cached ajax get. The 3-5 ms wait triggering multiple paints, plus when tracking dirty, the issue of dealing with new viewmodel state change (after construction) seems like a lot of effort could be simplified if createViewModel supported returning a promise that returns a viewmodel. That would let us deal with many of these issues in a clean and natural way right at component instantiation. Since the component loader is asyncronous anyway, seems like this shouldn't be too hard to add.

@caseyWebb
Copy link
Contributor

@caseyWebb caseyWebb commented Jun 25, 2018

Related: #64

@brianmhunt
Copy link
Member

@brianmhunt brianmhunt commented Jun 25, 2018

I get it. Will look into it, for sure. I feel like reworking the loader in general, too.

Just to ensure I’m on the right page, can you put together a codepen or jsfiddle that shows how a sample case and comments the expected behaviour?

@rposener
Copy link
Author

@rposener rposener commented Jun 25, 2018

@brianmhunt - I think this should be as simple a codepen I can get that gives an example of what and how it should be supported. Welcome to other's ideas/inputs as well codepen.

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.