[ RFC ] Improved modules API
See original GitHub issueWhat is the motivation for adding / enhancing this feature?
Current modules API is a huge milestone in VS history but still pretty limited. The goal of this transformation is to cut off those limits.
The biggest limitations are
- inability to load modules lazily in easy way
- modules merging during runtime process (old and new module are landing in final bundle) - still need to figure it out and it’s probably a case for another issue
The goal of the solution is to solve those two problems while not changing any currently existing module from the inside. In other words this change should be handled purely on Vue Storefront level so there are no changes needed in any of currently existing modules.
Solution
To allow lazy loading of modules and better error handling we should put an abstraction layer on top of Vuex (similar to router manager). I was trying to do it seamlessly as a proxy (see reference) but it turned out to be impossible. To use any of the modules the module object needs to be called directly which should enable seamless lazy loading, autocompletion and better error handling
//somewhere in code
const CatalogModule = () => import('@vue-storefront/catalog')
CatalogModule.dispatch('actionName', payload)
We will also depreciate old root registration in index.ts
and extendModule
method in favor of VueStorefrontModule.extend()
so everything is encapsulated.
This is something I would like to do during Christmas break.
Ofc everything will be backward comaptible and for next 3 major versions you could still use old way of registering and using modules.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (1 by maintainers)
Top GitHub Comments
This is awesome. How about adding the module hooks by this chance? I mean hooks like: afterApplicationLoaded, afterStoreviewChanged (there were few cases we encountered with @patzick thay there’s is no entry point for applying some business logic once the proper store view is loaded)? I think it would be great to use similar approach like Nuxt has and set the fixed set of endpoints; current set is too limited I belive
While we are here, would be nice to add dependency checking between vsf modules. I.e. if there is a checkout module, build process should check if the cart module is being loaded as well. We would probably want also to have control over which modules load first based on something else than alphabetic order.