13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- import { find , objectEntries , objectValues , sprintf , assign , keyBy } from '../utils/fns' ;
16
+ import { find , objectEntries , objectValues , sprintf , keyBy } from '../utils/fns' ;
17
17
18
18
import { ERROR_MESSAGES , LOG_LEVEL , LOG_MESSAGES , FEATURE_VARIABLE_TYPES } from '../utils/enums' ;
19
19
import configValidator from '../utils/config_validator' ;
@@ -99,27 +99,27 @@ const MODULE_NAME = 'PROJECT_CONFIG';
99
99
100
100
// eslint-disable-next-line @typescript-eslint/no-explicit-any
101
101
function createMutationSafeDatafileCopy ( datafile : any ) : ProjectConfig {
102
- const datafileCopy = assign ( { } , datafile ) ;
102
+ const datafileCopy = { ... datafile } ;
103
103
datafileCopy . audiences = ( datafile . audiences || [ ] ) . map ( ( audience : Audience ) => {
104
- return assign ( { } , audience ) ;
104
+ return { ... audience } ;
105
105
} ) ;
106
106
datafileCopy . experiments = ( datafile . experiments || [ ] ) . map ( ( experiment : Experiment ) => {
107
- return assign ( { } , experiment ) ;
107
+ return { ... experiment } ;
108
108
} ) ;
109
109
datafileCopy . featureFlags = ( datafile . featureFlags || [ ] ) . map ( ( featureFlag : FeatureFlag ) => {
110
- return assign ( { } , featureFlag ) ;
110
+ return { ... featureFlag } ;
111
111
} ) ;
112
112
datafileCopy . groups = ( datafile . groups || [ ] ) . map ( ( group : Group ) => {
113
- const groupCopy = assign ( { } , group ) ;
113
+ const groupCopy = { ... group } ;
114
114
groupCopy . experiments = ( group . experiments || [ ] ) . map ( experiment => {
115
- return assign ( { } , experiment ) ;
115
+ return { ... experiment } ;
116
116
} ) ;
117
117
return groupCopy ;
118
118
} ) ;
119
119
datafileCopy . rollouts = ( datafile . rollouts || [ ] ) . map ( ( rollout : Rollout ) => {
120
- const rolloutCopy = assign ( { } , rollout ) ;
120
+ const rolloutCopy = { ... rollout } ;
121
121
rolloutCopy . experiments = ( rollout . experiments || [ ] ) . map ( experiment => {
122
- return assign ( { } , experiment ) ;
122
+ return { ... experiment } ;
123
123
} ) ;
124
124
return rolloutCopy ;
125
125
} ) ;
@@ -148,8 +148,11 @@ export const createProjectConfig = function(datafileObj?: JSON, datafileStr: str
148
148
( projectConfig . audiences || [ ] ) . forEach ( audience => {
149
149
audience . conditions = JSON . parse ( audience . conditions as string ) ;
150
150
} ) ;
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
+ }
153
156
154
157
projectConfig . attributeKeyMap = keyBy ( projectConfig . attributes , 'key' ) ;
155
158
projectConfig . eventKeyMap = keyBy ( projectConfig . events , 'key' ) ;
@@ -159,7 +162,8 @@ export const createProjectConfig = function(datafileObj?: JSON, datafileStr: str
159
162
Object . keys ( projectConfig . groupIdMap || { } ) . forEach ( Id => {
160
163
experiments = projectConfig . groupIdMap [ Id ] . experiments ;
161
164
( experiments || [ ] ) . forEach ( experiment => {
162
- projectConfig . experiments . push ( assign ( experiment , { groupId : Id } ) ) ;
165
+ experiment . groupId = Id ;
166
+ projectConfig . experiments . push ( experiment ) ;
163
167
} ) ;
164
168
} ) ;
165
169
@@ -226,7 +230,11 @@ export const createProjectConfig = function(datafileObj?: JSON, datafileStr: str
226
230
experiment . variationKeyMap = keyBy ( experiment . variations , 'key' ) ;
227
231
228
232
// 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
+
230
238
objectValues ( experiment . variationKeyMap || { } ) . forEach ( variation => {
231
239
if ( variation . variables ) {
232
240
projectConfig . variationVariableUsageMap [ variation . id ] = keyBy ( variation . variables , 'id' ) ;
0 commit comments