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

rewrite shisell in typescript #36

Merged
merged 19 commits into from
Oct 15, 2018
Merged

rewrite shisell in typescript #36

merged 19 commits into from
Oct 15, 2018

Conversation

nataly87s
Copy link
Contributor

@nataly87s nataly87s commented Oct 4, 2018

  • rewrote the package in typescript
  • added missing tests (currently 100% coverage)
  • set up multiple build targets (cjs, es5, es2015, umd)

@nataly87s nataly87s requested a review from AvivRubys October 4, 2018 12:56
@nataly87s nataly87s force-pushed the typescript branch 3 times, most recently from 021334d to 92d41d9 Compare October 5, 2018 10:35
Copy link
Contributor

@AvivRubys AvivRubys left a comment

Choose a reason for hiding this comment

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

Looks good generally, mostly nitpicking stuff.
However, I couldn't get any of the subpackages (filters, extenders, writers) to work in node, I think there need to be writers.js etc files in the published package for that to work.
Also - both src and tools folders are included in the package, is this on purpose? If so, the .d.ts files are not really needed - we can just direct typings to the ts source code.

.npmignore Outdated
@@ -1,8 +1,12 @@
.idea
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this was preexisting, but with al the stuff we're adding here - what do you think of using package.json's files as a whitelist instead of this blacklist?

readonly context: AnalyticsContext = new AnalyticsContext(),
) {}

dispatch = (eventName: string = '', analyticsContext?: AnalyticsContext): T => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are dispatch and extend arrow functions instead of methods on purpose? Dispatchers are created a lot of times, this will cause each of them to create a new function

return this;
}

const union = new AnalyticsContext();
Copy link
Contributor

Choose a reason for hiding this comment

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

This bit of code is clever, but hard to read and throws type safety out the window.
Feels to me like this was far easier to understand and just as good: https://github.com/Soluto/shisell-js/blob/master/lib/AnalyticsDispatcher.js#L13

return !!obj && typeof obj === 'object' && !Array.isArray(obj);
}

export function isArray(arr: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just Array.isArray?

import {withContext} from './withContext';

export function withExtras(extras: DataMap) {
if (!isObject(extras)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like an error for sure, it's worth writing a log about it (in development mode)
Same for withIdentities/withFilters

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's the previous behavior. if it were up to me I would throw an exception here

return x;
}

export function isObject(obj: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

User-defined type guards were made to be used in this file 😄
Also, unknown fits better here then any.

build.sh Outdated

rm -rf dist

yarn tsc -d
Copy link
Contributor

@AvivRubys AvivRubys Oct 8, 2018

Choose a reason for hiding this comment

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

Why not add tslib dependency and use importHelpers? This way we don't need to emit async await etc helpers in the library.

@nataly87s nataly87s merged commit b43c12a into master Oct 15, 2018
@nataly87s nataly87s deleted the typescript branch October 15, 2018 06:50
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