@openfeature/react-sdk 0.4.11 → 1.0.1
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/README.md +2 -2
- package/dist/cjs/index.js +176 -92
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +160 -79
- package/dist/esm/index.js.map +4 -4
- package/dist/types.d.ts +3 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
<img alt="Specification" src="https://img.shields.io/static/v1?label=specification&message=v0.8.0&color=yellow&style=for-the-badge" />
|
|
17
17
|
</a>
|
|
18
18
|
<!-- x-release-please-start-version -->
|
|
19
|
-
<a href="https://github.com/open-feature/js-sdk/releases/tag/react-sdk-
|
|
20
|
-
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=
|
|
19
|
+
<a href="https://github.com/open-feature/js-sdk/releases/tag/react-sdk-v1.0.1">
|
|
20
|
+
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v1.0.1&color=blue&style=for-the-badge" />
|
|
21
21
|
</a>
|
|
22
22
|
<!-- x-release-please-end -->
|
|
23
23
|
<br/>
|
package/dist/cjs/index.js
CHANGED
|
@@ -101,8 +101,8 @@ __export(index_exports, {
|
|
|
101
101
|
module.exports = __toCommonJS(index_exports);
|
|
102
102
|
|
|
103
103
|
// src/evaluation/use-feature-flag.ts
|
|
104
|
-
var
|
|
105
|
-
var
|
|
104
|
+
var import_web_sdk5 = require("@openfeature/web-sdk");
|
|
105
|
+
var import_react6 = require("react");
|
|
106
106
|
|
|
107
107
|
// src/internal/context.ts
|
|
108
108
|
var import_react = __toESM(require("react"));
|
|
@@ -146,67 +146,131 @@ var DEFAULT_OPTIONS = {
|
|
|
146
146
|
var normalizeOptions = (options = {}) => {
|
|
147
147
|
const updateOnContextChanged = options.updateOnContextChanged;
|
|
148
148
|
const updateOnConfigurationChanged = options.updateOnConfigurationChanged;
|
|
149
|
-
const
|
|
149
|
+
const suspendUntilReady = "suspendUntilReady" in options ? options.suspendUntilReady : options.suspend;
|
|
150
150
|
const suspendWhileReconciling = "suspendWhileReconciling" in options ? options.suspendWhileReconciling : options.suspend;
|
|
151
|
-
return __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, typeof
|
|
151
|
+
return __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, typeof suspendUntilReady === "boolean" && { suspendUntilReady }), typeof suspendWhileReconciling === "boolean" && { suspendWhileReconciling }), typeof updateOnContextChanged === "boolean" && { updateOnContextChanged }), typeof updateOnConfigurationChanged === "boolean" && { updateOnConfigurationChanged });
|
|
152
152
|
};
|
|
153
153
|
|
|
154
154
|
// src/internal/suspense.ts
|
|
155
155
|
var import_web_sdk = require("@openfeature/web-sdk");
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
156
|
+
|
|
157
|
+
// src/internal/use.ts
|
|
158
|
+
var import_react2 = __toESM(require("react"));
|
|
159
|
+
var use = import_react2.default.use || // This extra generic is to avoid TypeScript mixing up the generic and JSX syntax
|
|
160
|
+
// and emitting an error.
|
|
161
|
+
// We assume that this is only for the `use(thenable)` case, not `use(context)`.
|
|
162
|
+
// https://github.com/facebook/react/blob/aed00dacfb79d17c53218404c52b1c7aa59c4a89/packages/react-server/src/ReactFizzThenable.js#L45
|
|
163
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
164
|
+
((thenable) => {
|
|
165
|
+
switch (thenable.status) {
|
|
166
|
+
case "pending":
|
|
167
|
+
throw thenable;
|
|
168
|
+
case "fulfilled":
|
|
169
|
+
return thenable.value;
|
|
170
|
+
case "rejected":
|
|
171
|
+
throw thenable.reason;
|
|
172
|
+
default:
|
|
173
|
+
thenable.status = "pending";
|
|
174
|
+
thenable.then(
|
|
175
|
+
(v) => {
|
|
176
|
+
thenable.status = "fulfilled";
|
|
177
|
+
thenable.value = v;
|
|
178
|
+
},
|
|
179
|
+
(e) => {
|
|
180
|
+
thenable.status = "rejected";
|
|
181
|
+
thenable.reason = e;
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
throw thenable;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// src/internal/suspense.ts
|
|
189
|
+
var globalProviderSuspenseStatus = /* @__PURE__ */ new WeakMap();
|
|
190
|
+
function suspendUntilInitialized(provider, client) {
|
|
191
|
+
const statusPromiseRef = globalProviderSuspenseStatus.get(provider);
|
|
192
|
+
if (!statusPromiseRef) {
|
|
193
|
+
const statusPromise = provider !== import_web_sdk.NOOP_PROVIDER ? isProviderReady(client) : Promise.resolve();
|
|
194
|
+
globalProviderSuspenseStatus.set(provider, statusPromise);
|
|
195
|
+
use(statusPromise);
|
|
196
|
+
} else {
|
|
197
|
+
use(statusPromiseRef);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function suspendUntilReconciled(client) {
|
|
201
|
+
use(isProviderReady(client));
|
|
202
|
+
}
|
|
203
|
+
function isProviderReady(client) {
|
|
204
|
+
return __async(this, null, function* () {
|
|
205
|
+
const controller = new AbortController();
|
|
206
|
+
try {
|
|
207
|
+
return yield new Promise((resolve, reject) => {
|
|
208
|
+
client.addHandler(import_web_sdk.ProviderEvents.Ready, resolve, { signal: controller.signal });
|
|
209
|
+
client.addHandler(import_web_sdk.ProviderEvents.Error, reject, { signal: controller.signal });
|
|
210
|
+
});
|
|
211
|
+
} finally {
|
|
212
|
+
controller.abort();
|
|
213
|
+
}
|
|
167
214
|
});
|
|
168
215
|
}
|
|
169
216
|
|
|
170
217
|
// src/provider/use-open-feature-client.ts
|
|
171
|
-
var
|
|
218
|
+
var import_react3 = __toESM(require("react"));
|
|
219
|
+
|
|
220
|
+
// src/internal/errors.ts
|
|
221
|
+
var context = "Components using OpenFeature must be wrapped with an <OpenFeatureProvider>.";
|
|
222
|
+
var tip = "If you are seeing this in a test, see: https://openfeature.dev/docs/reference/technologies/client/web/react#testing";
|
|
223
|
+
var MissingContextError = class extends Error {
|
|
224
|
+
constructor(reason) {
|
|
225
|
+
super(`${reason}: ${context} ${tip}`);
|
|
226
|
+
this.name = "MissingContextError";
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// src/provider/use-open-feature-client.ts
|
|
172
231
|
function useOpenFeatureClient() {
|
|
173
|
-
const { client } =
|
|
232
|
+
const { client } = import_react3.default.useContext(Context) || {};
|
|
174
233
|
if (!client) {
|
|
175
|
-
throw new
|
|
176
|
-
"No OpenFeature client available - components using OpenFeature must be wrapped with an <OpenFeatureProvider>. If you are seeing this in a test, see: https://openfeature.dev/docs/reference/technologies/client/web/react#testing"
|
|
177
|
-
);
|
|
234
|
+
throw new MissingContextError("No OpenFeature client available");
|
|
178
235
|
}
|
|
179
236
|
return client;
|
|
180
237
|
}
|
|
181
238
|
|
|
182
239
|
// src/provider/use-open-feature-client-status.ts
|
|
183
|
-
var
|
|
240
|
+
var import_react4 = require("react");
|
|
184
241
|
var import_web_sdk2 = require("@openfeature/web-sdk");
|
|
185
242
|
function useOpenFeatureClientStatus() {
|
|
186
243
|
const client = useOpenFeatureClient();
|
|
187
|
-
const [status, setStatus] = (0,
|
|
188
|
-
|
|
244
|
+
const [status, setStatus] = (0, import_react4.useState)(client.providerStatus);
|
|
245
|
+
const controller = new AbortController();
|
|
246
|
+
(0, import_react4.useEffect)(() => {
|
|
189
247
|
const updateStatus = () => setStatus(client.providerStatus);
|
|
190
|
-
client.addHandler(import_web_sdk2.ProviderEvents.ConfigurationChanged, updateStatus);
|
|
191
|
-
client.addHandler(import_web_sdk2.ProviderEvents.ContextChanged, updateStatus);
|
|
192
|
-
client.addHandler(import_web_sdk2.ProviderEvents.Error, updateStatus);
|
|
193
|
-
client.addHandler(import_web_sdk2.ProviderEvents.Ready, updateStatus);
|
|
194
|
-
client.addHandler(import_web_sdk2.ProviderEvents.Stale, updateStatus);
|
|
195
|
-
client.addHandler(import_web_sdk2.ProviderEvents.Reconciling, updateStatus);
|
|
248
|
+
client.addHandler(import_web_sdk2.ProviderEvents.ConfigurationChanged, updateStatus, { signal: controller.signal });
|
|
249
|
+
client.addHandler(import_web_sdk2.ProviderEvents.ContextChanged, updateStatus, { signal: controller.signal });
|
|
250
|
+
client.addHandler(import_web_sdk2.ProviderEvents.Error, updateStatus, { signal: controller.signal });
|
|
251
|
+
client.addHandler(import_web_sdk2.ProviderEvents.Ready, updateStatus, { signal: controller.signal });
|
|
252
|
+
client.addHandler(import_web_sdk2.ProviderEvents.Stale, updateStatus, { signal: controller.signal });
|
|
253
|
+
client.addHandler(import_web_sdk2.ProviderEvents.Reconciling, updateStatus, { signal: controller.signal });
|
|
196
254
|
return () => {
|
|
197
|
-
|
|
198
|
-
client.removeHandler(import_web_sdk2.ProviderEvents.ContextChanged, updateStatus);
|
|
199
|
-
client.removeHandler(import_web_sdk2.ProviderEvents.Error, updateStatus);
|
|
200
|
-
client.removeHandler(import_web_sdk2.ProviderEvents.Ready, updateStatus);
|
|
201
|
-
client.removeHandler(import_web_sdk2.ProviderEvents.Stale, updateStatus);
|
|
202
|
-
client.removeHandler(import_web_sdk2.ProviderEvents.Reconciling, updateStatus);
|
|
255
|
+
controller.abort();
|
|
203
256
|
};
|
|
204
257
|
}, [client]);
|
|
205
258
|
return status;
|
|
206
259
|
}
|
|
207
260
|
|
|
208
|
-
// src/
|
|
261
|
+
// src/provider/use-open-feature-provider.ts
|
|
262
|
+
var import_react5 = __toESM(require("react"));
|
|
209
263
|
var import_web_sdk3 = require("@openfeature/web-sdk");
|
|
264
|
+
function useOpenFeatureProvider() {
|
|
265
|
+
const openFeatureContext = import_react5.default.useContext(Context);
|
|
266
|
+
if (!openFeatureContext) {
|
|
267
|
+
throw new MissingContextError("No OpenFeature context available");
|
|
268
|
+
}
|
|
269
|
+
return import_web_sdk3.OpenFeature.getProvider(openFeatureContext.domain);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// src/internal/hook-flag-query.ts
|
|
273
|
+
var import_web_sdk4 = require("@openfeature/web-sdk");
|
|
210
274
|
var HookFlagQuery = class {
|
|
211
275
|
constructor(_details) {
|
|
212
276
|
this._details = _details;
|
|
@@ -229,7 +293,7 @@ var HookFlagQuery = class {
|
|
|
229
293
|
}
|
|
230
294
|
get isError() {
|
|
231
295
|
var _a;
|
|
232
|
-
return !!((_a = this._details) == null ? void 0 : _a.errorCode) || this._details.reason ==
|
|
296
|
+
return !!((_a = this._details) == null ? void 0 : _a.errorCode) || this._details.reason == import_web_sdk4.StandardResolutionReasons.ERROR;
|
|
233
297
|
}
|
|
234
298
|
get errorCode() {
|
|
235
299
|
var _a;
|
|
@@ -240,7 +304,7 @@ var HookFlagQuery = class {
|
|
|
240
304
|
return (_a = this._details) == null ? void 0 : _a.errorMessage;
|
|
241
305
|
}
|
|
242
306
|
get isAuthoritative() {
|
|
243
|
-
return !this.isError && this._details.reason !=
|
|
307
|
+
return !this.isError && this._details.reason != import_web_sdk4.StandardResolutionReasons.STALE && this._details.reason != import_web_sdk4.StandardResolutionReasons.DISABLED;
|
|
244
308
|
}
|
|
245
309
|
get type() {
|
|
246
310
|
return typeof this._details.value;
|
|
@@ -314,82 +378,102 @@ function attachHandlersAndResolve(flagKey, defaultValue, resolver, options) {
|
|
|
314
378
|
const defaultedOptions = __spreadValues(__spreadValues(__spreadValues({}, DEFAULT_OPTIONS), useProviderOptions()), normalizeOptions(options));
|
|
315
379
|
const client = useOpenFeatureClient();
|
|
316
380
|
const status = useOpenFeatureClientStatus();
|
|
317
|
-
|
|
318
|
-
|
|
381
|
+
const provider = useOpenFeatureProvider();
|
|
382
|
+
const isFirstRender = (0, import_react6.useRef)(true);
|
|
383
|
+
if (defaultedOptions.suspendUntilReady && status === import_web_sdk5.ProviderStatus.NOT_READY) {
|
|
384
|
+
suspendUntilInitialized(provider, client);
|
|
319
385
|
}
|
|
320
|
-
if (defaultedOptions.suspendWhileReconciling && status ===
|
|
321
|
-
|
|
386
|
+
if (defaultedOptions.suspendWhileReconciling && status === import_web_sdk5.ProviderStatus.RECONCILING) {
|
|
387
|
+
suspendUntilReconciled(client);
|
|
322
388
|
}
|
|
323
|
-
const [evaluationDetails, setEvaluationDetails] = (0,
|
|
324
|
-
resolver(client).call(client, flagKey, defaultValue, options)
|
|
389
|
+
const [evaluationDetails, setEvaluationDetails] = (0, import_react6.useState)(
|
|
390
|
+
() => resolver(client).call(client, flagKey, defaultValue, options)
|
|
325
391
|
);
|
|
326
|
-
|
|
327
|
-
|
|
392
|
+
(0, import_react6.useEffect)(() => {
|
|
393
|
+
if (isFirstRender.current) {
|
|
394
|
+
isFirstRender.current = false;
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
const newDetails = resolver(client).call(client, flagKey, defaultValue, options);
|
|
398
|
+
if (!isEqual(newDetails.value, evaluationDetails.value)) {
|
|
399
|
+
setEvaluationDetails(newDetails);
|
|
400
|
+
}
|
|
401
|
+
}, [client, flagKey, defaultValue, options, resolver, evaluationDetails]);
|
|
402
|
+
const evaluationDetailsRef = (0, import_react6.useRef)(evaluationDetails);
|
|
403
|
+
(0, import_react6.useEffect)(() => {
|
|
328
404
|
evaluationDetailsRef.current = evaluationDetails;
|
|
329
405
|
}, [evaluationDetails]);
|
|
330
|
-
const updateEvaluationDetailsCallback = () => {
|
|
406
|
+
const updateEvaluationDetailsCallback = (0, import_react6.useCallback)(() => {
|
|
331
407
|
const updatedEvaluationDetails = resolver(client).call(client, flagKey, defaultValue, options);
|
|
332
408
|
if (!isEqual(updatedEvaluationDetails.value, evaluationDetailsRef.current.value)) {
|
|
333
409
|
setEvaluationDetails(updatedEvaluationDetails);
|
|
334
410
|
}
|
|
335
|
-
};
|
|
336
|
-
const configurationChangeCallback = (
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
411
|
+
}, [client, flagKey, defaultValue, options, resolver]);
|
|
412
|
+
const configurationChangeCallback = (0, import_react6.useCallback)(
|
|
413
|
+
(eventDetails) => {
|
|
414
|
+
if (shouldEvaluateFlag(flagKey, eventDetails == null ? void 0 : eventDetails.flagsChanged)) {
|
|
415
|
+
updateEvaluationDetailsCallback();
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
[flagKey, updateEvaluationDetailsCallback]
|
|
419
|
+
);
|
|
420
|
+
(0, import_react6.useEffect)(() => {
|
|
421
|
+
const controller = new AbortController();
|
|
422
|
+
if (status === import_web_sdk5.ProviderStatus.NOT_READY) {
|
|
423
|
+
client.addHandler(import_web_sdk5.ProviderEvents.Ready, updateEvaluationDetailsCallback, { signal: controller.signal });
|
|
344
424
|
}
|
|
345
425
|
if (defaultedOptions.updateOnContextChanged) {
|
|
346
|
-
client.addHandler(
|
|
426
|
+
client.addHandler(import_web_sdk5.ProviderEvents.ContextChanged, updateEvaluationDetailsCallback, { signal: controller.signal });
|
|
347
427
|
}
|
|
348
|
-
return () => {
|
|
349
|
-
client.removeHandler(import_web_sdk4.ProviderEvents.Ready, updateEvaluationDetailsCallback);
|
|
350
|
-
client.removeHandler(import_web_sdk4.ProviderEvents.ContextChanged, updateEvaluationDetailsCallback);
|
|
351
|
-
};
|
|
352
|
-
}, []);
|
|
353
|
-
(0, import_react4.useEffect)(() => {
|
|
354
428
|
if (defaultedOptions.updateOnConfigurationChanged) {
|
|
355
|
-
client.addHandler(
|
|
429
|
+
client.addHandler(import_web_sdk5.ProviderEvents.ConfigurationChanged, configurationChangeCallback, {
|
|
430
|
+
signal: controller.signal
|
|
431
|
+
});
|
|
356
432
|
}
|
|
357
433
|
return () => {
|
|
358
|
-
|
|
434
|
+
controller.abort();
|
|
359
435
|
};
|
|
360
|
-
}, [
|
|
436
|
+
}, [
|
|
437
|
+
client,
|
|
438
|
+
status,
|
|
439
|
+
defaultedOptions.updateOnContextChanged,
|
|
440
|
+
defaultedOptions.updateOnConfigurationChanged,
|
|
441
|
+
updateEvaluationDetailsCallback,
|
|
442
|
+
configurationChangeCallback
|
|
443
|
+
]);
|
|
361
444
|
return evaluationDetails;
|
|
362
445
|
}
|
|
363
446
|
|
|
364
447
|
// src/provider/provider.tsx
|
|
365
|
-
var
|
|
366
|
-
var
|
|
448
|
+
var import_web_sdk6 = require("@openfeature/web-sdk");
|
|
449
|
+
var React5 = __toESM(require("react"));
|
|
367
450
|
function OpenFeatureProvider(_a) {
|
|
368
451
|
var _b = _a, { client, domain, children } = _b, options = __objRest(_b, ["client", "domain", "children"]);
|
|
369
452
|
if (!client) {
|
|
370
|
-
client =
|
|
453
|
+
client = import_web_sdk6.OpenFeature.getClient(domain);
|
|
371
454
|
}
|
|
372
|
-
return /* @__PURE__ */
|
|
455
|
+
return /* @__PURE__ */ React5.createElement(Context.Provider, { value: { client, options, domain } }, children);
|
|
373
456
|
}
|
|
374
457
|
|
|
375
458
|
// src/provider/use-when-provider-ready.ts
|
|
376
|
-
var
|
|
459
|
+
var import_web_sdk7 = require("@openfeature/web-sdk");
|
|
377
460
|
function useWhenProviderReady(options) {
|
|
461
|
+
const defaultedOptions = __spreadValues(__spreadValues(__spreadValues({}, DEFAULT_OPTIONS), useProviderOptions()), normalizeOptions(options));
|
|
378
462
|
const client = useOpenFeatureClient();
|
|
379
463
|
const status = useOpenFeatureClientStatus();
|
|
380
|
-
const
|
|
381
|
-
if (defaultedOptions.suspendUntilReady && status ===
|
|
382
|
-
|
|
464
|
+
const provider = useOpenFeatureProvider();
|
|
465
|
+
if (defaultedOptions.suspendUntilReady && status === import_web_sdk7.ProviderStatus.NOT_READY) {
|
|
466
|
+
suspendUntilInitialized(provider, client);
|
|
383
467
|
}
|
|
384
|
-
return status ===
|
|
468
|
+
return status === import_web_sdk7.ProviderStatus.READY;
|
|
385
469
|
}
|
|
386
470
|
|
|
387
471
|
// src/provider/test-provider.tsx
|
|
388
|
-
var
|
|
389
|
-
var
|
|
472
|
+
var import_web_sdk8 = require("@openfeature/web-sdk");
|
|
473
|
+
var import_react7 = __toESM(require("react"));
|
|
390
474
|
var TEST_VARIANT = "test-variant";
|
|
391
475
|
var TEST_PROVIDER = "test-provider";
|
|
392
|
-
var TestProvider = class extends
|
|
476
|
+
var TestProvider = class extends import_web_sdk8.InMemoryProvider {
|
|
393
477
|
constructor(flagValueMap, delay = 0) {
|
|
394
478
|
const flagConfig = Object.entries(flagValueMap).reduce((acc, flag) => {
|
|
395
479
|
return __spreadProps(__spreadValues({}, acc), {
|
|
@@ -424,15 +508,15 @@ var TestProvider = class extends import_web_sdk7.InMemoryProvider {
|
|
|
424
508
|
};
|
|
425
509
|
function OpenFeatureTestProvider(testProviderOptions) {
|
|
426
510
|
const { flagValueMap, provider } = testProviderOptions;
|
|
427
|
-
const effectiveProvider = flagValueMap ? new TestProvider(flagValueMap, testProviderOptions.delayMs) : mixInNoop(provider) ||
|
|
428
|
-
testProviderOptions.domain ?
|
|
429
|
-
return /* @__PURE__ */
|
|
511
|
+
const effectiveProvider = flagValueMap ? new TestProvider(flagValueMap, testProviderOptions.delayMs) : mixInNoop(provider) || import_web_sdk8.NOOP_PROVIDER;
|
|
512
|
+
testProviderOptions.domain ? import_web_sdk8.OpenFeature.setProvider(testProviderOptions.domain, effectiveProvider) : import_web_sdk8.OpenFeature.setProvider(effectiveProvider);
|
|
513
|
+
return /* @__PURE__ */ import_react7.default.createElement(OpenFeatureProvider, __spreadProps(__spreadValues({}, testProviderOptions), { domain: testProviderOptions.domain }), testProviderOptions.children);
|
|
430
514
|
}
|
|
431
515
|
function mixInNoop(provider = {}) {
|
|
432
|
-
for (const prop of Object.getOwnPropertyNames(Object.getPrototypeOf(
|
|
516
|
+
for (const prop of Object.getOwnPropertyNames(Object.getPrototypeOf(import_web_sdk8.NOOP_PROVIDER)).filter((prop2) => prop2 !== "constructor")) {
|
|
433
517
|
const patchedProvider = provider;
|
|
434
518
|
if (!Object.getPrototypeOf(patchedProvider)[prop] && !patchedProvider[prop]) {
|
|
435
|
-
patchedProvider[prop] = Object.getPrototypeOf(
|
|
519
|
+
patchedProvider[prop] = Object.getPrototypeOf(import_web_sdk8.NOOP_PROVIDER)[prop];
|
|
436
520
|
}
|
|
437
521
|
}
|
|
438
522
|
if (!provider.metadata || !provider.metadata.name) {
|
|
@@ -442,17 +526,17 @@ function mixInNoop(provider = {}) {
|
|
|
442
526
|
}
|
|
443
527
|
|
|
444
528
|
// src/context/use-context-mutator.ts
|
|
445
|
-
var
|
|
446
|
-
var
|
|
529
|
+
var import_react8 = require("react");
|
|
530
|
+
var import_web_sdk9 = require("@openfeature/web-sdk");
|
|
447
531
|
function useContextMutator(options = { defaultContext: false }) {
|
|
448
|
-
const { domain } = (0,
|
|
449
|
-
const previousContext = (0,
|
|
450
|
-
const setContext = (0,
|
|
532
|
+
const { domain } = (0, import_react8.useContext)(Context) || {};
|
|
533
|
+
const previousContext = (0, import_react8.useRef)(null);
|
|
534
|
+
const setContext = (0, import_react8.useCallback)((updatedContext) => __async(null, null, function* () {
|
|
451
535
|
if (previousContext.current !== updatedContext) {
|
|
452
536
|
if (!domain || (options == null ? void 0 : options.defaultContext)) {
|
|
453
|
-
|
|
537
|
+
import_web_sdk9.OpenFeature.setContext(updatedContext);
|
|
454
538
|
} else {
|
|
455
|
-
|
|
539
|
+
import_web_sdk9.OpenFeature.setContext(domain, updatedContext);
|
|
456
540
|
}
|
|
457
541
|
previousContext.current = updatedContext;
|
|
458
542
|
}
|
|
@@ -463,10 +547,10 @@ function useContextMutator(options = { defaultContext: false }) {
|
|
|
463
547
|
}
|
|
464
548
|
|
|
465
549
|
// src/tracking/use-track.ts
|
|
466
|
-
var
|
|
550
|
+
var import_react9 = require("react");
|
|
467
551
|
function useTrack() {
|
|
468
552
|
const client = useOpenFeatureClient();
|
|
469
|
-
const track = (0,
|
|
553
|
+
const track = (0, import_react9.useCallback)((trackingEventName, trackingEventDetails) => {
|
|
470
554
|
client.track(trackingEventName, trackingEventDetails);
|
|
471
555
|
}, []);
|
|
472
556
|
return {
|