Open rposener opened 6 years ago
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?
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.