@statsig/react-bindings 0.0.1-beta.8 → 1.0.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/README.md +0 -3
- package/package.json +2 -2
- package/src/NoopEvaluationsClient.js +62 -29
- package/src/OnDeviceVsPrecomputedUtils.d.ts +2 -3
- package/src/OnDeviceVsPrecomputedUtils.js +9 -5
- package/src/StatsigContext.js +3 -2
- package/src/StatsigProvider.d.ts +2 -3
- package/src/StatsigProvider.js +17 -19
- package/src/index.d.ts +8 -6
- package/src/index.js +26 -27
- package/src/useDynamicConfig.d.ts +4 -3
- package/src/useDynamicConfig.js +16 -15
- package/src/useExperiment.d.ts +4 -3
- package/src/useExperiment.js +16 -15
- package/src/useFeatureGate.d.ts +5 -0
- package/src/useFeatureGate.js +22 -0
- package/src/useGateValue.d.ts +5 -0
- package/src/useGateValue.js +22 -0
- package/src/useLayer.d.ts +2 -2
- package/src/useLayer.js +11 -23
- package/src/useStatsigClient.d.ts +6 -0
- package/src/useStatsigClient.js +44 -0
- package/src/useStatsigOnDeviceEvalClient.d.ts +6 -0
- package/src/useStatsigOnDeviceEvalClient.js +44 -0
- package/src/useStatsigUser.d.ts +8 -3
- package/src/useStatsigUser.js +26 -13
- package/src/useConfigImpl.d.ts +0 -5
- package/src/useConfigImpl.js +0 -36
- package/src/useGate.d.ts +0 -5
- package/src/useGate.js +0 -34
- package/src/useStatsigOnDeviceEvaluationsClient.d.ts +0 -2
- package/src/useStatsigOnDeviceEvaluationsClient.js +0 -16
- package/src/useStatsigPrecomputedEvaluationsClient.d.ts +0 -2
- package/src/useStatsigPrecomputedEvaluationsClient.js +0 -16
package/README.md
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
# Statsig - React
|
|
2
2
|
|
|
3
|
-
> [!IMPORTANT]
|
|
4
|
-
> This version of the SDK is still in beta. The non-beta version can be found [here](https://github.com/statsig-io/react-sdk).
|
|
5
|
-
|
|
6
3
|
ReactJS specific additions for use with a Statsig Javascript SDK.
|
|
7
4
|
|
|
8
5
|
Learn more by visiting: https://docs.statsig.com/client/javascript-sdk
|
package/package.json
CHANGED
|
@@ -1,44 +1,77 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.NoopEvaluationsClient = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
13
|
+
const client_core_1 = require("@statsig/client-core");
|
|
14
|
+
const _noop = () => {
|
|
6
15
|
// noop
|
|
7
16
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
args[_i] = arguments[_i];
|
|
14
|
-
}
|
|
15
|
-
var name = typeof args[0] === 'string' ? args[0] : args[1];
|
|
17
|
+
const _noopAsync = () => Promise.resolve();
|
|
18
|
+
const NOOP_DETAILS = { reason: 'Error' };
|
|
19
|
+
const _defaultEvaluation = (type) => {
|
|
20
|
+
return (...args) => {
|
|
21
|
+
const name = typeof args[0] === 'string' ? args[0] : args[1];
|
|
16
22
|
switch (type) {
|
|
17
23
|
case 'gate':
|
|
18
|
-
return (0, client_core_1.
|
|
24
|
+
return (0, client_core_1._makeFeatureGate)(name, NOOP_DETAILS, null);
|
|
19
25
|
case 'config':
|
|
20
|
-
return (0, client_core_1.
|
|
26
|
+
return (0, client_core_1._makeDynamicConfig)(name, NOOP_DETAILS, null);
|
|
21
27
|
case 'layer':
|
|
22
|
-
return (0, client_core_1.
|
|
28
|
+
return (0, client_core_1._makeLayer)(name, NOOP_DETAILS, null);
|
|
23
29
|
}
|
|
24
30
|
};
|
|
25
31
|
};
|
|
26
|
-
|
|
32
|
+
const _noopDataAdapter = {
|
|
33
|
+
__primeInMemoryCache: _noop,
|
|
34
|
+
attach: _noop,
|
|
35
|
+
getDataSync: () => null,
|
|
36
|
+
getDataAsync: () => Promise.resolve(null),
|
|
37
|
+
setData: _noop,
|
|
38
|
+
setDataLegacy: _noop,
|
|
39
|
+
prefetchData: _noopAsync,
|
|
40
|
+
};
|
|
41
|
+
const context = {
|
|
42
|
+
sdkKey: '',
|
|
43
|
+
options: {},
|
|
44
|
+
values: null,
|
|
45
|
+
user: { userID: '' },
|
|
46
|
+
errorBoundary: {},
|
|
47
|
+
};
|
|
48
|
+
const _client = {
|
|
27
49
|
isNoop: true,
|
|
28
50
|
loadingStatus: 'Uninitialized',
|
|
29
|
-
initializeSync:
|
|
30
|
-
initializeAsync:
|
|
31
|
-
shutdown:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
initializeSync: _noop,
|
|
52
|
+
initializeAsync: _noopAsync,
|
|
53
|
+
shutdown: _noopAsync,
|
|
54
|
+
flush: _noopAsync,
|
|
55
|
+
updateRuntimeOptions: _noop,
|
|
56
|
+
updateUserSync: _noop,
|
|
57
|
+
updateUserAsync: _noopAsync,
|
|
58
|
+
getContext: () => (Object.assign({}, context)),
|
|
59
|
+
getAsyncContext: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
return (Object.assign(Object.assign({}, context), { session: {
|
|
61
|
+
data: { sessionID: '', startTime: 0, lastUpdate: 0 },
|
|
62
|
+
sdkKey: '',
|
|
63
|
+
}, stableID: '' }));
|
|
64
|
+
}),
|
|
65
|
+
checkGate: () => false,
|
|
66
|
+
getFeatureGate: _defaultEvaluation('gate'),
|
|
67
|
+
getDynamicConfig: _defaultEvaluation('config'),
|
|
68
|
+
getExperiment: _defaultEvaluation('config'),
|
|
69
|
+
getLayer: _defaultEvaluation('layer'),
|
|
70
|
+
logEvent: _noop,
|
|
71
|
+
on: _noop,
|
|
72
|
+
off: _noop,
|
|
73
|
+
$on: _noop,
|
|
74
|
+
$emt: _noop,
|
|
75
|
+
dataAdapter: _noopDataAdapter,
|
|
43
76
|
};
|
|
44
|
-
exports.NoopEvaluationsClient =
|
|
77
|
+
exports.NoopEvaluationsClient = _client;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { OnDeviceEvaluationsInterface, PrecomputedEvaluationsInterface } from '@statsig/client-core';
|
|
2
|
-
export declare function
|
|
3
|
-
|
|
4
|
-
}): client is PrecomputedEvaluationsInterface;
|
|
2
|
+
export declare function isPrecomputedEvalClient(client: OnDeviceEvaluationsInterface | PrecomputedEvaluationsInterface): client is PrecomputedEvaluationsInterface;
|
|
3
|
+
export declare function isNoopClient(client: OnDeviceEvaluationsInterface | PrecomputedEvaluationsInterface): boolean;
|
|
5
4
|
export declare function logMissingStatsigUserWarning(): void;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.logMissingStatsigUserWarning = exports.
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
if (
|
|
3
|
+
exports.logMissingStatsigUserWarning = exports.isNoopClient = exports.isPrecomputedEvalClient = void 0;
|
|
4
|
+
const client_core_1 = require("@statsig/client-core");
|
|
5
|
+
function isPrecomputedEvalClient(client) {
|
|
6
|
+
if (isNoopClient(client)) {
|
|
7
7
|
return false;
|
|
8
8
|
}
|
|
9
9
|
return 'updateUserSync' in client;
|
|
10
10
|
}
|
|
11
|
-
exports.
|
|
11
|
+
exports.isPrecomputedEvalClient = isPrecomputedEvalClient;
|
|
12
|
+
function isNoopClient(client) {
|
|
13
|
+
return 'isNoop' in client;
|
|
14
|
+
}
|
|
15
|
+
exports.isNoopClient = isNoopClient;
|
|
12
16
|
function logMissingStatsigUserWarning() {
|
|
13
17
|
client_core_1.Log.warn('StatsigUser not provided for On Device Evaluation. Returning default value.');
|
|
14
18
|
}
|
package/src/StatsigContext.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
|
|
4
5
|
exports.default = (0, react_1.createContext)({
|
|
5
6
|
renderVersion: 0,
|
|
6
|
-
client:
|
|
7
|
+
client: NoopEvaluationsClient_1.NoopEvaluationsClient,
|
|
7
8
|
});
|
package/src/StatsigProvider.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { StatsigClientInterface } from '@statsig/client-core';
|
|
3
|
-
type
|
|
3
|
+
export type StatsigProviderProps = {
|
|
4
4
|
children: ReactNode | ReactNode[];
|
|
5
5
|
client: StatsigClientInterface;
|
|
6
6
|
};
|
|
7
|
-
export
|
|
8
|
-
export {};
|
|
7
|
+
export declare function StatsigProvider({ client, children, }: StatsigProviderProps): JSX.Element;
|
package/src/StatsigProvider.js
CHANGED
|
@@ -1,30 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
(0, react_1.useEffect)(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
setRenderVersion(function (v) { return v + 1; });
|
|
14
|
-
}
|
|
3
|
+
exports.StatsigProvider = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const client_core_1 = require("@statsig/client-core");
|
|
7
|
+
const StatsigContext_1 = require("./StatsigContext");
|
|
8
|
+
function StatsigProvider({ client, children, }) {
|
|
9
|
+
const [renderVersion, setRenderVersion] = (0, react_1.useState)(0);
|
|
10
|
+
(0, react_1.useEffect)(() => {
|
|
11
|
+
const onValuesUpdated = () => {
|
|
12
|
+
setRenderVersion((v) => v + 1);
|
|
15
13
|
};
|
|
16
|
-
|
|
17
|
-
client
|
|
18
|
-
return
|
|
19
|
-
client.shutdown().catch(
|
|
14
|
+
client_core_1.SDKType._setBindingType('react');
|
|
15
|
+
client.$on('values_updated', onValuesUpdated);
|
|
16
|
+
return () => {
|
|
17
|
+
client.shutdown().catch((error) => {
|
|
20
18
|
client_core_1.Log.error('An error occured during shutdown', error);
|
|
21
19
|
});
|
|
22
|
-
client.off('
|
|
20
|
+
client.off('values_updated', onValuesUpdated);
|
|
23
21
|
};
|
|
24
22
|
}, [client]);
|
|
25
|
-
return ((0, jsx_runtime_1.jsx)(StatsigContext_1.default.Provider, { value: { renderVersion
|
|
23
|
+
return ((0, jsx_runtime_1.jsx)(StatsigContext_1.default.Provider, { value: { renderVersion, client }, children: _shouldRender(client) ? children : null }));
|
|
26
24
|
}
|
|
27
|
-
exports.
|
|
25
|
+
exports.StatsigProvider = StatsigProvider;
|
|
28
26
|
function _shouldRender(client) {
|
|
29
27
|
if ('isNoop' in client) {
|
|
30
28
|
return true;
|
package/src/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import StatsigContext from './StatsigContext';
|
|
2
|
-
import StatsigProvider from './StatsigProvider';
|
|
2
|
+
import { StatsigProvider, StatsigProviderProps } from './StatsigProvider';
|
|
3
3
|
import useDynamicConfig from './useDynamicConfig';
|
|
4
4
|
import useExperiment from './useExperiment';
|
|
5
|
-
import
|
|
5
|
+
import useFeatureGate from './useFeatureGate';
|
|
6
|
+
import useGateValue from './useGateValue';
|
|
6
7
|
import useLayer from './useLayer';
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import useStatsigUser from './useStatsigUser';
|
|
10
|
-
export {
|
|
8
|
+
import { useStatsigClient } from './useStatsigClient';
|
|
9
|
+
import { useStatsigOnDeviceEvalClient } from './useStatsigOnDeviceEvalClient';
|
|
10
|
+
import { useStatsigUser } from './useStatsigUser';
|
|
11
|
+
export type { StatsigProviderProps };
|
|
12
|
+
export { StatsigContext, StatsigProvider, useDynamicConfig, useExperiment, useGateValue, useFeatureGate, useLayer, useStatsigOnDeviceEvalClient, useStatsigClient, useStatsigUser, };
|
package/src/index.js
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.
|
|
15
|
-
|
|
3
|
+
exports.useStatsigUser = exports.useStatsigClient = exports.useStatsigOnDeviceEvalClient = exports.useLayer = exports.useFeatureGate = exports.useGateValue = exports.useExperiment = exports.useDynamicConfig = exports.StatsigProvider = exports.StatsigContext = void 0;
|
|
4
|
+
const StatsigContext_1 = require("./StatsigContext");
|
|
16
5
|
exports.StatsigContext = StatsigContext_1.default;
|
|
17
|
-
|
|
18
|
-
exports
|
|
19
|
-
|
|
6
|
+
const StatsigProvider_1 = require("./StatsigProvider");
|
|
7
|
+
Object.defineProperty(exports, "StatsigProvider", { enumerable: true, get: function () { return StatsigProvider_1.StatsigProvider; } });
|
|
8
|
+
const useDynamicConfig_1 = require("./useDynamicConfig");
|
|
20
9
|
exports.useDynamicConfig = useDynamicConfig_1.default;
|
|
21
|
-
|
|
10
|
+
const useExperiment_1 = require("./useExperiment");
|
|
22
11
|
exports.useExperiment = useExperiment_1.default;
|
|
23
|
-
|
|
24
|
-
exports.
|
|
25
|
-
|
|
12
|
+
const useFeatureGate_1 = require("./useFeatureGate");
|
|
13
|
+
exports.useFeatureGate = useFeatureGate_1.default;
|
|
14
|
+
const useGateValue_1 = require("./useGateValue");
|
|
15
|
+
exports.useGateValue = useGateValue_1.default;
|
|
16
|
+
const useLayer_1 = require("./useLayer");
|
|
26
17
|
exports.useLayer = useLayer_1.default;
|
|
27
|
-
|
|
28
|
-
exports
|
|
29
|
-
|
|
30
|
-
exports
|
|
31
|
-
|
|
32
|
-
exports
|
|
33
|
-
__STATSIG__ =
|
|
18
|
+
const useStatsigClient_1 = require("./useStatsigClient");
|
|
19
|
+
Object.defineProperty(exports, "useStatsigClient", { enumerable: true, get: function () { return useStatsigClient_1.useStatsigClient; } });
|
|
20
|
+
const useStatsigOnDeviceEvalClient_1 = require("./useStatsigOnDeviceEvalClient");
|
|
21
|
+
Object.defineProperty(exports, "useStatsigOnDeviceEvalClient", { enumerable: true, get: function () { return useStatsigOnDeviceEvalClient_1.useStatsigOnDeviceEvalClient; } });
|
|
22
|
+
const useStatsigUser_1 = require("./useStatsigUser");
|
|
23
|
+
Object.defineProperty(exports, "useStatsigUser", { enumerable: true, get: function () { return useStatsigUser_1.useStatsigUser; } });
|
|
24
|
+
__STATSIG__ = Object.assign(Object.assign({}, (__STATSIG__ !== null && __STATSIG__ !== void 0 ? __STATSIG__ : {})), { StatsigContext: StatsigContext_1.default,
|
|
25
|
+
StatsigProvider: StatsigProvider_1.StatsigProvider,
|
|
26
|
+
useDynamicConfig: useDynamicConfig_1.default,
|
|
27
|
+
useExperiment: useExperiment_1.default,
|
|
28
|
+
useGateValue: useGateValue_1.default,
|
|
29
|
+
useFeatureGate: useFeatureGate_1.default,
|
|
30
|
+
useLayer: useLayer_1.default,
|
|
31
|
+
useStatsigOnDeviceEvalClient: useStatsigOnDeviceEvalClient_1.useStatsigOnDeviceEvalClient,
|
|
32
|
+
useStatsigClient: useStatsigClient_1.useStatsigClient });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { DynamicConfig } from '@statsig/client-core';
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { DynamicConfig, DynamicConfigEvaluationOptions, StatsigUser } from '@statsig/client-core';
|
|
2
|
+
export type UseDynamicConfigOptions = DynamicConfigEvaluationOptions & {
|
|
3
|
+
user: StatsigUser | null;
|
|
4
|
+
};
|
|
4
5
|
export default function (configName: string, options?: UseDynamicConfigOptions): DynamicConfig;
|
package/src/useDynamicConfig.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const client_core_1 = require("@statsig/client-core");
|
|
5
|
+
const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
|
|
6
|
+
const OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
|
|
7
|
+
const StatsigContext_1 = require("./StatsigContext");
|
|
16
8
|
function default_1(configName, options) {
|
|
17
|
-
|
|
18
|
-
return (0,
|
|
9
|
+
const { client, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
|
|
10
|
+
return (0, react_1.useMemo)(() => {
|
|
11
|
+
if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvalClient)(client)) {
|
|
12
|
+
return client.getDynamicConfig(configName, options);
|
|
13
|
+
}
|
|
14
|
+
if ((options === null || options === void 0 ? void 0 : options.user) != null) {
|
|
15
|
+
return client.getDynamicConfig(configName, options.user, options);
|
|
16
|
+
}
|
|
17
|
+
client_core_1.Log.warn(`useDynamicConfig hook failed to find a valid Statsig client for dynamic config '${configName}'.`);
|
|
18
|
+
return NoopEvaluationsClient_1.NoopEvaluationsClient.getDynamicConfig(configName, options);
|
|
19
|
+
}, [configName, client, renderVersion, options]);
|
|
19
20
|
}
|
|
20
21
|
exports.default = default_1;
|
package/src/useExperiment.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Experiment } from '@statsig/client-core';
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Experiment, ExperimentEvaluationOptions, StatsigUser } from '@statsig/client-core';
|
|
2
|
+
export type UseExperimentOptions = ExperimentEvaluationOptions & {
|
|
3
|
+
user: StatsigUser | null;
|
|
4
|
+
};
|
|
4
5
|
export default function (experimentName: string, options?: UseExperimentOptions): Experiment;
|
package/src/useExperiment.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const client_core_1 = require("@statsig/client-core");
|
|
5
|
+
const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
|
|
6
|
+
const OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
|
|
7
|
+
const StatsigContext_1 = require("./StatsigContext");
|
|
16
8
|
function default_1(experimentName, options) {
|
|
17
|
-
|
|
18
|
-
return (0,
|
|
9
|
+
const { client, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
|
|
10
|
+
return (0, react_1.useMemo)(() => {
|
|
11
|
+
if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvalClient)(client)) {
|
|
12
|
+
return client.getExperiment(experimentName, options);
|
|
13
|
+
}
|
|
14
|
+
if ((options === null || options === void 0 ? void 0 : options.user) != null) {
|
|
15
|
+
return client.getExperiment(experimentName, options.user, options);
|
|
16
|
+
}
|
|
17
|
+
client_core_1.Log.warn(`useExperiment hook failed to find a valid Statsig client for experiment '${experimentName}'.`);
|
|
18
|
+
return NoopEvaluationsClient_1.NoopEvaluationsClient.getExperiment(experimentName, options);
|
|
19
|
+
}, [experimentName, client, renderVersion, options]);
|
|
19
20
|
}
|
|
20
21
|
exports.default = default_1;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { FeatureGate, FeatureGateEvaluationOptions, StatsigUser } from '@statsig/client-core';
|
|
2
|
+
export type useFeatureGateOptions = FeatureGateEvaluationOptions & {
|
|
3
|
+
user: StatsigUser | null;
|
|
4
|
+
};
|
|
5
|
+
export default function (gateName: string, options?: useFeatureGateOptions): FeatureGate;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const client_core_1 = require("@statsig/client-core");
|
|
5
|
+
const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
|
|
6
|
+
const OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
|
|
7
|
+
const StatsigContext_1 = require("./StatsigContext");
|
|
8
|
+
function default_1(gateName, options) {
|
|
9
|
+
const { client, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
|
|
10
|
+
const gate = (0, react_1.useMemo)(() => {
|
|
11
|
+
if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvalClient)(client)) {
|
|
12
|
+
return client.getFeatureGate(gateName, options);
|
|
13
|
+
}
|
|
14
|
+
if ((options === null || options === void 0 ? void 0 : options.user) != null) {
|
|
15
|
+
return client.getFeatureGate(gateName, options.user, options);
|
|
16
|
+
}
|
|
17
|
+
client_core_1.Log.warn(`useFeatureGate hook failed to find a valid Statsig client for gate '${gateName}'.`);
|
|
18
|
+
return NoopEvaluationsClient_1.NoopEvaluationsClient.getFeatureGate(gateName, options);
|
|
19
|
+
}, [gateName, client, renderVersion, options]);
|
|
20
|
+
return gate;
|
|
21
|
+
}
|
|
22
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { FeatureGateEvaluationOptions, StatsigUser } from '@statsig/client-core';
|
|
2
|
+
export type useFeatureGateOptions = FeatureGateEvaluationOptions & {
|
|
3
|
+
user: StatsigUser | null;
|
|
4
|
+
};
|
|
5
|
+
export default function (gateName: string, options?: useFeatureGateOptions): boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const client_core_1 = require("@statsig/client-core");
|
|
5
|
+
const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
|
|
6
|
+
const OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
|
|
7
|
+
const StatsigContext_1 = require("./StatsigContext");
|
|
8
|
+
function default_1(gateName, options) {
|
|
9
|
+
const { client, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
|
|
10
|
+
const gate = (0, react_1.useMemo)(() => {
|
|
11
|
+
if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvalClient)(client)) {
|
|
12
|
+
return client.checkGate(gateName, options);
|
|
13
|
+
}
|
|
14
|
+
if ((options === null || options === void 0 ? void 0 : options.user) != null) {
|
|
15
|
+
return client.checkGate(gateName, options.user, options);
|
|
16
|
+
}
|
|
17
|
+
client_core_1.Log.warn(`useFeatureGate hook failed to find a valid Statsig client for gate '${gateName}'.`);
|
|
18
|
+
return NoopEvaluationsClient_1.NoopEvaluationsClient.checkGate(gateName, options);
|
|
19
|
+
}, [gateName, client, renderVersion, options]);
|
|
20
|
+
return gate;
|
|
21
|
+
}
|
|
22
|
+
exports.default = default_1;
|
package/src/useLayer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type UseLayerOptions =
|
|
1
|
+
import { Layer, LayerEvaluationOptions, StatsigUser } from '@statsig/client-core';
|
|
2
|
+
export type UseLayerOptions = LayerEvaluationOptions & {
|
|
3
3
|
user: StatsigUser | null;
|
|
4
4
|
};
|
|
5
5
|
export default function (layerName: string, options?: UseLayerOptions): Layer;
|
package/src/useLayer.js
CHANGED
|
@@ -1,34 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const client_core_1 = require("@statsig/client-core");
|
|
5
|
+
const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
|
|
6
|
+
const OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
|
|
7
|
+
const StatsigContext_1 = require("./StatsigContext");
|
|
19
8
|
function default_1(layerName, options) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvaluationsClient)(client)) {
|
|
9
|
+
const { client, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
|
|
10
|
+
const layer = (0, react_1.useMemo)(() => {
|
|
11
|
+
if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvalClient)(client)) {
|
|
24
12
|
return client.getLayer(layerName, options);
|
|
25
13
|
}
|
|
26
|
-
if (options.user != null) {
|
|
14
|
+
if ((options === null || options === void 0 ? void 0 : options.user) != null) {
|
|
27
15
|
return client.getLayer(layerName, options.user, options);
|
|
28
16
|
}
|
|
29
|
-
client_core_1.Log.warn(
|
|
17
|
+
client_core_1.Log.warn(`useLayer hook failed to find a valid Statsig client for layer '${layerName}'.`);
|
|
30
18
|
return NoopEvaluationsClient_1.NoopEvaluationsClient.getLayer(layerName, options);
|
|
31
|
-
}, [client
|
|
19
|
+
}, [layerName, client, renderVersion, options]);
|
|
32
20
|
return layer;
|
|
33
21
|
}
|
|
34
22
|
exports.default = default_1;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { PrecomputedEvaluationsInterface } from '@statsig/client-core';
|
|
2
|
+
type HositedFuncs = Pick<PrecomputedEvaluationsInterface, 'checkGate' | 'getFeatureGate' | 'getDynamicConfig' | 'getExperiment' | 'getLayer' | 'logEvent'>;
|
|
3
|
+
export declare function useStatsigClient(): HositedFuncs & {
|
|
4
|
+
client: PrecomputedEvaluationsInterface;
|
|
5
|
+
};
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useStatsigClient = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const client_core_1 = require("@statsig/client-core");
|
|
6
|
+
const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
|
|
7
|
+
const OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
|
|
8
|
+
const StatsigContext_1 = require("./StatsigContext");
|
|
9
|
+
function useStatsigClient() {
|
|
10
|
+
const { client: anyClient, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
|
|
11
|
+
const client = (0, react_1.useMemo)(() => {
|
|
12
|
+
if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvalClient)(anyClient)) {
|
|
13
|
+
return anyClient;
|
|
14
|
+
}
|
|
15
|
+
client_core_1.Log.warn('Attempting to retrieve a StatsigClient but none was set.');
|
|
16
|
+
return NoopEvaluationsClient_1.NoopEvaluationsClient;
|
|
17
|
+
}, [anyClient, renderVersion]);
|
|
18
|
+
const deps = [client, renderVersion];
|
|
19
|
+
return {
|
|
20
|
+
client,
|
|
21
|
+
checkGate: (0, react_1.useCallback)((name, options) => {
|
|
22
|
+
return client.checkGate(name, options);
|
|
23
|
+
}, deps),
|
|
24
|
+
getFeatureGate: (0, react_1.useCallback)((name, options) => {
|
|
25
|
+
return client.getFeatureGate(name, options);
|
|
26
|
+
}, deps),
|
|
27
|
+
getDynamicConfig: (0, react_1.useCallback)((name, options) => {
|
|
28
|
+
return client.getDynamicConfig(name, options);
|
|
29
|
+
}, deps),
|
|
30
|
+
getExperiment: (0, react_1.useCallback)((name, options) => {
|
|
31
|
+
return client.getExperiment(name, options);
|
|
32
|
+
}, deps),
|
|
33
|
+
getLayer: (0, react_1.useCallback)((name, options) => {
|
|
34
|
+
return client.getLayer(name, options);
|
|
35
|
+
}, deps),
|
|
36
|
+
logEvent: (0, react_1.useCallback)((eventName, value, metadata) => {
|
|
37
|
+
if (typeof eventName === 'string') {
|
|
38
|
+
return client.logEvent(eventName, value, metadata);
|
|
39
|
+
}
|
|
40
|
+
return client.logEvent(eventName);
|
|
41
|
+
}, deps),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
exports.useStatsigClient = useStatsigClient;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { OnDeviceEvaluationsInterface } from '@statsig/client-core';
|
|
2
|
+
type HositedFuncs = Pick<OnDeviceEvaluationsInterface, 'checkGate' | 'getFeatureGate' | 'getDynamicConfig' | 'getExperiment' | 'getLayer' | 'logEvent'>;
|
|
3
|
+
export declare function useStatsigOnDeviceEvalClient(): HositedFuncs & {
|
|
4
|
+
client: OnDeviceEvaluationsInterface;
|
|
5
|
+
};
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useStatsigOnDeviceEvalClient = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const client_core_1 = require("@statsig/client-core");
|
|
6
|
+
const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
|
|
7
|
+
const OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
|
|
8
|
+
const StatsigContext_1 = require("./StatsigContext");
|
|
9
|
+
function useStatsigOnDeviceEvalClient() {
|
|
10
|
+
const { client: anyClient, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
|
|
11
|
+
const client = (0, react_1.useMemo)(() => {
|
|
12
|
+
if (!(0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvalClient)(anyClient)) {
|
|
13
|
+
return anyClient;
|
|
14
|
+
}
|
|
15
|
+
client_core_1.Log.warn('Attempting to retrieve a StatsigOnDeviceEvalClient but none was set.');
|
|
16
|
+
return NoopEvaluationsClient_1.NoopEvaluationsClient;
|
|
17
|
+
}, [anyClient, renderVersion]);
|
|
18
|
+
const deps = [client, renderVersion];
|
|
19
|
+
return {
|
|
20
|
+
client,
|
|
21
|
+
checkGate: (0, react_1.useCallback)((name, options) => {
|
|
22
|
+
return client.checkGate(name, options);
|
|
23
|
+
}, deps),
|
|
24
|
+
getFeatureGate: (0, react_1.useCallback)((name, options) => {
|
|
25
|
+
return client.getFeatureGate(name, options);
|
|
26
|
+
}, deps),
|
|
27
|
+
getDynamicConfig: (0, react_1.useCallback)((name, options) => {
|
|
28
|
+
return client.getDynamicConfig(name, options);
|
|
29
|
+
}, deps),
|
|
30
|
+
getExperiment: (0, react_1.useCallback)((name, options) => {
|
|
31
|
+
return client.getExperiment(name, options);
|
|
32
|
+
}, deps),
|
|
33
|
+
getLayer: (0, react_1.useCallback)((name, options) => {
|
|
34
|
+
return client.getLayer(name, options);
|
|
35
|
+
}, deps),
|
|
36
|
+
logEvent: (0, react_1.useCallback)((eventName, user, value, metadata) => {
|
|
37
|
+
if (typeof eventName === 'string') {
|
|
38
|
+
return client.logEvent(eventName, user, value, metadata);
|
|
39
|
+
}
|
|
40
|
+
return client.logEvent(eventName, user);
|
|
41
|
+
}, deps),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
exports.useStatsigOnDeviceEvalClient = useStatsigOnDeviceEvalClient;
|
package/src/useStatsigUser.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { StatsigUser } from '@statsig/client-core';
|
|
2
|
+
type UpdaterArg = StatsigUser | ((previous: StatsigUser) => StatsigUser);
|
|
3
|
+
type UpdaterFunc<T> = (updated: UpdaterArg) => T;
|
|
4
|
+
type SyncUpdateFunc = UpdaterFunc<void>;
|
|
5
|
+
type AsyncUpdateFunc = UpdaterFunc<Promise<void>>;
|
|
2
6
|
export type UseStatsigUserResult = {
|
|
3
7
|
user: StatsigUser;
|
|
4
|
-
updateUserSync:
|
|
5
|
-
updateUserAsync:
|
|
8
|
+
updateUserSync: SyncUpdateFunc;
|
|
9
|
+
updateUserAsync: AsyncUpdateFunc;
|
|
6
10
|
};
|
|
7
|
-
export
|
|
11
|
+
export declare function useStatsigUser(): UseStatsigUserResult;
|
|
12
|
+
export {};
|
package/src/useStatsigUser.js
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
exports.useStatsigUser = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const StatsigContext_1 = require("./StatsigContext");
|
|
6
|
+
const useStatsigClient_1 = require("./useStatsigClient");
|
|
7
|
+
function useStatsigUser() {
|
|
8
|
+
const { client } = (0, useStatsigClient_1.useStatsigClient)();
|
|
9
|
+
const { renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
|
|
10
|
+
const deps = [client, renderVersion];
|
|
11
|
+
const memoUser = (0, react_1.useMemo)(() => {
|
|
12
|
+
const context = client.getContext();
|
|
13
|
+
return context.user;
|
|
14
|
+
}, deps);
|
|
6
15
|
return {
|
|
7
|
-
user:
|
|
8
|
-
updateUserSync:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
user: memoUser,
|
|
17
|
+
updateUserSync: (0, react_1.useCallback)((arg) => {
|
|
18
|
+
if (typeof arg === 'function') {
|
|
19
|
+
arg = arg(memoUser);
|
|
20
|
+
}
|
|
21
|
+
client.updateUserSync(arg);
|
|
22
|
+
}, deps),
|
|
23
|
+
updateUserAsync: (0, react_1.useCallback)((arg) => {
|
|
24
|
+
if (typeof arg === 'function') {
|
|
25
|
+
arg = arg(memoUser);
|
|
26
|
+
}
|
|
27
|
+
return client.updateUserAsync(arg);
|
|
28
|
+
}, deps),
|
|
16
29
|
};
|
|
17
30
|
}
|
|
18
|
-
exports.
|
|
31
|
+
exports.useStatsigUser = useStatsigUser;
|
package/src/useConfigImpl.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { DynamicConfig, EvaluationOptions, StatsigUser } from '@statsig/client-core';
|
|
2
|
-
export type UseConfigOptions = EvaluationOptions & {
|
|
3
|
-
user: StatsigUser | null;
|
|
4
|
-
};
|
|
5
|
-
export declare function useConfigImpl(hook: 'useExperiment' | 'useDynamicConfig', configName: string, options?: UseConfigOptions): DynamicConfig;
|
package/src/useConfigImpl.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.useConfigImpl = void 0;
|
|
15
|
-
var react_1 = require("react");
|
|
16
|
-
var client_core_1 = require("@statsig/client-core");
|
|
17
|
-
var NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
|
|
18
|
-
var OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
|
|
19
|
-
var StatsigContext_1 = require("./StatsigContext");
|
|
20
|
-
function useConfigImpl(hook, configName, options) {
|
|
21
|
-
if (options === void 0) { options = __assign(__assign({}, client_core_1.DEFAULT_EVAL_OPTIONS), { user: null }); }
|
|
22
|
-
var client = (0, react_1.useContext)(StatsigContext_1.default).client;
|
|
23
|
-
var config = (0, react_1.useMemo)(function () {
|
|
24
|
-
if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvaluationsClient)(client)) {
|
|
25
|
-
return client.getDynamicConfig(configName, options);
|
|
26
|
-
}
|
|
27
|
-
if (options.user != null) {
|
|
28
|
-
return client.getDynamicConfig(configName, options.user, options);
|
|
29
|
-
}
|
|
30
|
-
var type = hook === 'useDynamicConfig' ? 'dynamic config' : 'experiment';
|
|
31
|
-
client_core_1.Log.warn("".concat(hook, " hook failed to find a valid Statsig client for ").concat(type, " '").concat(configName, "'."));
|
|
32
|
-
return NoopEvaluationsClient_1.NoopEvaluationsClient.getDynamicConfig(configName, options);
|
|
33
|
-
}, [client.loadingStatus, options]);
|
|
34
|
-
return config;
|
|
35
|
-
}
|
|
36
|
-
exports.useConfigImpl = useConfigImpl;
|
package/src/useGate.d.ts
DELETED
package/src/useGate.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
var react_1 = require("react");
|
|
15
|
-
var client_core_1 = require("@statsig/client-core");
|
|
16
|
-
var NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
|
|
17
|
-
var OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
|
|
18
|
-
var StatsigContext_1 = require("./StatsigContext");
|
|
19
|
-
function default_1(gateName, options) {
|
|
20
|
-
if (options === void 0) { options = __assign(__assign({}, client_core_1.DEFAULT_EVAL_OPTIONS), { user: null }); }
|
|
21
|
-
var client = (0, react_1.useContext)(StatsigContext_1.default).client;
|
|
22
|
-
var gate = (0, react_1.useMemo)(function () {
|
|
23
|
-
if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvaluationsClient)(client)) {
|
|
24
|
-
return client.getFeatureGate(gateName, options);
|
|
25
|
-
}
|
|
26
|
-
if (options.user != null) {
|
|
27
|
-
return client.getFeatureGate(gateName, options.user, options);
|
|
28
|
-
}
|
|
29
|
-
client_core_1.Log.warn("useGate hook failed to find a valid Statsig client for gate '".concat(gateName, "'."));
|
|
30
|
-
return NoopEvaluationsClient_1.NoopEvaluationsClient.getFeatureGate(gateName, options);
|
|
31
|
-
}, [client.loadingStatus, options]);
|
|
32
|
-
return gate;
|
|
33
|
-
}
|
|
34
|
-
exports.default = default_1;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var react_1 = require("react");
|
|
4
|
-
var client_core_1 = require("@statsig/client-core");
|
|
5
|
-
var NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
|
|
6
|
-
var OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
|
|
7
|
-
var StatsigContext_1 = require("./StatsigContext");
|
|
8
|
-
function default_1() {
|
|
9
|
-
var client = (0, react_1.useContext)(StatsigContext_1.default).client;
|
|
10
|
-
if (!(0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvaluationsClient)(client)) {
|
|
11
|
-
return client;
|
|
12
|
-
}
|
|
13
|
-
client_core_1.Log.warn('Attempting to retrive a Statsig OnDeviceEvaluationsClient but none was set.');
|
|
14
|
-
return NoopEvaluationsClient_1.NoopEvaluationsClient;
|
|
15
|
-
}
|
|
16
|
-
exports.default = default_1;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var react_1 = require("react");
|
|
4
|
-
var client_core_1 = require("@statsig/client-core");
|
|
5
|
-
var NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
|
|
6
|
-
var OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
|
|
7
|
-
var StatsigContext_1 = require("./StatsigContext");
|
|
8
|
-
function default_1() {
|
|
9
|
-
var client = (0, react_1.useContext)(StatsigContext_1.default).client;
|
|
10
|
-
if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvaluationsClient)(client)) {
|
|
11
|
-
return client;
|
|
12
|
-
}
|
|
13
|
-
client_core_1.Log.warn('Attempting to retrive a Statsig PrecomputedEvaluationsClient but none was set.');
|
|
14
|
-
return NoopEvaluationsClient_1.NoopEvaluationsClient;
|
|
15
|
-
}
|
|
16
|
-
exports.default = default_1;
|