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

Set user #52

Merged
merged 6 commits into from
Aug 29, 2019
Merged

Set user #52

merged 6 commits into from
Aug 29, 2019

Conversation

M-OC
Copy link
Contributor

@M-OC M-OC commented Aug 29, 2019

  • extracts types, constants into separate files
  • extracts 'track', 'getPropertyId' and some minor methods into separate files
  • check for 'propertyId' no longer occurs within 'track' method
  • 'setUser' no longer accepts 'undefined'
  • 'setUser' now accepts {user: {email: 'foo'}} and {email: 'foo'}

@@ -420,7 +420,7 @@ module.exports = {
'import/exports-last': 'off',
'import/group-exports': 'off',
'import/no-cycle': 'error',
'import/no-default-export': 'error',
'import/no-default-export': 'off',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We were already ignoring this rule elsewhere.

@@ -1,5 +1,5 @@
/* @flow */

import type { MuseGlobalType } from './types';
import type { MuseGlobalType } from './lib/types';
Copy link
Contributor

Choose a reason for hiding this comment

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

would it make sense to create a types folder and put MuseGlobalType in index.js for now until we have more types? When I think about lib usually I think helper libraries and things like that. I think types should be in a folder of its own.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, but I'd prefer to do that + additional refactoring in another PR if possible.

src/lib/track.js Outdated
// remove null, undefined values
user.id || delete user.id
user.email || delete user.email
user.name || delete user.name
Copy link
Contributor Author

@M-OC M-OC Aug 29, 2019

Choose a reason for hiding this comment

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

The 'delete' statements above are new. The rest of this method is unchanged.

@@ -0,0 +1,33 @@
import { getClientID, getMerchantID } from '@paypal/sdk-client/src';

export const getPropertyId = ({ paramsToPropertyIdUrl }) => {
Copy link
Contributor Author

@M-OC M-OC Aug 29, 2019

Choose a reason for hiding this comment

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

This method is unchanged.

@@ -26,3 +33,39 @@ export const removeFromCart = (items, currentItems = []) => {
export const addToCart = (items, currentItems = []) => {
return [ ...currentItems, ...items ];
};
// $FlowFixMe
export const composeCart = (type, data) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method now uses 'constants' imported above. Otherwise unchanged.

@@ -21,3 +22,12 @@ export const setCookie = (cookieName : string, cookieValue : string, expirationM
const expires = `expires=${ d.toUTCString() }`;
document.cookie = `${ cookieName }=${ cookieValue }; Path=/; ${ expires }`;
};

export const getUserIdCookie = () : ?string => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These methods were removed from 'tracker-component'. They have not been altered. (note: ONE_MONTH_IN_MILLISECONDS should probably be in constants)

@@ -0,0 +1,16 @@
/* @flow */
export default {
'sevenDays': 6.048e+8,
Copy link
Contributor

@songz songz Aug 29, 2019

Choose a reason for hiding this comment

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

Personally, (nitpick) I think its easier to understand if you wrote it like this: sevenDays: 7*24*60*60*1000

😆

src/lib/track.js Outdated
};

// remove null, undefined values
user.id || delete user.id
Copy link
Contributor

Choose a reason for hiding this comment

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

this is impossible right? Because right above you are setting userIdCookie

src/lib/track.js Outdated
// remove null, undefined values
user.id || delete user.id
user.email || delete user.email
user.name || delete user.name
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought setting email and name field to null or '' will reset it on our back end? We want these values to get passed down the pipeline to get processed as is, so maybe we should not delete these fields?

accessTokenUrl,
storage,
defaultTrackerConfig
} = constants;
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 import { accessokenUrl .... } from './lib/constants'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Each key would have to be exported separately in that case.

const track = <T>(config : Config, trackingType : TrackingType, trackingData : T) => {
export const clearTrackQueue = (config : Config) => {
// $FlowFixMe
return trackEventQueue.filter(([ trackingType, trackingData ]) => { // eslint-disable-line array-callback-return
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: much cleaner to use a forEach and then return [] imo

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. This was Zach's original implementation, and looks like it's just moved in the file. Maybe we can add a TODO instead to change this method?

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

export const clearTrackQueue = (config : Config) => {
// $FlowFixMe
return trackEventQueue.filter(([ trackingType, trackingData ]) => { // eslint-disable-line array-callback-return
track(config, trackingType, trackingData);
Copy link
Contributor

Choose a reason for hiding this comment

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

question, does track also fire off JL events?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It uses a different 'tracker' method. See "trackEventByType" & "getJetlore".

Copy link
Contributor

Choose a reason for hiding this comment

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

#53

Copy link
Contributor

@joshbeam joshbeam left a comment

Choose a reason for hiding this comment

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

Good refactor, thanks for all the comments explaining the code. After we merge this, let's do a full E2E of all the methods.

const track = <T>(config : Config, trackingType : TrackingType, trackingData : T) => {
export const clearTrackQueue = (config : Config) => {
// $FlowFixMe
return trackEventQueue.filter(([ trackingType, trackingData ]) => { // eslint-disable-line array-callback-return
Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. This was Zach's original implementation, and looks like it's just moved in the file. Maybe we can add a TODO instead to change this method?

@M-OC M-OC force-pushed the setUser branch 2 times, most recently from 20c5154 to 5670038 Compare August 29, 2019 21:27
@M-OC M-OC merged commit 17a5dd9 into paypal:2.0 Aug 29, 2019
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.

3 participants