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

Refactor to ES6 #29

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

Refactor to ES6 #29

wants to merge 12 commits into from

Conversation

vellotis
Copy link

@vellotis vellotis commented Jan 5, 2017

The overall logic is mostly left in place but implemented as ES6. Babelify is used to transpile it to ES5 to make it compatible with all browsers.

Previously promises weren't used correctly. Promises by nature should support async usage. By just wrapping a synchronous logic into a new Promise(function(resolve, reject) { /* synchronous logic */ }) is not enough.

A function that is passed with the arguments resolve and reject. The executor function is executed immediately by the Promise implementation, passing resolve and reject functions (the executor is called before the Promise constructor even returns the created object).
. . .
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

One thing that this PR doesn't cover is tests. The tests have been updated to pass for given refactoring but doesn't really cover much. ie. Every plugin/extension interface should have a mock to test against. So the same test suite should be ran for all interfaces.

A downside of this PR is a size of compiled hwcrypto.js which is 39.3KB and 16.3KB for minimized version which are almost 4x bigger than for previous ES5 implementation. But I don't think it is not a problem in terms of improved and improving internet speeds.

Manually tested with following browsers:

  • Chrome 55.0.2883.87 (on Windows 7)
  • Firefox 50.1.0 (on Ubuntu 16.10)
  • Internet Explorer 11 (on Windows 7)

"modules": true
},
"rules": {
"no-console": 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

String literals instead of numeric shortcuts should be preferred.

@martinpaljak
Copy link
Contributor

martinpaljak commented Jan 5, 2017

As a general rule, moving to ES6 and especially ES6 modules is great and sensible step. Some parts of this should be revised though.

Regarding tests, a small effort was made to have browser based instrumented testing for whatever active backend someone has, but that did not really get off the ground.

export const VERSION = '0.0.10'

export const digidoc_mime = 'application/x-digidoc'
export const digidoc_chrome = 'TokenSigning'
Copy link
Contributor

Choose a reason for hiding this comment

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

These should not see light outside of their actual implementations. The idea of modules is to keep things modular and self-contained. In fact, proliferation of "digidoc" throughout the codebase should be avoided or kept minimal.

Copy link
Author

Choose a reason for hiding this comment

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

I agree.

export const NO_IMPLEMENTATION = 'no_implementation'
export const NOT_ALLOWED = 'not_allowed'

export const localServiceURL = 'https://local.ria.ee'
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here. What is local.ria.ee, "spotilocal.com"?

Copy link
Author

Choose a reason for hiding this comment

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

I agree with that as well.

Copy link
Author

Choose a reason for hiding this comment

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

Actually it is a bigger topic I would like to discuss.
Has local servlet as a pluginless backend been discussed? What are the reasons that contradict to this option?

So actually it currently should stay in a separate branch.

@vellotis vellotis force-pushed the master branch 2 times, most recently from 097815e to b9522de Compare January 6, 2017 08:40
- Promise polyfill added. PanthomJS somewhy has it missing on Windows
- Stubable mocks implemented for DigiDocPlugin and DigiDocExtension to test backend integration without needing them to be in place
- Few bugs found and fixed
# Conflicts:
#	.travis.yml
#	bower.json
#	package.json
@vellotis
Copy link
Author

Tests added for different backends.
@martinpaljak is it applicable?

@martinpaljak martinpaljak added this to the 0.1.0 milestone Jan 25, 2017
@martinpaljak
Copy link
Contributor

Looking forward, it might be best to split it into separate commits, that:

  • Move from the hybrid file to ES6 modules + webpack
  • Adds any backends
  • Deals with improving testability in a modular way.

And then separately:

  • enhances the public API with methods for querying available backends, selecting one explicitly, and using authentication

For the API enhancements, some adjustments could be made at the same go, like making it explicit that getCertificate() is supposed to read getSigningCertificate(). Also, auth() does not need certificate as an input, this is implicitly dealt by the native part and returned in the JWS token.

Whoever implements authentication, shall have to re-do quite a lot of the backend code as well, so picking up any newer API would be sensible at the same transition.

@martinpaljak
Copy link
Contributor

And maybe a little more ad-hoc "internal api" for backend integration development would be nice to have, as a set of a few developer notes.

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