Skip to content

Conversation

@imbstack
Copy link
Contributor

This simplifies the setup at the bottom of the main.js in our services and allows for easier requiring of components in modules that otherwise are not loaded by the loader. An example of what I want to do is:

const monitor = require('./main')('monitor').prefix('script');
monitor.info('whatever', {foo: 5});

This way we can configure monitor in one place, using configuration loaded in the same way as all of our other components but also allow people to have modules that exist outside the main.js setup.

Bugzilla Bug: 1527723

@imbstack imbstack requested review from a team and jhford as code owners February 13, 2019 22:33
Copy link
Collaborator

@djmitche djmitche left a comment

Choose a reason for hiding this comment

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

Loading is an async operation, so the suggested method of importing monitor would require an await (and thus can't be used at the module level).

Also, it seem you've removed the .catch(..) from the main.js's -- what happens if loading fails? Unless I'm missing something, maybe a fix for that is to define a sub-function that will automatically catch and handle async errors, such as load.main(process.argv[2]).

@imbstack
Copy link
Contributor Author

Ah yeah, we can do:

const loader = require('./main');
const monitor = await loader('monitor').prefix('foo');

Ah yeah, we need to catch the error because of unhandled rejection stuff. I can fix that. Does this general plan make sense though?

"dependencies": {
"assume": "^2.1.0",
"debug": "^4.1.0",
"lodash": "^4.17.11",
Copy link
Collaborator

Choose a reason for hiding this comment

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

😊

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought you might like that :)

Copy link
Collaborator

@djmitche djmitche left a comment

Choose a reason for hiding this comment

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

Yep, the overall idea makes sense!

@imbstack imbstack merged commit 016584c into master Feb 14, 2019
@imbstack imbstack deleted the bug-1527723 branch February 14, 2019 18:21
imbstack pushed a commit that referenced this pull request May 5, 2020
imbstack pushed a commit that referenced this pull request May 7, 2020
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.

5 participants