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

[FSSDK-11006] remove assign function and use spreading #979

Merged
merged 3 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/core/audience_evaluator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import { getLogger } from '../../modules/logging';

import fns from '../../utils/fns';

Check warning on line 18 in lib/core/audience_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / lint

'fns' is defined but never used

Check warning on line 18 in lib/core/audience_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (20)

'fns' is defined but never used

Check warning on line 18 in lib/core/audience_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (22)

'fns' is defined but never used

Check warning on line 18 in lib/core/audience_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (18)

'fns' is defined but never used

Check warning on line 18 in lib/core/audience_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (16)

'fns' is defined but never used
import {
LOG_LEVEL,
LOG_MESSAGES,
Expand Down Expand Up @@ -44,10 +44,11 @@
* @constructor
*/
constructor(UNSTABLE_conditionEvaluators: unknown) {
this.typeToEvaluatorMap = fns.assign({}, UNSTABLE_conditionEvaluators, {
this.typeToEvaluatorMap = {
...UNSTABLE_conditionEvaluators as any,

Check warning on line 48 in lib/core/audience_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 48 in lib/core/audience_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (20)

Unexpected any. Specify a different type

Check warning on line 48 in lib/core/audience_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (22)

Unexpected any. Specify a different type

Check warning on line 48 in lib/core/audience_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type

Check warning on line 48 in lib/core/audience_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (16)

Unexpected any. Specify a different type
custom_attribute: customAttributeConditionEvaluator,
third_party_dimension: odpSegmentsConditionEvaluator,
});
};
}

/**
Expand Down Expand Up @@ -109,7 +110,7 @@
}
try {
return evaluator.evaluate(condition, user);
} catch (err: any) {

Check warning on line 113 in lib/core/audience_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 113 in lib/core/audience_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (20)

Unexpected any. Specify a different type

Check warning on line 113 in lib/core/audience_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (22)

Unexpected any. Specify a different type

Check warning on line 113 in lib/core/audience_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type

Check warning on line 113 in lib/core/audience_evaluator/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (16)

Unexpected any. Specify a different type
logger.log(
LOG_LEVEL.ERROR,
ERROR_MESSAGES.CONDITION_EVALUATOR_ERROR, MODULE_NAME, condition.type, err.message
Expand Down
2 changes: 1 addition & 1 deletion lib/core/decision_service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { LogHandler } from '../../modules/logging';
import { sprintf } from '../../utils/fns';

import fns from '../../utils/fns';

Check warning on line 19 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / lint

'fns' is defined but never used

Check warning on line 19 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (20)

'fns' is defined but never used

Check warning on line 19 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (22)

'fns' is defined but never used

Check warning on line 19 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (18)

'fns' is defined but never used

Check warning on line 19 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (16)

'fns' is defined but never used
import { bucket } from '../bucketer';
import {
AUDIENCE_EVALUATION_TYPES,
Expand Down Expand Up @@ -312,7 +312,7 @@

const userProfile = this.getUserProfile(userId) || {} as UserProfile;
const attributeExperimentBucketMap = attributes[CONTROL_ATTRIBUTES.STICKY_BUCKETING_KEY];
return fns.assign({}, userProfile.experiment_bucket_map, attributeExperimentBucketMap);
return { ...userProfile.experiment_bucket_map, ...attributeExperimentBucketMap as any };

Check warning on line 315 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 315 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (20)

Unexpected any. Specify a different type

Check warning on line 315 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (22)

Unexpected any. Specify a different type

Check warning on line 315 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type

Check warning on line 315 in lib/core/decision_service/index.ts

View workflow job for this annotation

GitHub Actions / unit_tests (16)

Unexpected any. Specify a different type
}

/**
Expand Down
34 changes: 21 additions & 13 deletions lib/project_config/project_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { find, objectEntries, objectValues, sprintf, assign, keyBy } from '../utils/fns';
import { find, objectEntries, objectValues, sprintf, keyBy } from '../utils/fns';

import { ERROR_MESSAGES, LOG_LEVEL, LOG_MESSAGES, FEATURE_VARIABLE_TYPES } from '../utils/enums';
import configValidator from '../utils/config_validator';
Expand Down Expand Up @@ -99,27 +99,27 @@ const MODULE_NAME = 'PROJECT_CONFIG';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function createMutationSafeDatafileCopy(datafile: any): ProjectConfig {
const datafileCopy = assign({}, datafile);
const datafileCopy = { ...datafile };
datafileCopy.audiences = (datafile.audiences || []).map((audience: Audience) => {
return assign({}, audience);
return { ...audience };
});
datafileCopy.experiments = (datafile.experiments || []).map((experiment: Experiment) => {
return assign({}, experiment);
return { ...experiment };
});
datafileCopy.featureFlags = (datafile.featureFlags || []).map((featureFlag: FeatureFlag) => {
return assign({}, featureFlag);
return { ...featureFlag };
});
datafileCopy.groups = (datafile.groups || []).map((group: Group) => {
const groupCopy = assign({}, group);
const groupCopy = { ...group };
groupCopy.experiments = (group.experiments || []).map(experiment => {
return assign({}, experiment);
return { ...experiment };
});
return groupCopy;
});
datafileCopy.rollouts = (datafile.rollouts || []).map((rollout: Rollout) => {
const rolloutCopy = assign({}, rollout);
const rolloutCopy = { ...rollout };
rolloutCopy.experiments = (rollout.experiments || []).map(experiment => {
return assign({}, experiment);
return { ...experiment };
});
return rolloutCopy;
});
Expand Down Expand Up @@ -148,8 +148,11 @@ export const createProjectConfig = function(datafileObj?: JSON, datafileStr: str
(projectConfig.audiences || []).forEach(audience => {
audience.conditions = JSON.parse(audience.conditions as string);
});
projectConfig.audiencesById = keyBy(projectConfig.audiences, 'id');
assign(projectConfig.audiencesById, keyBy(projectConfig.typedAudiences, 'id'));

projectConfig.audiencesById = {
...keyBy(projectConfig.audiences, 'id'),
...keyBy(projectConfig.typedAudiences, 'id'),
}

projectConfig.attributeKeyMap = keyBy(projectConfig.attributes, 'key');
projectConfig.eventKeyMap = keyBy(projectConfig.events, 'key');
Expand All @@ -159,7 +162,8 @@ export const createProjectConfig = function(datafileObj?: JSON, datafileStr: str
Object.keys(projectConfig.groupIdMap || {}).forEach(Id => {
experiments = projectConfig.groupIdMap[Id].experiments;
(experiments || []).forEach(experiment => {
projectConfig.experiments.push(assign(experiment, { groupId: Id }));
experiment.groupId = Id;
projectConfig.experiments.push(experiment);
});
});

Expand Down Expand Up @@ -226,7 +230,11 @@ export const createProjectConfig = function(datafileObj?: JSON, datafileStr: str
experiment.variationKeyMap = keyBy(experiment.variations, 'key');

// Creates { <variationId>: { key: <variationKey>, id: <variationId> } } mapping for quick lookup
assign(projectConfig.variationIdMap, keyBy(experiment.variations, 'id'));
projectConfig.variationIdMap = {
...projectConfig.variationIdMap,
...keyBy(experiment.variations, 'id')
};

objectValues(experiment.variationKeyMap || {}).forEach(variation => {
if (variation.variables) {
projectConfig.variationVariableUsageMap[variation.id] = keyBy(variation.variables, 'id');
Expand Down
17 changes: 0 additions & 17 deletions lib/utils/fns/index.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,5 @@ describe('lib/utils/fns', function() {
assert.isFalse(fns.isNumber(null));
});
});

describe('assign', function() {
it('should return empty object when target is not provided', function() {
assert.deepEqual(fns.assign(), {});
});

it('should copy correctly when Object.assign is available in environment', function() {
assert.deepEqual(fns.assign({ a: 'a'}, {b: 'b'}), { a: 'a', b: 'b' });
});

it('should copy correctly when Object.assign is not available in environment', function() {
var originalAssign = Object.assign;
Object.assign = null;
assert.deepEqual(fns.assign({ a: 'a'}, {b: 'b'}, {c: 'c'}), { a: 'a', b: 'b', c: 'c' });
Object.assign = originalAssign;
});
});
});
});
25 changes: 0 additions & 25 deletions lib/utils/fns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,6 @@ import { v4 } from 'uuid';

const MAX_SAFE_INTEGER_LIMIT = Math.pow(2, 53);

// eslint-disable-next-line
export function assign(target: any, ...sources: any[]): any {
if (!target) {
return {};
}
if (typeof Object.assign === 'function') {
return Object.assign(target, ...sources);
} else {
const to = Object(target);
for (let index = 0; index < sources.length; index++) {
const nextSource = sources[index];
if (nextSource !== null && nextSource !== undefined) {
for (const nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
}
}

export function currentTimestamp(): number {
return Math.round(new Date().getTime());
}
Expand Down Expand Up @@ -165,7 +141,6 @@ export function checkArrayEquality(arrayA: string[], arrayB: string[]): boolean
}

export default {
assign,
checkArrayEquality,
currentTimestamp,
isSafeInteger,
Expand Down
32 changes: 0 additions & 32 deletions lib/utils/local_storage/tryLocalStorage.ts

This file was deleted.

Loading