-
Notifications
You must be signed in to change notification settings - Fork 83
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
refact: Integrate code from utils
package into optimizely-sdk
#749
Conversation
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.
Looks great Overall! I have a couple of requests other than the explicit comments.
- Can you update the copyright header wherever applicable.
- Please add description to the PR.
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
sendNotifications(notificationType: NOTIFICATION_TYPES, notificationData?: any): void | ||
} | ||
|
||
export default { |
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.
Can you add the new additions to default
exports as well.
@@ -115,7 +116,7 @@ const jsonSchemaBundle = { | |||
commonjs(), | |||
typescript(typescriptPluginOptions), | |||
], | |||
external: ['json-schema', '@optimizely/js-sdk-utils'], | |||
external: ['json-schema', './lib/utils/fns', 'uuid'], |
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.
./libs/utils/fns
should not be needed as an external bundle here
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 is getting really close. A couple of more changes to go.
- Move NotificationCenter interface and types from utils to
NotificationCenter
module. - Copyright should be updated to reflect only the years in which the file was changed. For example a file containing
2016, 2018
will be changed to2016, 2018, 2022
. A file containing2016, 2018-2021
will be changed to2016, 2018-2022
. Use commas to separate the years where there is a break in between. Use dashes where there is continuity.
* - logEvent {Object} | ||
* | ||
*/ | ||
export enum NOTIFICATION_TYPES { |
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.
NOTIFICATION_TYPES and NotificationCenter interface can be moved to NotificationCenter
module?
} from '../../utils/enums'; | ||
|
||
const MODULE_NAME = 'NOTIFICATION_CENTER'; | ||
|
||
export enum NOTIFICATION_TYPES { |
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.
move this to utils/enums.ts
@@ -239,3 +245,9 @@ export class NotificationCenter { | |||
export function createNotificationCenter(options: NotificationCenterOptions): NotificationCenter { | |||
return new NotificationCenter(options); | |||
} | |||
|
|||
export interface NotificationCenter { |
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.
remove this as this interface is already available in shared_types
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.
NotificationCenter
in shared type does not have sendNotifications
function which is required in Optimizely
class. This Notification Center contains sendNotifications
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.
There has to be a name conflict because this file now exports a class and an interface both with the same name. can you fix this
@ozayr-zaviar Can you update this branch with master. Looks like there are some conflicts after you merged your GIT actions PR |
@@ -16,7 +16,7 @@ | |||
import sinon from 'sinon'; | |||
import { assert } from 'chai'; | |||
import { getLogger } from '@optimizely/js-sdk-logging'; | |||
import { sprintf } from '@optimizely/js-sdk-utils'; | |||
import { sprintf } from '../../utils/fns'; |
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.
Any thoughts on using path aliases in the optimizely-sdk/tsconfig.json file to make these imports a bit easier to read?
Example tsconfig.js:
"paths": {
"*": [ "./typings/*" ],
"@utils": [ "./lib/utils/*" ],
},
Usage:
import { sprint } from '@utils/fns'
@@ -18,26 +18,26 @@ import { | |||
EventProcessor, | |||
ProcessableEvent, | |||
} from '@optimizely/js-sdk-event-processor'; | |||
import { NotificationCenter } from '@optimizely/js-sdk-utils'; | |||
import { NotificationSender } from '../../core/notification_center'; |
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.
Same comment as above, we should consider configuring tsconfig.json to add a path alias for the utils directory.
|
||
constructor(dispatcher: EventDispatcher, notificationCenter?: NotificationCenter) { | ||
constructor(dispatcher: EventDispatcher, notificationCenter?: NotificationSender) { |
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.
Should we refactor notificationCenter
to notificationSender
?
@@ -51,6 +51,6 @@ class ForwardingEventProcessor implements EventProcessor { | |||
} | |||
} | |||
|
|||
export function createForwardingEventProcessor(dispatcher: EventDispatcher, notificationCenter?: NotificationCenter): EventProcessor { | |||
export function createForwardingEventProcessor(dispatcher: EventDispatcher, notificationCenter?: NotificationSender): EventProcessor { |
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.
Consider notificationCenter
=> notificationSender
* @param {*} value | ||
* @returns {boolean} | ||
*/ | ||
export function isValidEnum(enumToCheck: { [key: string]: any }, value: number | string): boolean { |
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.
Is the lint warning here being ignored purposefully?
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.
For now, the warning has been suppressed but the any
type will be removed in another refactor activity described in theTODO
.
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.
Items to be reviewed:
- Path alias implementation for
utils
(import "@utils"). - Should
notificationCenter
be refactored tonotificationSender
? - utils/fns/index.ts > Is line 82's linting warning being ignored on purpose?
Items for later:
- Consider import order linting.
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.
@ozayr-zaviar can you update the @utils path alias every where.. i see many files are still using ../../utls
@@ -0,0 +1,17 @@ | |||
module.exports = { | |||
// "roots": [ |
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.
Remove commented code
} | ||
}) | ||
} | ||
/* |
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.
Move these comments to notificationcenter where you moved the code that was below these comments originally.
…vascript-sdk into uzair/consolidate-packages
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! Great work @ozayr-zaviar
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 🎉
Saw latest two commits - LGTM! |
utils
package into optimizely-sdk
Summary
Integrated code from
@optimizely/js-sdk-utils
into@optimizely/optimizely-sdk
package to reduce unnecessary external dependency.Test plan
All existing unit and E2E tests pass.