-
Notifications
You must be signed in to change notification settings - Fork 83
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
Conversation
}; | ||
context: EventContext; | ||
event: { | ||
id: string | null; |
There was a problem hiding this comment.
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;
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
import { LoggerFacade } from '@optimizely/js-sdk-logging'; | ||
import { EventV1 as CommonEventParams} from '@optimizely/js-sdk-event-processor'; |
There was a problem hiding this comment.
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
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; |
There was a problem hiding this comment.
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: ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variationKey = variationKey ? variationKey: ''; | |
variationKey = variationKey || ''; |
ba217b0
to
1c39080
Compare
There was a problem hiding this 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); | ||
|
There was a problem hiding this comment.
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
Summary
event_builder
module to TSTest plan
Existing unit tests