create VS modules from factory method instead of explict creation
See original GitHub issueWhat is the motivation for adding / enhancing this feature?
currently every VS module is created more or less liek this
import { VueStorefrontModule, VueStorefrontModuleConfig } from '@vue-storefront/core/lib/module'
const moduleConfig: VueStorefrontModuleConfig = {
key: KEY,
store: { modules: [{ key: KEY, module }] },
}
export const Notification = new VueStorefrontModule(moduleConfig)
While it’s pretty straigtforward it has some limitations and is tied to some specific data formats and a liiiiitle bit to teh exact way we are creating them. Moreover we need to deal with 2 very similar imports which doesn’t look very elegant. If we will change the way modules are created/registered in the future it will be hard to easly make backward-compatible mechanism with any abstraction layer over object creation. This is why it’s much more future-proof, easier in understanding and maintaining to make a small abstraction layer on top of it in a form of a simple factory method so the process will look now like this:
import { createModule } from '@vue-storefront/core/lib/module'
const SomeModule = createModule({
key: KEY,
store: { modules: [{ key: KEY, module }] },
})
In module.ts
the createModule
method will be extremely straightforward but you can imagine that it can take care of some mappings in modules if their API will change so module creators don;t need to take care of this by themselves
export function createModule(config: VueStorefrontModuleConfig) {
return new VueStorefrontModule(config)
}
This feature is 100% backward-compatible since normal creation will still be working like before. It’s just an insurance to have more control over the process of creation and being bulletproof . Also migration is just a simple search & replace.
What are the acceptance criteria
- createModule method si added to
module.ts
- All VS modules are ported
- There are pull requests for all 3rd party modules
Can you complete this feature request by yourself?
Yes
Issue Analytics
- State:
- Created 5 years ago
- Comments:7
Top GitHub Comments
I think that this is cool idea:) And i was just thinking…maybe this is nice occasion to move also modules registration to theme? Different themes may need different modules, and sometimes module is needed only on specific route so for example shouldn’t be registered globally.
Ok that wouls be great