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/hackathon may 18 migrate to es6 and make npm #1

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from

Conversation

Jaxolotl
Copy link

@Jaxolotl Jaxolotl commented May 15, 2018

@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.

  • Migrate the code to ES6
  • Make it an NPM private package to be consumed by our new connectors and built together with the connector’s code
  • Keep backwards compat to be able to generate the builds the old style and publish them for public consumption ( the npm script calls remain the same )
  • Add Linting validation as a build contract (must pass to build )
  • Add unit tests ( added some, more to come)
  • Add integration tests (TBD)
  • Deploy and publish using Travis CI (TBD)
  • Add JsDoc to all documentable methods and props ( need some refinement here yet )

I'd be great to define more specific tests:

  • Automated tests using our automation framework and consuming generic tests
  • Version targeted test ( testing shim against specific tableau versions based on support rules )
  • Testing browser compatibility for all versions
  • Create integration tests to match the Bridge behavior
  • Improve shim test-ability ( several methods just pass the ball to the bridge, or to another layer, but they don't communicate the success/failure status, and they don't even return a value )
  • Improve predict-ability ( some async methods just call setTimeout but there's no way to programatically verify the fulfillment or rejection. Implementing promises there, will significantly improve the usability and the error handling )

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

Jaxolotl added 15 commits May 8, 2018 11:33
- 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,
Copy link
Author

Choose a reason for hiding this comment

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

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.

@Jaxolotl
Copy link
Author

Jaxolotl commented May 15, 2018

Later I'll go through all the jsdocs and validate the @params and @returns tags against the API reference and also adding the @see tag with the link to the method documentation

@Jaxolotl Jaxolotl requested a review from sblasetti May 15, 2018 14:17
Copy link

@whoan whoan left a comment

Choose a reason for hiding this comment

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

Code looks great!
I wrote some comments to discuss further.

* @returns {*}
*/
function _getApprovedOriginsValue () {
let result = CookiesLib.get(APPROVED_ORIGINS_KEY);
Copy link

Choose a reason for hiding this comment

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

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);.

Copy link
Author

Choose a reason for hiding this comment

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

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
Copy link

Choose a reason for hiding this comment

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

I think origins should be singular

Copy link
Author

Choose a reason for hiding this comment

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

good catch

Copy link
Author

Choose a reason for hiding this comment

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

done


// pass along the output of the private function
return _saveApprovedOrigins(origins);
}

Copy link

Choose a reason for hiding this comment

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

It might be better to return something to comply with the JSDoc (or change the JSDoc which I know is a pending task)

Copy link
Author

@Jaxolotl Jaxolotl May 16, 2018

Choose a reason for hiding this comment

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

you're right, I'll change it to {Object|Undefined}

Copy link
Author

Choose a reason for hiding this comment

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

done


let originsString = _getApprovedOriginsValue();

if (!originsString || originsString.length === 0) {
Copy link

Choose a reason for hiding this comment

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

It seems like originsString.length === 0 is redundant here

Copy link
Author

Choose a reason for hiding this comment

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

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;
Copy link

Choose a reason for hiding this comment

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

Do we have a copy paste error here? patch vs fix.

Copy link
Author

Choose a reason for hiding this comment

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

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

Copy link
Author

Choose a reason for hiding this comment

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

changed

*/
export function getBuildNumber ({ showLog = false } = {}) {
// Grab the version number from the package json property ( one static source of truth )
Copy link

Choose a reason for hiding this comment

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

Does it miss some code here? It is not clear how the version number is retrieved.

Copy link
Author

Choose a reason for hiding this comment

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

you're right, it's explaining the BUILD_NUMBER constant origin, but it's not clear, I'll improve it

Copy link
Author

Choose a reason for hiding this comment

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

done

Shared.js Outdated
_triggerDataGathering (tablesAndIncrementValues) {

if (tablesAndIncrementValues.length !== 1) {
throw new Error(`Unexpected number of tables specified. Expected 1, actual ${tablesAndIncrementValues.length.toString()}`);
Copy link

Choose a reason for hiding this comment

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

In ${tablesAndIncrementValues.length.toString()}, the .toString() is not necessary anymore

Copy link
Author

Choose a reason for hiding this comment

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

done

Shared.js Outdated
throw new Error(`Unexpected number of tables specified. Expected 1, actual ${tablesAndIncrementValues.length.toString()}`);
}

let tableAndIncremntValue = tablesAndIncrementValues[0];
Copy link

Choose a reason for hiding this comment

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

There is a small typo in the variable name: tableAndIncremntValue (misses an e)

Copy link
Author

Choose a reason for hiding this comment

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

done

Copy link

@whoan whoan left a comment

Choose a reason for hiding this comment

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

Great job, the code is very clear.
I added some comments about minor things like typos in comments and alike.

Utilities.js Outdated
if (typeof src[key] === 'function') {
dest[key] = src[key];
/**
* WARNIG - copies are BY REFERENCE
Copy link

Choose a reason for hiding this comment

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

Small typo here

Copy link
Author

Choose a reason for hiding this comment

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

done

Table.js Outdated
// 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)
Copy link

Choose a reason for hiding this comment

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

Small typo in this comment

Copy link
Author

Choose a reason for hiding this comment

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

ohhh enought -> enough

Copy link
Author

Choose a reason for hiding this comment

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

done

Table.js Outdated

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)
Copy link

Choose a reason for hiding this comment

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

Copied typo here


describe('UNIT - Utilities', () => {

it('copyFunctions to copy funtions from source to target', () => {
Copy link

Choose a reason for hiding this comment

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

Small typo in funtions

Copy link
Author

Choose a reason for hiding this comment

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

done

import fs from 'fs-extra';
import path from 'path';

let execSync = require('child_process').execSync;
Copy link

Choose a reason for hiding this comment

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

Wasn't it possible to import here?

Copy link
Author

Choose a reason for hiding this comment

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

I didn't even try, will do

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()}`;
Copy link

Choose a reason for hiding this comment

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

I think toString() wouldn't be necessary here

Copy link
Author

Choose a reason for hiding this comment

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

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');
Copy link

Choose a reason for hiding this comment

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

Can't it go an import here?

if (runningOnTableau()) {
// Running on Tableau
// We have the tableau object defined
console.log(`Initializing NativeDispatcher, Reporting version number`);
Copy link

Choose a reason for hiding this comment

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

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';
Copy link

Choose a reason for hiding this comment

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

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
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