Skip to content

Commit 1adcbdb

Browse files
authored
[FSSDK-11006] remove assign function and use spreading (#979)
1 parent 787fbc0 commit 1adcbdb

File tree

6 files changed

+25
-90
lines changed

6 files changed

+25
-90
lines changed

lib/core/audience_evaluator/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ export class AudienceEvaluator {
4444
* @constructor
4545
*/
4646
constructor(UNSTABLE_conditionEvaluators: unknown) {
47-
this.typeToEvaluatorMap = fns.assign({}, UNSTABLE_conditionEvaluators, {
47+
this.typeToEvaluatorMap = {
48+
...UNSTABLE_conditionEvaluators as any,
4849
custom_attribute: customAttributeConditionEvaluator,
4950
third_party_dimension: odpSegmentsConditionEvaluator,
50-
});
51+
};
5152
}
5253

5354
/**

lib/core/decision_service/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ export class DecisionService {
312312

313313
const userProfile = this.getUserProfile(userId) || {} as UserProfile;
314314
const attributeExperimentBucketMap = attributes[CONTROL_ATTRIBUTES.STICKY_BUCKETING_KEY];
315-
return fns.assign({}, userProfile.experiment_bucket_map, attributeExperimentBucketMap);
315+
return { ...userProfile.experiment_bucket_map, ...attributeExperimentBucketMap as any };
316316
}
317317

318318
/**

lib/project_config/project_config.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { find, objectEntries, objectValues, sprintf, assign, keyBy } from '../utils/fns';
16+
import { find, objectEntries, objectValues, sprintf, keyBy } from '../utils/fns';
1717

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

100100
// eslint-disable-next-line @typescript-eslint/no-explicit-any
101101
function createMutationSafeDatafileCopy(datafile: any): ProjectConfig {
102-
const datafileCopy = assign({}, datafile);
102+
const datafileCopy = { ...datafile };
103103
datafileCopy.audiences = (datafile.audiences || []).map((audience: Audience) => {
104-
return assign({}, audience);
104+
return { ...audience };
105105
});
106106
datafileCopy.experiments = (datafile.experiments || []).map((experiment: Experiment) => {
107-
return assign({}, experiment);
107+
return { ...experiment };
108108
});
109109
datafileCopy.featureFlags = (datafile.featureFlags || []).map((featureFlag: FeatureFlag) => {
110-
return assign({}, featureFlag);
110+
return { ...featureFlag };
111111
});
112112
datafileCopy.groups = (datafile.groups || []).map((group: Group) => {
113-
const groupCopy = assign({}, group);
113+
const groupCopy = { ...group };
114114
groupCopy.experiments = (group.experiments || []).map(experiment => {
115-
return assign({}, experiment);
115+
return { ...experiment };
116116
});
117117
return groupCopy;
118118
});
119119
datafileCopy.rollouts = (datafile.rollouts || []).map((rollout: Rollout) => {
120-
const rolloutCopy = assign({}, rollout);
120+
const rolloutCopy = { ...rollout };
121121
rolloutCopy.experiments = (rollout.experiments || []).map(experiment => {
122-
return assign({}, experiment);
122+
return { ...experiment };
123123
});
124124
return rolloutCopy;
125125
});
@@ -148,8 +148,11 @@ export const createProjectConfig = function(datafileObj?: JSON, datafileStr: str
148148
(projectConfig.audiences || []).forEach(audience => {
149149
audience.conditions = JSON.parse(audience.conditions as string);
150150
});
151-
projectConfig.audiencesById = keyBy(projectConfig.audiences, 'id');
152-
assign(projectConfig.audiencesById, keyBy(projectConfig.typedAudiences, 'id'));
151+
152+
projectConfig.audiencesById = {
153+
...keyBy(projectConfig.audiences, 'id'),
154+
...keyBy(projectConfig.typedAudiences, 'id'),
155+
}
153156

154157
projectConfig.attributeKeyMap = keyBy(projectConfig.attributes, 'key');
155158
projectConfig.eventKeyMap = keyBy(projectConfig.events, 'key');
@@ -159,7 +162,8 @@ export const createProjectConfig = function(datafileObj?: JSON, datafileStr: str
159162
Object.keys(projectConfig.groupIdMap || {}).forEach(Id => {
160163
experiments = projectConfig.groupIdMap[Id].experiments;
161164
(experiments || []).forEach(experiment => {
162-
projectConfig.experiments.push(assign(experiment, { groupId: Id }));
165+
experiment.groupId = Id;
166+
projectConfig.experiments.push(experiment);
163167
});
164168
});
165169

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

228232
// Creates { <variationId>: { key: <variationKey>, id: <variationId> } } mapping for quick lookup
229-
assign(projectConfig.variationIdMap, keyBy(experiment.variations, 'id'));
233+
projectConfig.variationIdMap = {
234+
...projectConfig.variationIdMap,
235+
...keyBy(experiment.variations, 'id')
236+
};
237+
230238
objectValues(experiment.variationKeyMap || {}).forEach(variation => {
231239
if (variation.variables) {
232240
projectConfig.variationVariableUsageMap[variation.id] = keyBy(variation.variables, 'id');

lib/utils/fns/index.tests.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,5 @@ describe('lib/utils/fns', function() {
8484
assert.isFalse(fns.isNumber(null));
8585
});
8686
});
87-
88-
describe('assign', function() {
89-
it('should return empty object when target is not provided', function() {
90-
assert.deepEqual(fns.assign(), {});
91-
});
92-
93-
it('should copy correctly when Object.assign is available in environment', function() {
94-
assert.deepEqual(fns.assign({ a: 'a'}, {b: 'b'}), { a: 'a', b: 'b' });
95-
});
96-
97-
it('should copy correctly when Object.assign is not available in environment', function() {
98-
var originalAssign = Object.assign;
99-
Object.assign = null;
100-
assert.deepEqual(fns.assign({ a: 'a'}, {b: 'b'}, {c: 'c'}), { a: 'a', b: 'b', c: 'c' });
101-
Object.assign = originalAssign;
102-
});
103-
});
10487
});
10588
});

lib/utils/fns/index.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,6 @@ import { v4 } from 'uuid';
1717

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

20-
// eslint-disable-next-line
21-
export function assign(target: any, ...sources: any[]): any {
22-
if (!target) {
23-
return {};
24-
}
25-
if (typeof Object.assign === 'function') {
26-
return Object.assign(target, ...sources);
27-
} else {
28-
const to = Object(target);
29-
for (let index = 0; index < sources.length; index++) {
30-
const nextSource = sources[index];
31-
if (nextSource !== null && nextSource !== undefined) {
32-
for (const nextKey in nextSource) {
33-
// Avoid bugs when hasOwnProperty is shadowed
34-
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
35-
to[nextKey] = nextSource[nextKey];
36-
}
37-
}
38-
}
39-
}
40-
return to;
41-
}
42-
}
43-
4420
export function currentTimestamp(): number {
4521
return Math.round(new Date().getTime());
4622
}
@@ -165,7 +141,6 @@ export function checkArrayEquality(arrayA: string[], arrayB: string[]): boolean
165141
}
166142

167143
export default {
168-
assign,
169144
checkArrayEquality,
170145
currentTimestamp,
171146
isSafeInteger,

lib/utils/local_storage/tryLocalStorage.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)