Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/replace injector pattern with modules #85

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mmnathan
Copy link

@mmnathan mmnathan commented Nov 8, 2018

Replaced the injector pattern with default exports and removed injector related files. export default getX => x now becomes export default x and the get/setValue(enum) injectors are removed.

import routes from './routes';

Vue.use(VueRouter);

let router = null;

const getRouter = () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you aware that you are changing the behaviour of the running code with this change(s)?
Previously, the code in this function would only be executed when first called. Now it's executed when required (first thing). So will loose some control.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that the behaviour is changed but not how it affects the implementation, do you have an example of lost control?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say the router setup needs a value that is set in another file. You would like to control the order of how things are executed. Having to rely on changing the import order to (hopefully) change the order of execution is error-prone and unclear.
Explicitly calling functions to specify the order of execution gives you more control.

const configManager = new ConfigManager();
configManager.init(config.config, config.environment);

export default configManager;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this file located in the util folder and not in the config folder?

Copy link
Author

@mmnathan mmnathan Nov 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. It used to be created and registered in util/setupInjects.js, I’ve separated the ‘injectables’ into separate files but felt relocating/refactoring should be another issue.

@ThaNarie
Copy link

ThaNarie commented Nov 8, 2018

Keep in mind that when using default exports, you cannot really unit test files that import those if you need to mock them (unless you have require hooks).

@@ -1,6 +1,4 @@
const Params = {
export default {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had all enums like this in vue skeleton but after a comment of Narie we changed it to the const with the seperate export default. It had something to do with webstorm. I am not a big fan of a direct export default. I almost always use the const with the separate export default. So when you read the code you understand what is exported. In this case you have to look at the filename but doesn't always work because you can have multiple exports in one file.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, webstorm has/d better autocomplete / autoimport if the const has the same name as the file/import name.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point on the autocompletion, I did not consider this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants