question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

create VS modules from factory method instead of explict creation

See original GitHub issue

What 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:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
patzickcommented, Feb 12, 2019

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.

1reaction
pkarwcommented, Feb 12, 2019

Ok that wouls be great

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why should I use a factory class instead of direct object ...
Factory classes are often implemented because they allow the project to follow the SOLID principles more closely.
Read more >
The Factory Method Pattern and Its Implementation in Python
Factory Method is a creational design pattern used to create concrete implementations of a common interface. It separates the process of creating an...
Read more >
Dependency Injection vs Factory Pattern - Stack Overflow
Factory pattern is just one way to separate the responsibility of creating objects of other classes to another entity. Factory pattern can be...
Read more >
Factory method for designing pattern - GeeksforGeeks
The factory method is a creational design pattern, i.e., related to object creation. In the Factory pattern, we create objects without exposing the...
Read more >
The Factory Method - ModernesCpp.com
The factory method defines an interface to create a single object but lets subclasses decide which objects to create. The interface can provide ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found