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

refact: Integrate code from utils package into optimizely-sdk #749

Merged
merged 38 commits into from
May 23, 2022

Conversation

ozayr-zaviar
Copy link
Contributor

@ozayr-zaviar ozayr-zaviar commented Mar 28, 2022

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.

@coveralls
Copy link

coveralls commented Mar 28, 2022

Coverage Status

Coverage decreased (-0.2%) to 97.021% when pulling a1a6033 on uzair/consolidate-packages into 4034c7d on master.

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.

Looks great Overall! I have a couple of requests other than the explicit comments.

  1. Can you update the copyright header wherever applicable.
  2. Please add description to the PR.

// eslint-disable-next-line @typescript-eslint/no-explicit-any
sendNotifications(notificationType: NOTIFICATION_TYPES, notificationData?: any): void
}

export default {
Copy link
Contributor

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'],
Copy link
Contributor

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

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.

This is getting really close. A couple of more changes to go.

  1. Move NotificationCenter interface and types from utils to NotificationCenter module.
  2. 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 to 2016, 2018, 2022. A file containing 2016, 2018-2021 will be changed to 2016, 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 {
Copy link
Contributor

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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

@zashraf1985
Copy link
Contributor

@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';
Copy link
Contributor

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';
Copy link
Contributor

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) {
Copy link
Contributor

@opti-jnguyen opti-jnguyen May 4, 2022

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@opti-jnguyen opti-jnguyen left a 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:

  1. Path alias implementation for utils (import "@utils").
  2. Should notificationCenter be refactored to notificationSender?
  3. utils/fns/index.ts > Is line 82's linting warning being ignored on purpose?

Items for later:

  • Consider import order linting.

@zashraf1985 zashraf1985 closed this May 9, 2022
@zashraf1985 zashraf1985 reopened this May 9, 2022
@zashraf1985 zashraf1985 reopened this May 11, 2022
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.

@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": [
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove commented code

}
})
}
/*
Copy link
Contributor

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.

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! Great work @ozayr-zaviar

Copy link
Contributor

@opti-jnguyen opti-jnguyen left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

@opti-jnguyen
Copy link
Contributor

Saw latest two commits - LGTM!

@zashraf1985 zashraf1985 changed the title refact: Integrate utils package refact: Integrate code from utils package into optimizely-sdk May 23, 2022
@zashraf1985 zashraf1985 merged commit 843c9c4 into master May 23, 2022
@zashraf1985 zashraf1985 deleted the uzair/consolidate-packages branch May 23, 2022 22:56
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.

None yet

5 participants