@hackler/react-sdk 11.9.0 → 11.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Context.d.ts +2 -4
- package/lib/Context.d.ts.map +1 -1
- package/lib/Provider.d.ts +2 -2
- package/lib/Provider.d.ts.map +1 -1
- package/lib/client.d.ts +19 -7
- package/lib/client.d.ts.map +1 -1
- package/lib/config.d.ts +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/emitter.d.ts +11 -0
- package/lib/emitter.d.ts.map +1 -0
- package/lib/hooks.d.ts.map +1 -1
- package/lib/index.es.js +174 -82
- package/lib/index.js +174 -82
- package/lib/index.umd.js +1 -1
- package/lib/utils.d.ts +9 -0
- package/lib/utils.d.ts.map +1 -0
- package/package.json +2 -2
- package/CHANGELOG.md +0 -6
package/lib/index.js
CHANGED
|
@@ -43,6 +43,22 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
43
43
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
44
44
|
PERFORMANCE OF THIS SOFTWARE.
|
|
45
45
|
***************************************************************************** */
|
|
46
|
+
/* global Reflect, Promise */
|
|
47
|
+
|
|
48
|
+
var extendStatics = function(d, b) {
|
|
49
|
+
extendStatics = Object.setPrototypeOf ||
|
|
50
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
51
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
52
|
+
return extendStatics(d, b);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function __extends(d, b) {
|
|
56
|
+
if (typeof b !== "function" && b !== null)
|
|
57
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
58
|
+
extendStatics(d, b);
|
|
59
|
+
function __() { this.constructor = d; }
|
|
60
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
61
|
+
}
|
|
46
62
|
|
|
47
63
|
var __assign = function() {
|
|
48
64
|
__assign = Object.assign || function __assign(t) {
|
|
@@ -73,32 +89,114 @@ function __read(o, n) {
|
|
|
73
89
|
}
|
|
74
90
|
|
|
75
91
|
var SDK_NAME_HEADER = "react-sdk";
|
|
76
|
-
var SDK_VERSION_HEADER = "11.
|
|
92
|
+
var SDK_VERSION_HEADER = "11.10.0";
|
|
93
|
+
|
|
94
|
+
var Emitter = /** @class */ (function () {
|
|
95
|
+
function Emitter() {
|
|
96
|
+
this.listeners = {};
|
|
97
|
+
}
|
|
98
|
+
Emitter.prototype.on = function (eventName, fn) {
|
|
99
|
+
this.listeners[eventName] = (this.listeners[eventName] || []).concat(fn);
|
|
100
|
+
};
|
|
101
|
+
Emitter.prototype.off = function (eventName, fn) {
|
|
102
|
+
this.listeners[eventName] = (this.listeners[eventName] || []).filter(function (f) { return f !== fn; });
|
|
103
|
+
};
|
|
104
|
+
Emitter.prototype.emit = function (eventName, params) {
|
|
105
|
+
(this.listeners[eventName] || []).forEach(function (fn) {
|
|
106
|
+
fn(params);
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
return Emitter;
|
|
110
|
+
}());
|
|
77
111
|
|
|
78
|
-
var
|
|
112
|
+
var ObjectUtil = /** @class */ (function () {
|
|
113
|
+
function ObjectUtil() {
|
|
114
|
+
}
|
|
115
|
+
ObjectUtil.arePropertiesEqual = function (prevProps, currentProps) {
|
|
116
|
+
var prev = ObjectUtil.coerceUnknownToProperties(prevProps);
|
|
117
|
+
var current = ObjectUtil.coerceUnknownToProperties(currentProps);
|
|
118
|
+
var prevKeys = Object.keys(prev);
|
|
119
|
+
var currentKeys = Object.keys(current);
|
|
120
|
+
if (prevKeys.length !== currentKeys.length) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
return prevKeys.every(function (it) {
|
|
124
|
+
// @ts-ignore
|
|
125
|
+
return it in current && prev[it] === current[it];
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
ObjectUtil.coerceUnknownToProperties = function (props) {
|
|
129
|
+
if (typeof props === "object" && props !== null) {
|
|
130
|
+
return props;
|
|
131
|
+
}
|
|
132
|
+
return {};
|
|
133
|
+
};
|
|
134
|
+
return ObjectUtil;
|
|
135
|
+
}());
|
|
136
|
+
var UserUtil = /** @class */ (function () {
|
|
137
|
+
function UserUtil() {
|
|
138
|
+
}
|
|
139
|
+
UserUtil.isUserEqual = function (prevUser, currentUser) {
|
|
140
|
+
return ((prevUser === null || prevUser === void 0 ? void 0 : prevUser.id) === (currentUser === null || currentUser === void 0 ? void 0 : currentUser.id) &&
|
|
141
|
+
(prevUser === null || prevUser === void 0 ? void 0 : prevUser.deviceId) === (currentUser === null || currentUser === void 0 ? void 0 : currentUser.deviceId) &&
|
|
142
|
+
(prevUser === null || prevUser === void 0 ? void 0 : prevUser.userId) === (currentUser === null || currentUser === void 0 ? void 0 : currentUser.userId) &&
|
|
143
|
+
ObjectUtil.arePropertiesEqual(prevUser === null || prevUser === void 0 ? void 0 : prevUser.properties, currentUser === null || currentUser === void 0 ? void 0 : currentUser.properties) &&
|
|
144
|
+
ObjectUtil.arePropertiesEqual(prevUser === null || prevUser === void 0 ? void 0 : prevUser.identifiers, currentUser === null || currentUser === void 0 ? void 0 : currentUser.identifiers));
|
|
145
|
+
};
|
|
146
|
+
return UserUtil;
|
|
147
|
+
}());
|
|
148
|
+
|
|
149
|
+
var HackleReactSDKClient = /** @class */ (function (_super) {
|
|
150
|
+
__extends(HackleReactSDKClient, _super);
|
|
79
151
|
function HackleReactSDKClient(sdkKey, config) {
|
|
80
|
-
|
|
152
|
+
var _this = _super.call(this) || this;
|
|
153
|
+
_this._currentUser = null;
|
|
154
|
+
_this.client = Hackle__namespace.createInstance(sdkKey, __assign(__assign({}, config), { SDK_NAME_HEADER: SDK_NAME_HEADER, SDK_VERSION_HEADER: SDK_VERSION_HEADER }));
|
|
155
|
+
return _this;
|
|
81
156
|
}
|
|
157
|
+
HackleReactSDKClient.prototype.getUser = function () {
|
|
158
|
+
return this.client.getUser();
|
|
159
|
+
};
|
|
160
|
+
HackleReactSDKClient.prototype.setUser = function (user) {
|
|
161
|
+
this.client.setUser(user);
|
|
162
|
+
this.emitUpdatedUser(this.getUser());
|
|
163
|
+
};
|
|
164
|
+
HackleReactSDKClient.prototype.setUserId = function (userId) {
|
|
165
|
+
this.client.setUserId(userId);
|
|
166
|
+
this.emitUpdatedUser(this.getUser());
|
|
167
|
+
};
|
|
168
|
+
HackleReactSDKClient.prototype.setDeviceId = function (deviceId) {
|
|
169
|
+
this.client.setDeviceId(deviceId);
|
|
170
|
+
this.emitUpdatedUser(this.getUser());
|
|
171
|
+
};
|
|
172
|
+
HackleReactSDKClient.prototype.setUserProperty = function (key, value) {
|
|
173
|
+
this.client.setUserProperty(key, value);
|
|
174
|
+
this.emitUpdatedUser(this.getUser());
|
|
175
|
+
};
|
|
176
|
+
HackleReactSDKClient.prototype.resetUser = function () {
|
|
177
|
+
this.client.resetUser();
|
|
178
|
+
this.emitUpdatedUser(this.getUser());
|
|
179
|
+
};
|
|
82
180
|
HackleReactSDKClient.prototype.variation = function (experimentKey, user, defaultVariation) {
|
|
83
|
-
return this.client.variation(experimentKey, user, defaultVariation);
|
|
181
|
+
return this.client.variation(experimentKey, user || undefined, defaultVariation);
|
|
84
182
|
};
|
|
85
183
|
HackleReactSDKClient.prototype.variationDetail = function (experimentKey, user, defaultVariation) {
|
|
86
|
-
return this.client.variationDetail(experimentKey, user, defaultVariation);
|
|
184
|
+
return this.client.variationDetail(experimentKey, user || undefined, defaultVariation);
|
|
87
185
|
};
|
|
88
186
|
HackleReactSDKClient.prototype.isFeatureOn = function (featureKey, user) {
|
|
89
|
-
return this.client.isFeatureOn(featureKey, user);
|
|
187
|
+
return this.client.isFeatureOn(featureKey, user || undefined);
|
|
90
188
|
};
|
|
91
189
|
HackleReactSDKClient.prototype.featureFlagDetail = function (featureKey, user) {
|
|
92
|
-
return this.client.featureFlagDetail(featureKey, user);
|
|
190
|
+
return this.client.featureFlagDetail(featureKey, user || undefined);
|
|
93
191
|
};
|
|
94
192
|
HackleReactSDKClient.prototype.track = function (event, user) {
|
|
95
|
-
this.client.track(event, user);
|
|
193
|
+
this.client.track(event, user || undefined);
|
|
96
194
|
};
|
|
97
195
|
HackleReactSDKClient.prototype.trackPageView = function (option) {
|
|
98
|
-
this.client.trackPageView(option);
|
|
196
|
+
this.client.trackPageView(__assign(__assign({}, option), { user: (option === null || option === void 0 ? void 0 : option.user) || undefined }));
|
|
99
197
|
};
|
|
100
198
|
HackleReactSDKClient.prototype.remoteConfig = function (user) {
|
|
101
|
-
return this.client.remoteConfig(user);
|
|
199
|
+
return this.client.remoteConfig(user || undefined);
|
|
102
200
|
};
|
|
103
201
|
HackleReactSDKClient.prototype.onReady = function (cb, timeout) {
|
|
104
202
|
this.client.onReady(cb, timeout);
|
|
@@ -106,35 +204,50 @@ var HackleReactSDKClient = /** @class */ (function () {
|
|
|
106
204
|
HackleReactSDKClient.prototype.onInitialized = function (config) {
|
|
107
205
|
return this.client.onInitialized(config);
|
|
108
206
|
};
|
|
207
|
+
HackleReactSDKClient.prototype.emitUpdatedUser = function (user) {
|
|
208
|
+
if (!UserUtil.isUserEqual(this._currentUser, user)) {
|
|
209
|
+
this.emit("user-updated", user);
|
|
210
|
+
}
|
|
211
|
+
this._currentUser = user;
|
|
212
|
+
};
|
|
109
213
|
return HackleReactSDKClient;
|
|
110
|
-
}());
|
|
214
|
+
}(Emitter));
|
|
111
215
|
function createInstance(sdkKey, config) {
|
|
112
216
|
return new HackleReactSDKClient(sdkKey, config);
|
|
113
217
|
}
|
|
114
218
|
|
|
115
219
|
var HackleContext = React.createContext({
|
|
116
220
|
hackle: undefined,
|
|
117
|
-
|
|
118
|
-
initialized: false
|
|
221
|
+
userVersion: 0,
|
|
222
|
+
initialized: false
|
|
119
223
|
});
|
|
120
224
|
var HackleContextConsumer = HackleContext.Consumer;
|
|
121
225
|
var HackleContextProvider = HackleContext.Provider;
|
|
122
226
|
|
|
123
227
|
function HackleProvider(_a) {
|
|
124
|
-
var hackleClient = _a.hackleClient,
|
|
125
|
-
var
|
|
228
|
+
var hackleClient = _a.hackleClient, initialUser = _a.user, _b = _a.timeout, timeout = _b === void 0 ? 3000 : _b, _c = _a.supportSSR, supportSSR = _c === void 0 ? false : _c, children = _a.children;
|
|
229
|
+
var _d = __read(React.useState({
|
|
126
230
|
hackle: hackleClient,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
};
|
|
130
|
-
var _d = __read(React.useState(state), 2), value = _d[0], setValue = _d[1];
|
|
231
|
+
initialized: false,
|
|
232
|
+
userVersion: 0
|
|
233
|
+
}), 2), value = _d[0], setValue = _d[1];
|
|
131
234
|
React.useEffect(function () {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
}, [
|
|
235
|
+
if (typeof initialUser !== "undefined" && initialUser !== null) {
|
|
236
|
+
hackleClient.setUser(initialUser);
|
|
237
|
+
}
|
|
238
|
+
}, [initialUser]);
|
|
239
|
+
React.useEffect(function () {
|
|
240
|
+
var onUserUpdated = function () {
|
|
241
|
+
setValue(function (prevState) { return (__assign(__assign({}, prevState), { userVersion: prevState.userVersion + 1 })); });
|
|
242
|
+
};
|
|
243
|
+
hackleClient.on("user-updated", onUserUpdated);
|
|
244
|
+
return function () {
|
|
245
|
+
hackleClient.off("user-updated", onUserUpdated);
|
|
246
|
+
};
|
|
247
|
+
}, [hackleClient]);
|
|
136
248
|
React.useEffect(function () {
|
|
137
|
-
hackleClient
|
|
249
|
+
hackleClient
|
|
250
|
+
.onInitialized({ timeout: timeout })
|
|
138
251
|
.then(function () {
|
|
139
252
|
setValue(function (prevState) {
|
|
140
253
|
return __assign(__assign({}, prevState), { initialized: true });
|
|
@@ -143,7 +256,8 @@ function HackleProvider(_a) {
|
|
|
143
256
|
setValue(function (prevState) {
|
|
144
257
|
return __assign(__assign({}, prevState), { initialized: true });
|
|
145
258
|
});
|
|
146
|
-
})
|
|
259
|
+
})
|
|
260
|
+
.catch(function () {
|
|
147
261
|
setValue(function (prevState) {
|
|
148
262
|
return __assign(__assign({}, prevState), { initialized: true });
|
|
149
263
|
});
|
|
@@ -158,10 +272,10 @@ function HackleProvider(_a) {
|
|
|
158
272
|
var log = Hackle.Logger.log;
|
|
159
273
|
function useVariation(experimentKey, defaultVariation) {
|
|
160
274
|
if (defaultVariation === void 0) { defaultVariation = "A"; }
|
|
161
|
-
var _a = React.useContext(HackleContext), hackle = _a.hackle,
|
|
275
|
+
var _a = React.useContext(HackleContext), hackle = _a.hackle, userVersion = _a.userVersion, initialized = _a.initialized;
|
|
162
276
|
var getVariation = React.useCallback(function () {
|
|
163
|
-
return (initialized && (hackle === null || hackle === void 0 ? void 0 : hackle.variation(experimentKey
|
|
164
|
-
}, [defaultVariation, experimentKey,
|
|
277
|
+
return (initialized && (hackle === null || hackle === void 0 ? void 0 : hackle.variation(experimentKey))) || defaultVariation;
|
|
278
|
+
}, [defaultVariation, experimentKey, hackle, initialized]);
|
|
165
279
|
var _b = __read(React.useState(function () {
|
|
166
280
|
if (notExistClient(hackle)) {
|
|
167
281
|
if (typeof window !== "undefined") {
|
|
@@ -173,7 +287,7 @@ function useVariation(experimentKey, defaultVariation) {
|
|
|
173
287
|
}), 2), variation = _b[0], setVariation = _b[1];
|
|
174
288
|
var currentInput = {
|
|
175
289
|
key: experimentKey,
|
|
176
|
-
|
|
290
|
+
userVersion: userVersion,
|
|
177
291
|
initialized: initialized
|
|
178
292
|
};
|
|
179
293
|
var _c = __read(React.useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
|
|
@@ -185,10 +299,10 @@ function useVariation(experimentKey, defaultVariation) {
|
|
|
185
299
|
}
|
|
186
300
|
function useVariationDetail(experimentKey, defaultVariation) {
|
|
187
301
|
if (defaultVariation === void 0) { defaultVariation = "A"; }
|
|
188
|
-
var _a = React.useContext(HackleContext), hackle = _a.hackle,
|
|
302
|
+
var _a = React.useContext(HackleContext), hackle = _a.hackle, userVersion = _a.userVersion, initialized = _a.initialized;
|
|
189
303
|
var getVariationDetail = React.useCallback(function () {
|
|
190
|
-
return (hackle === null || hackle === void 0 ? void 0 : hackle.variationDetail(experimentKey
|
|
191
|
-
}, [defaultVariation, experimentKey,
|
|
304
|
+
return (hackle === null || hackle === void 0 ? void 0 : hackle.variationDetail(experimentKey)) || Hackle.Decision.of(defaultVariation, Hackle.DecisionReason.EXCEPTION);
|
|
305
|
+
}, [defaultVariation, experimentKey, hackle, initialized]);
|
|
192
306
|
var _b = __read(React.useState(function () {
|
|
193
307
|
if (notExistClient(hackle)) {
|
|
194
308
|
if (typeof window !== "undefined") {
|
|
@@ -200,7 +314,7 @@ function useVariationDetail(experimentKey, defaultVariation) {
|
|
|
200
314
|
}), 2), variationDetail = _b[0], setVariationDetail = _b[1];
|
|
201
315
|
var currentInput = {
|
|
202
316
|
key: experimentKey,
|
|
203
|
-
|
|
317
|
+
userVersion: userVersion,
|
|
204
318
|
initialized: initialized
|
|
205
319
|
};
|
|
206
320
|
var _c = __read(React.useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
|
|
@@ -220,13 +334,13 @@ function useLoadableVariation(experimentKey, defaultVariation) {
|
|
|
220
334
|
}
|
|
221
335
|
function useLoadableVariationDetail(experimentKey, defaultVariation) {
|
|
222
336
|
if (defaultVariation === void 0) { defaultVariation = "A"; }
|
|
223
|
-
var _a = React.useContext(HackleContext), hackle = _a.hackle,
|
|
337
|
+
var _a = React.useContext(HackleContext), hackle = _a.hackle, userVersion = _a.userVersion, initialized = _a.initialized;
|
|
224
338
|
var getVariationDetail = React.useCallback(function () {
|
|
225
339
|
if (!initialized) {
|
|
226
340
|
return Hackle.Decision.of(defaultVariation, Hackle.DecisionReason.SDK_NOT_READY);
|
|
227
341
|
}
|
|
228
|
-
return (hackle === null || hackle === void 0 ? void 0 : hackle.variationDetail(experimentKey
|
|
229
|
-
}, [defaultVariation, experimentKey,
|
|
342
|
+
return (hackle === null || hackle === void 0 ? void 0 : hackle.variationDetail(experimentKey)) || Hackle.Decision.of(defaultVariation, Hackle.DecisionReason.EXCEPTION);
|
|
343
|
+
}, [defaultVariation, experimentKey, hackle, initialized]);
|
|
230
344
|
var _b = __read(React.useState(function () {
|
|
231
345
|
if (notExistClient(hackle)) {
|
|
232
346
|
log.error("HackleClient is not existed");
|
|
@@ -236,7 +350,7 @@ function useLoadableVariationDetail(experimentKey, defaultVariation) {
|
|
|
236
350
|
}), 2), variationDetail = _b[0], setVariationDetail = _b[1];
|
|
237
351
|
var currentInput = {
|
|
238
352
|
key: experimentKey,
|
|
239
|
-
|
|
353
|
+
userVersion: userVersion,
|
|
240
354
|
initialized: initialized
|
|
241
355
|
};
|
|
242
356
|
var _c = __read(React.useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
|
|
@@ -250,10 +364,10 @@ function useLoadableVariationDetail(experimentKey, defaultVariation) {
|
|
|
250
364
|
};
|
|
251
365
|
}
|
|
252
366
|
function useFeature(featureKey) {
|
|
253
|
-
var _a = React.useContext(HackleContext), hackle = _a.hackle,
|
|
367
|
+
var _a = React.useContext(HackleContext), hackle = _a.hackle, userVersion = _a.userVersion, initialized = _a.initialized;
|
|
254
368
|
var getIsOn = React.useCallback(function () {
|
|
255
|
-
return (hackle === null || hackle === void 0 ? void 0 : hackle.isFeatureOn(featureKey
|
|
256
|
-
}, [featureKey,
|
|
369
|
+
return (hackle === null || hackle === void 0 ? void 0 : hackle.isFeatureOn(featureKey)) || false;
|
|
370
|
+
}, [featureKey, hackle, initialized]);
|
|
257
371
|
var _b = __read(React.useState(function () {
|
|
258
372
|
if (notExistClient(hackle)) {
|
|
259
373
|
if (typeof window !== "undefined") {
|
|
@@ -265,7 +379,7 @@ function useFeature(featureKey) {
|
|
|
265
379
|
}), 2), isOn = _b[0], setIsOn = _b[1];
|
|
266
380
|
var currentInput = {
|
|
267
381
|
key: featureKey,
|
|
268
|
-
|
|
382
|
+
userVersion: userVersion,
|
|
269
383
|
initialized: initialized
|
|
270
384
|
};
|
|
271
385
|
var _c = __read(React.useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
|
|
@@ -276,10 +390,10 @@ function useFeature(featureKey) {
|
|
|
276
390
|
return isOn;
|
|
277
391
|
}
|
|
278
392
|
function useFeatureFlagDetail(featureKey) {
|
|
279
|
-
var _a = React.useContext(HackleContext), hackle = _a.hackle,
|
|
393
|
+
var _a = React.useContext(HackleContext), hackle = _a.hackle, userVersion = _a.userVersion, initialized = _a.initialized;
|
|
280
394
|
var getFeatureDetail = React.useCallback(function () {
|
|
281
|
-
return (hackle === null || hackle === void 0 ? void 0 : hackle.featureFlagDetail(featureKey
|
|
282
|
-
}, [featureKey,
|
|
395
|
+
return (hackle === null || hackle === void 0 ? void 0 : hackle.featureFlagDetail(featureKey)) || Hackle.FeatureFlagDecision.off(Hackle.DecisionReason.EXCEPTION);
|
|
396
|
+
}, [featureKey, hackle, initialized]);
|
|
283
397
|
var _b = __read(React.useState(function () {
|
|
284
398
|
if (notExistClient(hackle)) {
|
|
285
399
|
if (typeof window !== "undefined") {
|
|
@@ -291,7 +405,7 @@ function useFeatureFlagDetail(featureKey) {
|
|
|
291
405
|
}), 2), featureDetail = _b[0], setFeatureDetail = _b[1];
|
|
292
406
|
var currentInput = {
|
|
293
407
|
key: featureKey,
|
|
294
|
-
|
|
408
|
+
userVersion: userVersion,
|
|
295
409
|
initialized: initialized
|
|
296
410
|
};
|
|
297
411
|
var _c = __read(React.useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
|
|
@@ -309,13 +423,13 @@ function useLoadableFeature(featureKey) {
|
|
|
309
423
|
};
|
|
310
424
|
}
|
|
311
425
|
function useLoadableFeatureDetail(featureKey) {
|
|
312
|
-
var _a = React.useContext(HackleContext), hackle = _a.hackle,
|
|
426
|
+
var _a = React.useContext(HackleContext), hackle = _a.hackle, userVersion = _a.userVersion, initialized = _a.initialized;
|
|
313
427
|
var getFeatureDetail = React.useCallback(function () {
|
|
314
428
|
if (!initialized) {
|
|
315
429
|
return Hackle.FeatureFlagDecision.off(Hackle.DecisionReason.SDK_NOT_READY);
|
|
316
430
|
}
|
|
317
|
-
return (hackle === null || hackle === void 0 ? void 0 : hackle.featureFlagDetail(featureKey
|
|
318
|
-
}, [featureKey,
|
|
431
|
+
return (hackle === null || hackle === void 0 ? void 0 : hackle.featureFlagDetail(featureKey)) || Hackle.FeatureFlagDecision.off(Hackle.DecisionReason.EXCEPTION);
|
|
432
|
+
}, [featureKey, hackle, initialized]);
|
|
319
433
|
var _b = __read(React.useState(function () {
|
|
320
434
|
if (notExistClient(hackle)) {
|
|
321
435
|
log.error("HackleClient is not existed");
|
|
@@ -325,7 +439,7 @@ function useLoadableFeatureDetail(featureKey) {
|
|
|
325
439
|
}), 2), featureDetail = _b[0], setFeatureDetail = _b[1];
|
|
326
440
|
var currentInput = {
|
|
327
441
|
key: featureKey,
|
|
328
|
-
|
|
442
|
+
userVersion: userVersion,
|
|
329
443
|
initialized: initialized
|
|
330
444
|
};
|
|
331
445
|
var _c = __read(React.useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
|
|
@@ -339,10 +453,10 @@ function useLoadableFeatureDetail(featureKey) {
|
|
|
339
453
|
};
|
|
340
454
|
}
|
|
341
455
|
function useRemoteConfig() {
|
|
342
|
-
var _a = React.useContext(HackleContext), hackle = _a.hackle,
|
|
456
|
+
var _a = React.useContext(HackleContext), hackle = _a.hackle, userVersion = _a.userVersion, initialized = _a.initialized;
|
|
343
457
|
var getRemoteConfig = React.useCallback(function () {
|
|
344
|
-
return (hackle === null || hackle === void 0 ? void 0 : hackle.remoteConfig(
|
|
345
|
-
}, [
|
|
458
|
+
return (hackle === null || hackle === void 0 ? void 0 : hackle.remoteConfig()) || new Hackle.EmptyHackleRemoteConfig();
|
|
459
|
+
}, [hackle, initialized]);
|
|
346
460
|
var _b = __read(React.useState(function () {
|
|
347
461
|
if (notExistClient(hackle)) {
|
|
348
462
|
log.error("HackleClient is not existed");
|
|
@@ -350,7 +464,7 @@ function useRemoteConfig() {
|
|
|
350
464
|
return getRemoteConfig();
|
|
351
465
|
}), 2), remoteConfig = _b[0], setRemoteConfig = _b[1];
|
|
352
466
|
var currentInput = {
|
|
353
|
-
|
|
467
|
+
userVersion: userVersion,
|
|
354
468
|
initialized: initialized
|
|
355
469
|
};
|
|
356
470
|
var _c = __read(React.useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
|
|
@@ -361,13 +475,13 @@ function useRemoteConfig() {
|
|
|
361
475
|
return remoteConfig;
|
|
362
476
|
}
|
|
363
477
|
function useLoadableRemoteConfig() {
|
|
364
|
-
var _a = React.useContext(HackleContext), hackle = _a.hackle,
|
|
478
|
+
var _a = React.useContext(HackleContext), hackle = _a.hackle, userVersion = _a.userVersion, initialized = _a.initialized;
|
|
365
479
|
var getRemoteConfig = React.useCallback(function () {
|
|
366
480
|
if (!initialized) {
|
|
367
481
|
return new Hackle.EmptyHackleRemoteConfig();
|
|
368
482
|
}
|
|
369
|
-
return (hackle === null || hackle === void 0 ? void 0 : hackle.remoteConfig(
|
|
370
|
-
}, [
|
|
483
|
+
return (hackle === null || hackle === void 0 ? void 0 : hackle.remoteConfig()) || new Hackle.EmptyHackleRemoteConfig();
|
|
484
|
+
}, [hackle, initialized]);
|
|
371
485
|
var _b = __read(React.useState(function () {
|
|
372
486
|
if (notExistClient(hackle)) {
|
|
373
487
|
log.error("HackleClient is not existed");
|
|
@@ -375,7 +489,7 @@ function useLoadableRemoteConfig() {
|
|
|
375
489
|
return getRemoteConfig();
|
|
376
490
|
}), 2), remoteConfig = _b[0], setRemoteConfig = _b[1];
|
|
377
491
|
var currentInput = {
|
|
378
|
-
|
|
492
|
+
userVersion: userVersion,
|
|
379
493
|
initialized: initialized
|
|
380
494
|
};
|
|
381
495
|
var _c = __read(React.useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
|
|
@@ -389,40 +503,18 @@ function useLoadableRemoteConfig() {
|
|
|
389
503
|
};
|
|
390
504
|
}
|
|
391
505
|
function useTrack() {
|
|
392
|
-
var
|
|
506
|
+
var hackle = React.useContext(HackleContext).hackle;
|
|
393
507
|
if (notExistClient(hackle)) {
|
|
394
508
|
log.error("HackleClient is not existed");
|
|
395
509
|
return function () { };
|
|
396
510
|
}
|
|
397
|
-
return function (event) { return hackle === null || hackle === void 0 ? void 0 : hackle.track(event
|
|
511
|
+
return function (event) { return hackle === null || hackle === void 0 ? void 0 : hackle.track(event); };
|
|
398
512
|
}
|
|
399
513
|
function notExistClient(hackle) {
|
|
400
514
|
return !hackle;
|
|
401
515
|
}
|
|
402
516
|
function isInputEqual(prev, current) {
|
|
403
|
-
|
|
404
|
-
return (prev.initialized === current.initialized &&
|
|
405
|
-
prev.key === current.key &&
|
|
406
|
-
((_a = prev.user) === null || _a === void 0 ? void 0 : _a.id) === ((_b = current.user) === null || _b === void 0 ? void 0 : _b.id) &&
|
|
407
|
-
arePropertiesEqual((_c = prev.user) === null || _c === void 0 ? void 0 : _c.properties, (_d = current.user) === null || _d === void 0 ? void 0 : _d.properties));
|
|
408
|
-
}
|
|
409
|
-
function arePropertiesEqual(prevProps, currentProps) {
|
|
410
|
-
var prev = coerceUnknownToProperties(prevProps);
|
|
411
|
-
var current = coerceUnknownToProperties(currentProps);
|
|
412
|
-
var prevKeys = Object.keys(prev);
|
|
413
|
-
var currentKeys = Object.keys(current);
|
|
414
|
-
if (prevKeys.length !== currentKeys.length) {
|
|
415
|
-
return false;
|
|
416
|
-
}
|
|
417
|
-
return prevKeys.every(function (it) {
|
|
418
|
-
return it in current && prev[it] === current[it];
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
function coerceUnknownToProperties(props) {
|
|
422
|
-
if (typeof props === "object" && props !== null) {
|
|
423
|
-
return props;
|
|
424
|
-
}
|
|
425
|
-
return {};
|
|
517
|
+
return (prev.initialized === current.initialized && prev.key === current.key && prev.userVersion === current.userVersion);
|
|
426
518
|
}
|
|
427
519
|
|
|
428
520
|
function Experiment(_a) {
|