Skip to content

feat: Convert event builder module to TS #680

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

Merged
merged 8 commits into from
Jun 16, 2021

Conversation

yavorona
Copy link
Contributor

@yavorona yavorona commented Jun 8, 2021

Summary

  • Convert event_builder module to TS

Test plan

Existing unit tests

@coveralls
Copy link

coveralls commented Jun 8, 2021

Coverage Status

Coverage decreased (-0.02%) to 96.976% when pulling 316d5e0 on pnguen/convert-event-builder-to-ts into f4375e9 on master.

@yavorona yavorona changed the title Pnguen/convert event builder to ts feat: Convert event builder module to TS Jun 9, 2021
};
context: EventContext;
event: {
id: string | null;
Copy link

@keppel2 keppel2 Jun 10, 2021

Choose a reason for hiding this comment

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

Could this be id?: string; ?

Copy link
Contributor Author

@yavorona yavorona Jun 10, 2021

Choose a reason for hiding this comment

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

No, it is not an optional property and can be of type string or null

Copy link
Contributor

Choose a reason for hiding this comment

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

@keppel2 you are right by intuition but JS and and TS are weird languages. id? is equivalent to string | undefined but not equivalent to string | null.

};
revenue: number | null;
value: number | null;
tags: EventTags | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

this can probably be tags?

Copy link
Contributor Author

@yavorona yavorona Jun 11, 2021

Choose a reason for hiding this comment

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

Not sure about this change. I think declaring this property as optional may not be the right way since we always pass tags to buildConversionEvent method. Its value can be of type EventTags or undefined if user does not specify it in track call. @zashraf1985 Please LMKWYT

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it makes sense. Ignore my comment on this

Comment on lines 125 to 132
const configObj = config.configObj;
const decisionObj = config.decisionObj;
const userId = config.userId;
const flagKey = config.flagKey;
const enabled = config.enabled;
const userAttributes = config.userAttributes;
const clientEngine = config.clientEngine;
const clientVersion = config.clientVersion;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const configObj = config.configObj;
const decisionObj = config.decisionObj;
const userId = config.userId;
const flagKey = config.flagKey;
const enabled = config.enabled;
const userAttributes = config.userAttributes;
const clientEngine = config.clientEngine;
const clientVersion = config.clientVersion;
const {
configObj,
decisionObj,
userId,
flagKey,
enabled,
userAttributes,
clientEngine,
clientVersion,
} = config;

* @param {ImpressionConfig} config
* @return {ImpressionEvent} an ImpressionEvent object
*/
export const buildImpressionEvent = function(config: ImpressionConfig): ImpressionEvent {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can actually destructure right here something like
function({configObj, userId .... }: ImpressionConfig)

* @param {ConversionConfig} config
* @return {ConversionEvent} a ConversionEvent object
*/
export const buildConversionEvent = function(config: ConversionConfig): ConversionEvent {
Copy link
Contributor

Choose a reason for hiding this comment

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

you can destructure config properties right here in the signature

Comment on lines 28 to 29
import { LoggerFacade } from '@optimizely/js-sdk-logging';
import { EventV1 as CommonEventParams} from '@optimizely/js-sdk-event-processor';
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably personal preference but i prefer to keep module imports above the relative ones

Comment on lines 119 to 130
function getCommonEventParams(options: ImpressionOptions | ConversionEventOptions): CommonEventParams {
const attributes = options.attributes;
const configObj = options.configObj;
const anonymize_ip = configObj.anonymizeIP ? configObj.anonymizeIP : false;
const botFiltering = configObj.botFiltering;
Copy link
Contributor

Choose a reason for hiding this comment

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

Some destructuring can probably reduce some code here too

const campaignId = experimentId ? getLayerId(configObj, experimentId) : null;

let variationKey = variationId ? getVariationKeyFromId(configObj, variationId) : null;
variationKey = variationKey ? variationKey: '';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
variationKey = variationKey ? variationKey: '';
variationKey = variationKey || '';

@yavorona yavorona removed their assignment Jun 11, 2021
@yavorona yavorona force-pushed the pnguen/convert-event-builder-to-ts branch from ba217b0 to 1c39080 Compare June 14, 2021 22:43
Copy link
Contributor

@zashraf1985 zashraf1985 left a comment

Choose a reason for hiding this comment

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

LGTM!

const ruleType = decisionObj.decisionSource;
const experimentKey = decision.getExperimentKey(decisionObj);
const variationKey = decision.getVariationKey(decisionObj);

Copy link
Contributor

Choose a reason for hiding this comment

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

Super NIT: Extra line break

@yavorona yavorona closed this Jun 16, 2021
@yavorona yavorona reopened this Jun 16, 2021
@yavorona yavorona merged commit 88fded0 into master Jun 16, 2021
@yavorona yavorona deleted the pnguen/convert-event-builder-to-ts branch June 16, 2021 22:32
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.

4 participants