marko-js-archive / marko-widgets

[LEGACY] Module to support binding of behavior to rendered UI components rendered on the server or client
http://v3.markojs.com/docs/marko-widgets/
MIT License
142 stars 40 forks source link

Support lazy widget initialization within Marko Widgets #145

Open shanimal opened 8 years ago

shanimal commented 8 years ago

Looking for a modular approach to loading Marko widgets from the file server.

The thought is that some portions of your app may never be needed. Things like dialogs, detail views, shopping carts. It would make sense to not include those in the initial site load.

patrick-steele-idem commented 8 years ago

Do you have any thoughts how this would look in practice based on your experience? Maybe some sample code to illustrate the pattern?

Also, are you using Lasso?

shanimal commented 8 years ago

I'm thinking a lazy loaded widget would look exactly the same as a regular widget from the standpoint of template. If the application has a list of registered, properly name-spaced widgets, Marko would check the registry when it loads the template (i think it already does this) and if the widget doesn't exist, Marko would attempt to download it.

It might go something like:

I'm assuming lasso could be used to bundle the components but it wouldn't be required.

Due to my lack of experience, the details of the implementation escapes me.

A dialog might look like this... <alert-dialog-widget message="${data.error.message}" type="error" />

I'm assuming the widgets are properly bundled according to project needs. For instance a dialog bundle might include multiple widgets. <alert-dialog-widget message="${data.error.message}" type="error" bundle="./dialog" />

But a widget located on a CDN might look like this <widget-marko-cart bundle="http://marko-widget-cdn.org/components/shopping/">

Configuration could be passed of course <widget-marko-cart bundle="${config.roots.shopping}">

shanimal commented 8 years ago

One problem I've encountered in the past is optimizing so that you aren't loading code you already have. For instance we wouldn't need to include Marko and jQuery since we already have those.