Feature/hackathon may 18 migrate to es6 and make npm#1
Conversation
- Convert ES5 constructor funtion to ES6 Classes - Added JsDoc - Added JsDoc rules to eslint - Retrieve BUILD_NUMBER from package.json ( one source of truth) ( bundle tested successfully with QBO v3 on simulator )
…g package.json as source of truth - Remove DefinePligin from webpack.config, we need the build number to be available when building from connectors - Importing i18n json instead of using json-loader ( avoiding conflicts when consumed as npm package from other building strategies ) - Smoke test pass as local npm package with QBO v3 and simulator
- improve messageHandlers.wdcHandler verification, and log a message if absent - Avoid double casting in condition
- disable no-unused-vars eslint rule on 2 lines for legacy documentation purpose
…ore build and converting to es5 before uglification - convert webpack-production script to ES6 - increments minor version (temporarily, will ask for that later)
- update package.json to run make_version script with babel cli, maintaining the ´previous ux - fix missing separator on VersionNumber.toString method body
- include babel-polyfill ( let's discuss about file size, IMHO the min version has a decent size and by including it we won't care anymore about accidental introduction of unsupported features on IE and Edge ... until we deprecate support for them ) - add information "engines" property to package json
…oid polluting the test output - add NativeDispatcher unit tests
| "parser": "babel-eslint", | ||
| "extends": ["eslint:recommended", "standard"], | ||
| "rules": { | ||
| "no-console": 0, |
There was a problem hiding this comment.
unfortunately we have to leave the no-console rule set off globally because it's part of the application flow.
I'd like to improve this later.
|
Later I'll go through all the jsdocs and validate the |
whoan
left a comment
There was a problem hiding this comment.
Code looks great!
I wrote some comments to discuss further.
| * @returns {*} | ||
| */ | ||
| function _getApprovedOriginsValue () { | ||
| let result = CookiesLib.get(APPROVED_ORIGINS_KEY); |
There was a problem hiding this comment.
Is there any reason to have an assignation here? If CookiesLib.get returns a primitive type, we could avoid a copy just returning: return CookiesLib.get(APPROVED_ORIGINS_KEY);.
There was a problem hiding this comment.
Yup, good point. The 2 reasons are:
- I tried to keep things as less modified as possible
- Probably the original code's intent was to have a potential breakpoint for debugging
| return []; | ||
| } | ||
| /** | ||
| * Adds an approved origins to the list already saved in a session cookie |
| // pass along the output of the private function | ||
| return _saveApprovedOrigins(origins); | ||
| } | ||
|
|
There was a problem hiding this comment.
It might be better to return something to comply with the JSDoc (or change the JSDoc which I know is a pending task)
There was a problem hiding this comment.
you're right, I'll change it to {Object|Undefined}
|
|
||
| let originsString = _getApprovedOriginsValue(); | ||
|
|
||
| if (!originsString || originsString.length === 0) { |
There was a problem hiding this comment.
It seems like originsString.length === 0 is redundant here
There was a problem hiding this comment.
yup, same thing here, just trying to keep as much as possible untouched
| compare (other) { | ||
| let majorDiff = this.major - other.major; | ||
| let minorDiff = this.minor - other.minor; | ||
| let fixDiff = this.patch - other.fix; |
There was a problem hiding this comment.
Do we have a copy paste error here? patch vs fix.
There was a problem hiding this comment.
Nope, patch is the correct definition for the third number on the semver definition, I left the fix word for the input to ask Ben about that, I'd go for both to be patch for consistency
| * @returns {String} | ||
| */ | ||
| export function getBuildNumber ({ showLog = false } = {}) { | ||
| // Grab the version number from the package json property ( one static source of truth ) |
There was a problem hiding this comment.
Does it miss some code here? It is not clear how the version number is retrieved.
There was a problem hiding this comment.
you're right, it's explaining the BUILD_NUMBER constant origin, but it's not clear, I'll improve it
| _triggerDataGathering (tablesAndIncrementValues) { | ||
|
|
||
| if (tablesAndIncrementValues.length !== 1) { | ||
| throw new Error(`Unexpected number of tables specified. Expected 1, actual ${tablesAndIncrementValues.length.toString()}`); |
There was a problem hiding this comment.
In ${tablesAndIncrementValues.length.toString()}, the .toString() is not necessary anymore
| throw new Error(`Unexpected number of tables specified. Expected 1, actual ${tablesAndIncrementValues.length.toString()}`); | ||
| } | ||
|
|
||
| let tableAndIncremntValue = tablesAndIncrementValues[0]; |
There was a problem hiding this comment.
There is a small typo in the variable name: tableAndIncremntValue (misses an e)
whoan
left a comment
There was a problem hiding this comment.
Great job, the code is very clear.
I added some comments about minor things like typos in comments and alike.
| if (typeof src[key] === 'function') { | ||
| dest[key] = src[key]; | ||
| /** | ||
| * WARNIG - copies are BY REFERENCE |
| // note: add boolean return for testing purpose | ||
|
|
||
| // Do some quick validation that this data is the format we expect | ||
| // is this validation enought? shouldn't we throw an error? (Jax) |
|
|
||
| if (!Array.isArray(data)) { | ||
| // Log a warning because the data is not an array like we expected | ||
| // is this validation enought? shouldn't we throw an error? (Jax) |
|
|
||
| describe('UNIT - Utilities', () => { | ||
|
|
||
| it('copyFunctions to copy funtions from source to target', () => { |
| import fs from 'fs-extra'; | ||
| import path from 'path'; | ||
|
|
||
| let execSync = require('child_process').execSync; |
| let versionNumber = new VersionNumber(getBuildNumber()); | ||
|
|
||
| // Build up the name for the regular and minified versions of the file | ||
| let fullVersionName = `${WDC_LIB_PREFIX}${versionNumber.toString()}`; |
There was a problem hiding this comment.
I think toString() wouldn't be necessary here
There was a problem hiding this comment.
is necessary because it's calling the toString() met6hod of the class explicitly .... you never know :P
| import SimulatorDispatcher from './SimulatorDispatcher'; | ||
| import { getBuildNumber } from './DevUtils/BuildNumber'; | ||
|
|
||
| let qwebchannel = require('qwebchannel'); |
| if (runningOnTableau()) { | ||
| // Running on Tableau | ||
| // We have the tableau object defined | ||
| console.log(`Initializing NativeDispatcher, Reporting version number`); |
There was a problem hiding this comment.
Just FYI, I've seen it's better to not use String templates when not needed, but I think it's a matter of tastes though.
| @@ -0,0 +1,12 @@ | |||
| import webpack from 'webpack'; | |||
There was a problem hiding this comment.
I am pretty sure we can do tree shaking here.
- add @see links to online documentation for SImulator and Native dispatchers - add some tweaks to linting rules
@benlower and @LGraber : This pull request is merely informative, any feedback is hugely welcome. The merging target is sill OUR FORK, we need to talk and discuss before considering it for targeting the official repo.
Notes:
Since we don’t have Samm and Brendan maintaining the shim, and is a critical piece of code for our wdc’s I took the initiative to fork it and make this changes as a POC to match our development standards, this way might gain more collaborators.
I'd be great to define more specific tests:
Tested this with local Anaplan connector as a standalone lib and with local QBO as part of the connector’s build, both in the simulator and Tableau desktop 10.5