@statsig/react-bindings 0.0.1-beta.22 → 0.0.1-beta.23
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/package.json +2 -2
- package/src/NoopEvaluationsClient.js +8 -1
- package/src/index.d.ts +3 -2
- package/src/index.js +7 -4
- package/src/useExperiment.js +1 -1
- package/src/useFeatureGate.d.ts +5 -0
- package/src/{useGate.js → useFeatureGate.js} +1 -1
- package/src/useGateValue.d.ts +5 -0
- package/src/useGateValue.js +22 -0
- package/src/useStatsigUser.js +5 -2
- package/src/useGate.d.ts +0 -5
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statsig/react-bindings",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.23",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@statsig/client-core": "0.0.1-beta.
|
|
5
|
+
"@statsig/client-core": "0.0.1-beta.23"
|
|
6
6
|
},
|
|
7
7
|
"peerDependencies": {
|
|
8
8
|
"react": "^16.6.3 || ^17.0.0 || ^18.0.0"
|
|
@@ -34,10 +34,17 @@ const _client = {
|
|
|
34
34
|
initializeSync: _noop,
|
|
35
35
|
initializeAsync: _noopAsync,
|
|
36
36
|
shutdown: _noopAsync,
|
|
37
|
+
flush: _noopAsync,
|
|
37
38
|
updateRuntimeOptions: _noop,
|
|
38
39
|
updateUserSync: _noop,
|
|
39
40
|
updateUserAsync: _noopAsync,
|
|
40
|
-
|
|
41
|
+
getContext: () => ({
|
|
42
|
+
sdkKey: '',
|
|
43
|
+
sessionID: '',
|
|
44
|
+
options: {},
|
|
45
|
+
values: null,
|
|
46
|
+
user: { userID: '' },
|
|
47
|
+
}),
|
|
41
48
|
checkGate: () => false,
|
|
42
49
|
getFeatureGate: _defaultEvaluation('gate'),
|
|
43
50
|
getDynamicConfig: _defaultEvaluation('config'),
|
package/src/index.d.ts
CHANGED
|
@@ -2,10 +2,11 @@ import StatsigContext from './StatsigContext';
|
|
|
2
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
8
|
import { useStatsigClient } from './useStatsigClient';
|
|
8
9
|
import { useStatsigOnDeviceEvalClient } from './useStatsigOnDeviceEvalClient';
|
|
9
10
|
import { useStatsigUser } from './useStatsigUser';
|
|
10
11
|
export type { StatsigProviderProps };
|
|
11
|
-
export { StatsigContext, StatsigProvider, useDynamicConfig, useExperiment,
|
|
12
|
+
export { StatsigContext, StatsigProvider, useDynamicConfig, useExperiment, useGateValue, useFeatureGate, useLayer, useStatsigOnDeviceEvalClient, useStatsigClient, useStatsigUser, };
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useStatsigUser = exports.useStatsigClient = exports.useStatsigOnDeviceEvalClient = exports.useLayer = exports.
|
|
3
|
+
exports.useStatsigUser = exports.useStatsigClient = exports.useStatsigOnDeviceEvalClient = exports.useLayer = exports.useFeatureGate = exports.useGateValue = exports.useExperiment = exports.useDynamicConfig = exports.StatsigProvider = exports.StatsigContext = void 0;
|
|
4
4
|
const StatsigContext_1 = require("./StatsigContext");
|
|
5
5
|
exports.StatsigContext = StatsigContext_1.default;
|
|
6
6
|
const StatsigProvider_1 = require("./StatsigProvider");
|
|
@@ -9,8 +9,10 @@ const useDynamicConfig_1 = require("./useDynamicConfig");
|
|
|
9
9
|
exports.useDynamicConfig = useDynamicConfig_1.default;
|
|
10
10
|
const useExperiment_1 = require("./useExperiment");
|
|
11
11
|
exports.useExperiment = useExperiment_1.default;
|
|
12
|
-
const
|
|
13
|
-
exports.
|
|
12
|
+
const useFeatureGate_1 = require("./useFeatureGate");
|
|
13
|
+
exports.useFeatureGate = useFeatureGate_1.default;
|
|
14
|
+
const useGateValue_1 = require("./useGateValue");
|
|
15
|
+
exports.useGateValue = useGateValue_1.default;
|
|
14
16
|
const useLayer_1 = require("./useLayer");
|
|
15
17
|
exports.useLayer = useLayer_1.default;
|
|
16
18
|
const useStatsigClient_1 = require("./useStatsigClient");
|
|
@@ -23,7 +25,8 @@ __STATSIG__ = Object.assign(Object.assign({}, (__STATSIG__ !== null && __STATSIG
|
|
|
23
25
|
StatsigProvider: StatsigProvider_1.StatsigProvider,
|
|
24
26
|
useDynamicConfig: useDynamicConfig_1.default,
|
|
25
27
|
useExperiment: useExperiment_1.default,
|
|
26
|
-
|
|
28
|
+
useGateValue: useGateValue_1.default,
|
|
29
|
+
useFeatureGate: useFeatureGate_1.default,
|
|
27
30
|
useLayer: useLayer_1.default,
|
|
28
31
|
useStatsigOnDeviceEvalClient: useStatsigOnDeviceEvalClient_1.useStatsigOnDeviceEvalClient,
|
|
29
32
|
useStatsigClient: useStatsigClient_1.useStatsigClient });
|
package/src/useExperiment.js
CHANGED
|
@@ -14,7 +14,7 @@ function default_1(experimentName, options) {
|
|
|
14
14
|
if ((options === null || options === void 0 ? void 0 : options.user) != null) {
|
|
15
15
|
return client.getExperiment(experimentName, options.user, options);
|
|
16
16
|
}
|
|
17
|
-
client_core_1.Log.warn(`
|
|
17
|
+
client_core_1.Log.warn(`useExperiment hook failed to find a valid Statsig client for experiment '${experimentName}'.`);
|
|
18
18
|
return NoopEvaluationsClient_1.NoopEvaluationsClient.getExperiment(experimentName, options);
|
|
19
19
|
}, [experimentName, renderVersion, options]);
|
|
20
20
|
}
|
|
@@ -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;
|
|
@@ -14,7 +14,7 @@ function default_1(gateName, options) {
|
|
|
14
14
|
if ((options === null || options === void 0 ? void 0 : options.user) != null) {
|
|
15
15
|
return client.getFeatureGate(gateName, options.user, options);
|
|
16
16
|
}
|
|
17
|
-
client_core_1.Log.warn(`
|
|
17
|
+
client_core_1.Log.warn(`useFeatureGate hook failed to find a valid Statsig client for gate '${gateName}'.`);
|
|
18
18
|
return NoopEvaluationsClient_1.NoopEvaluationsClient.getFeatureGate(gateName, options);
|
|
19
19
|
}, [gateName, renderVersion, options]);
|
|
20
20
|
return gate;
|
|
@@ -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, renderVersion, options]);
|
|
20
|
+
return gate;
|
|
21
|
+
}
|
|
22
|
+
exports.default = default_1;
|
package/src/useStatsigUser.js
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useStatsigUser = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
+
const StatsigContext_1 = require("./StatsigContext");
|
|
5
6
|
const useStatsigClient_1 = require("./useStatsigClient");
|
|
6
7
|
function useStatsigUser() {
|
|
7
8
|
const client = (0, useStatsigClient_1.useStatsigClient)();
|
|
9
|
+
const { renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
|
|
8
10
|
const memoUser = (0, react_1.useMemo)(() => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
const context = client.getContext();
|
|
12
|
+
return context.user;
|
|
13
|
+
}, [client, renderVersion]);
|
|
11
14
|
return {
|
|
12
15
|
user: memoUser,
|
|
13
16
|
updateUserSync: (fn) => {
|
package/src/useGate.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { FeatureGate, FeatureGateEvaluationOptions, StatsigUser } from '@statsig/client-core';
|
|
2
|
-
export type UseGateOptions = FeatureGateEvaluationOptions & {
|
|
3
|
-
user: StatsigUser | null;
|
|
4
|
-
};
|
|
5
|
-
export default function (gateName: string, options?: UseGateOptions): FeatureGate;
|