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

Refactoring and update of dependencied #55

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

Refactoring and update of dependencied #55

wants to merge 6 commits into from

Conversation

gustawdaniel
Copy link

Main goal of this refactoring was understanding error described in this package:

#47

and imap package

mscdex/node-imap#710

Main change is having all events in constant that are described in comments.
Meaning of error and end or close of different EventEmitter is different.
Main function of this package is mapping between different events so
having the same names was confusing. This problem was not solved and
source of ECONNRESET is still not found, but this refactor helps to deduce
that there are two options:

  • final user of this package should reset connection on error ECONNRESET in his code - we can describe it in documentation
  • socket used by imap should close connection after ECONNRESET - and this is bug of node

mscdex/node-imap#753

In official node.js docs there is written:

Usage of util.inherits() is discouraged. Please use the ES6 class and extends keywords to get language level inheritance support. Also note that the two styles are semantically incompatible.

In this commit this problem is solved. Class syntax is used and replacing prototypes.

Sources for further reading:

> https://nodejs.org/api/util.html#util_util_inherits_constructor_superconstructor
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
> nodejs/node#4179
> https://medium.com/@parsyval/javascript-prototype-vs-class-a7015d5473b
For the purpose of clarify what exactly happens in code, which events are possible, which impossible, and what it does mean there was created list of events.

It is recommended to use these constants instead of names of event in stings because it allow to differentiated between events from different sets.

For example event 'error' or 'end' can be understood differently in context of imap or notifier.
Instead of simple string in code constants wit events names are applied. It allow to differentiated between events of different objects that can have the same name. It allows to manage names of events independent to logic of code.

Sources:
Pros of this approach (in php but it desn't matter)
> https://pehapkari.cz/blog/2017/07/12/the-bulletproof-event-naming-for-symfony-event-dispatcher/
Example of merge in big js project where constants were used as names of events
> mochajs/mocha#3655

Opposed opinion (why constant is bad idea):
> https://stackoverflow.com/questions/42713927/why-arent-constants-used-for-events-in-node-js

So I invite to the discussion if you think that these changes are bad.

Why `require('events')` instead `require('events').EventEmitter`? Both forms works but proposed in this commit is now recommended and agreed in current documentation. 

Further reading:
Edit of first answer there
> https://stackoverflow.com/questions/21557369/javascript-requireevents-eventemitter
Official docs:
> https://nodejs.org/api/events.html
Code with backward compatibility
> https://github.com/nodejs/node-v0.x-archive/blob/master/lib/events.js
Changes similar to these for Imap and Notifier events.
Not all packages are updated. There is problem with mialparser. I believe it will be solved in further commits. Now there are added comments and problem is highlighted.
"imap": "~0.8.9",
"async": "^2.6.2",
"debug": "^4.1.1",
"imap": "~0.8.19",
"mailparser": "0.6.2"
Copy link

Choose a reason for hiding this comment

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

2.7.1 is latest now

Copy link
Author

Choose a reason for hiding this comment

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

I think that many of packes there was updated from time when I created this pull request.

You are invited add new pull request with updates.

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.

2 participants