@statsig/react-bindings 0.0.1-beta.2 → 0.0.1-beta.20
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 +1 -1
- package/package.json +2 -2
- package/src/NoopEvaluationsClient.js +36 -26
- package/src/OnDeviceVsPrecomputedUtils.d.ts +2 -1
- package/src/OnDeviceVsPrecomputedUtils.js +12 -5
- package/src/StatsigContext.d.ts +2 -3
- package/src/StatsigContext.js +3 -3
- package/src/StatsigProvider.d.ts +5 -10
- package/src/StatsigProvider.js +19 -46
- package/src/index.d.ts +6 -2
- package/src/index.js +22 -20
- package/src/useDynamicConfig.d.ts +2 -2
- package/src/useDynamicConfig.js +15 -22
- package/src/useExperiment.d.ts +4 -3
- package/src/useExperiment.js +16 -16
- package/src/useGate.d.ts +2 -2
- package/src/useGate.js +15 -21
- package/src/useLayer.d.ts +2 -2
- package/src/useLayer.js +15 -21
- package/src/useStatsigClient.d.ts +2 -5
- package/src/useStatsigClient.js +14 -5
- package/src/useStatsigOnDeviceEvalClient.d.ts +2 -0
- package/src/useStatsigOnDeviceEvalClient.js +17 -0
- package/src/useStatsigUser.d.ts +7 -0
- package/src/useStatsigUser.js +23 -0
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,41 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NoopEvaluationsClient = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const client_core_1 = require("@statsig/client-core");
|
|
5
|
+
const _noop = () => {
|
|
6
6
|
// noop
|
|
7
7
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
var name = typeof args[0] === 'string' ? args[0] : args[1];
|
|
8
|
+
const _noopAsync = () => Promise.resolve();
|
|
9
|
+
const NOOP_DETAILS = { reason: 'Error' };
|
|
10
|
+
const _defaultEvaluation = (type) => {
|
|
11
|
+
return (...args) => {
|
|
12
|
+
const name = typeof args[0] === 'string' ? args[0] : args[1];
|
|
15
13
|
switch (type) {
|
|
16
14
|
case 'gate':
|
|
17
|
-
return (0, client_core_1.makeFeatureGate)(name,
|
|
15
|
+
return (0, client_core_1.makeFeatureGate)(name, NOOP_DETAILS, null);
|
|
18
16
|
case 'config':
|
|
19
|
-
return (0, client_core_1.makeDynamicConfig)(name,
|
|
17
|
+
return (0, client_core_1.makeDynamicConfig)(name, NOOP_DETAILS, null);
|
|
20
18
|
case 'layer':
|
|
21
|
-
return (0, client_core_1.makeLayer)(name,
|
|
19
|
+
return (0, client_core_1.makeLayer)(name, NOOP_DETAILS, null);
|
|
22
20
|
}
|
|
23
21
|
};
|
|
24
22
|
};
|
|
25
|
-
|
|
23
|
+
const _noopDataAdapter = {
|
|
24
|
+
__primeInMemoryCache: _noop,
|
|
25
|
+
attach: _noop,
|
|
26
|
+
getDataSync: () => null,
|
|
27
|
+
getDataAsync: () => Promise.resolve(null),
|
|
28
|
+
setData: _noop,
|
|
29
|
+
prefetchData: _noopAsync,
|
|
30
|
+
};
|
|
31
|
+
const _client = {
|
|
26
32
|
isNoop: true,
|
|
27
33
|
loadingStatus: 'Uninitialized',
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
initializeSync: _noop,
|
|
35
|
+
initializeAsync: _noopAsync,
|
|
36
|
+
shutdown: _noopAsync,
|
|
37
|
+
updateRuntimeOptions: _noop,
|
|
38
|
+
updateUserSync: _noop,
|
|
39
|
+
updateUserAsync: _noopAsync,
|
|
40
|
+
getCurrentUser: () => ({ userID: '' }),
|
|
41
|
+
checkGate: () => false,
|
|
42
|
+
getFeatureGate: _defaultEvaluation('gate'),
|
|
43
|
+
getDynamicConfig: _defaultEvaluation('config'),
|
|
44
|
+
getExperiment: _defaultEvaluation('config'),
|
|
45
|
+
getLayer: _defaultEvaluation('layer'),
|
|
46
|
+
logEvent: _noop,
|
|
47
|
+
on: _noop,
|
|
48
|
+
off: _noop,
|
|
49
|
+
dataAdapter: _noopDataAdapter,
|
|
40
50
|
};
|
|
41
|
-
exports.NoopEvaluationsClient =
|
|
51
|
+
exports.NoopEvaluationsClient = _client;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { OnDeviceEvaluationsInterface, PrecomputedEvaluationsInterface } from '@statsig/client-core';
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function isPrecomputedEvalClient(client: OnDeviceEvaluationsInterface | PrecomputedEvaluationsInterface): client is PrecomputedEvaluationsInterface;
|
|
3
|
+
export declare function isNoopClient(client: OnDeviceEvaluationsInterface | PrecomputedEvaluationsInterface): boolean;
|
|
3
4
|
export declare function logMissingStatsigUserWarning(): void;
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.logMissingStatsigUserWarning = exports.
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
|
|
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
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
return 'updateUserSync' in client;
|
|
7
10
|
}
|
|
8
|
-
exports.
|
|
11
|
+
exports.isPrecomputedEvalClient = isPrecomputedEvalClient;
|
|
12
|
+
function isNoopClient(client) {
|
|
13
|
+
return 'isNoop' in client;
|
|
14
|
+
}
|
|
15
|
+
exports.isNoopClient = isNoopClient;
|
|
9
16
|
function logMissingStatsigUserWarning() {
|
|
10
17
|
client_core_1.Log.warn('StatsigUser not provided for On Device Evaluation. Returning default value.');
|
|
11
18
|
}
|
package/src/StatsigContext.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StatsigClientInterface } from '@statsig/client-core';
|
|
2
2
|
export interface StatsigContext {
|
|
3
3
|
readonly renderVersion: number;
|
|
4
|
-
readonly
|
|
5
|
-
readonly onDeviceClient: OnDeviceEvaluationsInterface;
|
|
4
|
+
readonly client: StatsigClientInterface;
|
|
6
5
|
}
|
|
7
6
|
declare const _default: import("react").Context<StatsigContext>;
|
|
8
7
|
export default _default;
|
package/src/StatsigContext.js
CHANGED
|
@@ -1,8 +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
|
-
|
|
7
|
-
onDeviceClient: {},
|
|
7
|
+
client: NoopEvaluationsClient_1.NoopEvaluationsClient,
|
|
8
8
|
});
|
package/src/StatsigProvider.d.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
type
|
|
2
|
+
import { StatsigClientInterface } from '@statsig/client-core';
|
|
3
|
+
export type StatsigProviderProps = {
|
|
4
4
|
children: ReactNode | ReactNode[];
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
precomputedClient: PrecomputedEvaluationsInterface;
|
|
9
|
-
onDeviceClient: OnDeviceEvaluationsInterface;
|
|
10
|
-
});
|
|
11
|
-
export default function StatsigProvider(props: Props): JSX.Element;
|
|
12
|
-
export {};
|
|
5
|
+
client: StatsigClientInterface;
|
|
6
|
+
};
|
|
7
|
+
export declare function StatsigProvider({ client, children, }: StatsigProviderProps): JSX.Element;
|
package/src/StatsigProvider.js
CHANGED
|
@@ -1,55 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
precomputedClient = (0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvaluationsClient)(props.client)
|
|
14
|
-
? props.client
|
|
15
|
-
: NoopEvaluationsClient_1.NoopEvaluationsClient;
|
|
16
|
-
onDeviceClient = !(0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvaluationsClient)(props.client)
|
|
17
|
-
? props.client
|
|
18
|
-
: NoopEvaluationsClient_1.NoopEvaluationsClient;
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
precomputedClient = props.precomputedClient;
|
|
22
|
-
onDeviceClient = props.onDeviceClient;
|
|
23
|
-
}
|
|
24
|
-
var _a = (0, react_1.useState)(0), renderVersion = _a[0], setRenderVersion = _a[1];
|
|
25
|
-
var clients = [precomputedClient, onDeviceClient];
|
|
26
|
-
(0, react_1.useEffect)(function () {
|
|
27
|
-
var onStatusChange = function (data) {
|
|
28
|
-
if (data.event === 'status_change') {
|
|
29
|
-
setRenderVersion(function (v) { return v + 1; });
|
|
30
|
-
}
|
|
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);
|
|
31
13
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
client.
|
|
35
|
-
client_core_1.Log.error('An error
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
return function () {
|
|
39
|
-
clients.forEach(function (client) {
|
|
40
|
-
client.shutdown().catch(function (error) {
|
|
41
|
-
client_core_1.Log.error('An error occured during shutdown', error);
|
|
42
|
-
});
|
|
43
|
-
client.off('status_change', onStatusChange);
|
|
14
|
+
client.on('values_updated', onValuesUpdated);
|
|
15
|
+
return () => {
|
|
16
|
+
client.shutdown().catch((error) => {
|
|
17
|
+
client_core_1.Log.error('An error occured during shutdown', error);
|
|
44
18
|
});
|
|
19
|
+
client.off('values_updated', onValuesUpdated);
|
|
45
20
|
};
|
|
46
|
-
},
|
|
47
|
-
return ((0, jsx_runtime_1.jsx)(StatsigContext_1.default.Provider, { value: { renderVersion
|
|
48
|
-
? props.children
|
|
49
|
-
: null }));
|
|
21
|
+
}, [client]);
|
|
22
|
+
return ((0, jsx_runtime_1.jsx)(StatsigContext_1.default.Provider, { value: { renderVersion, client }, children: _shouldRender(client) ? children : null }));
|
|
50
23
|
}
|
|
51
|
-
exports.
|
|
52
|
-
function
|
|
24
|
+
exports.StatsigProvider = StatsigProvider;
|
|
25
|
+
function _shouldRender(client) {
|
|
53
26
|
if ('isNoop' in client) {
|
|
54
27
|
return true;
|
|
55
28
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
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
5
|
import useGate from './useGate';
|
|
6
6
|
import useLayer from './useLayer';
|
|
7
|
-
|
|
7
|
+
import { useStatsigClient } from './useStatsigClient';
|
|
8
|
+
import { useStatsigOnDeviceEvalClient } from './useStatsigOnDeviceEvalClient';
|
|
9
|
+
import { useStatsigUser } from './useStatsigUser';
|
|
10
|
+
export type { StatsigProviderProps };
|
|
11
|
+
export { StatsigContext, StatsigProvider, useDynamicConfig, useExperiment, useGate, useLayer, useStatsigOnDeviceEvalClient, useStatsigClient, useStatsigUser, };
|
package/src/index.js
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
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.useGate = 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
|
-
|
|
12
|
+
const useGate_1 = require("./useGate");
|
|
24
13
|
exports.useGate = useGate_1.default;
|
|
25
|
-
|
|
14
|
+
const useLayer_1 = require("./useLayer");
|
|
26
15
|
exports.useLayer = useLayer_1.default;
|
|
27
|
-
|
|
16
|
+
const useStatsigClient_1 = require("./useStatsigClient");
|
|
17
|
+
Object.defineProperty(exports, "useStatsigClient", { enumerable: true, get: function () { return useStatsigClient_1.useStatsigClient; } });
|
|
18
|
+
const useStatsigOnDeviceEvalClient_1 = require("./useStatsigOnDeviceEvalClient");
|
|
19
|
+
Object.defineProperty(exports, "useStatsigOnDeviceEvalClient", { enumerable: true, get: function () { return useStatsigOnDeviceEvalClient_1.useStatsigOnDeviceEvalClient; } });
|
|
20
|
+
const useStatsigUser_1 = require("./useStatsigUser");
|
|
21
|
+
Object.defineProperty(exports, "useStatsigUser", { enumerable: true, get: function () { return useStatsigUser_1.useStatsigUser; } });
|
|
22
|
+
__STATSIG__ = Object.assign(Object.assign({}, (__STATSIG__ !== null && __STATSIG__ !== void 0 ? __STATSIG__ : {})), { StatsigContext: StatsigContext_1.default,
|
|
23
|
+
StatsigProvider: StatsigProvider_1.StatsigProvider,
|
|
24
|
+
useDynamicConfig: useDynamicConfig_1.default,
|
|
25
|
+
useExperiment: useExperiment_1.default,
|
|
26
|
+
useGate: useGate_1.default,
|
|
27
|
+
useLayer: useLayer_1.default,
|
|
28
|
+
useStatsigOnDeviceEvalClient: useStatsigOnDeviceEvalClient_1.useStatsigOnDeviceEvalClient,
|
|
29
|
+
useStatsigClient: useStatsigClient_1.useStatsigClient });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DynamicConfig,
|
|
2
|
-
export type UseDynamicConfigOptions =
|
|
1
|
+
import { DynamicConfig, DynamicConfigEvaluationOptions, StatsigUser } from '@statsig/client-core';
|
|
2
|
+
export type UseDynamicConfigOptions = DynamicConfigEvaluationOptions & {
|
|
3
3
|
user: StatsigUser | null;
|
|
4
4
|
};
|
|
5
5
|
export default function (configName: string, options?: UseDynamicConfigOptions): DynamicConfig;
|
package/src/useDynamicConfig.js
CHANGED
|
@@ -1,28 +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
|
-
|
|
16
|
-
|
|
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");
|
|
17
8
|
function default_1(configName, options) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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(configName, options);
|
|
13
|
+
}
|
|
14
|
+
if ((options === null || options === void 0 ? void 0 : options.user) != null) {
|
|
15
|
+
return client.getExperiment(configName, options.user, options);
|
|
23
16
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
client_core_1.Log.warn(`useDynamicConfig hook failed to find a valid Statsig client for dynamic config '${configName}'.`);
|
|
18
|
+
return NoopEvaluationsClient_1.NoopEvaluationsClient.getExperiment(configName, options);
|
|
19
|
+
}, [configName, renderVersion, options]);
|
|
27
20
|
}
|
|
28
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,21 +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
|
-
|
|
19
|
-
|
|
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(`useGate hook failed to find a valid Statsig client for experiment '${experimentName}'.`);
|
|
18
|
+
return NoopEvaluationsClient_1.NoopEvaluationsClient.getExperiment(experimentName, options);
|
|
19
|
+
}, [experimentName, renderVersion, options]);
|
|
20
20
|
}
|
|
21
21
|
exports.default = default_1;
|
package/src/useGate.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type UseGateOptions =
|
|
1
|
+
import { FeatureGate, FeatureGateEvaluationOptions, StatsigUser } from '@statsig/client-core';
|
|
2
|
+
export type UseGateOptions = FeatureGateEvaluationOptions & {
|
|
3
3
|
user: StatsigUser | null;
|
|
4
4
|
};
|
|
5
5
|
export default function (gateName: string, options?: UseGateOptions): FeatureGate;
|
package/src/useGate.js
CHANGED
|
@@ -1,28 +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
|
-
|
|
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");
|
|
17
8
|
function default_1(gateName, options) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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);
|
|
23
16
|
}
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
client_core_1.Log.warn(`useGate hook failed to find a valid Statsig client for gate '${gateName}'.`);
|
|
18
|
+
return NoopEvaluationsClient_1.NoopEvaluationsClient.getFeatureGate(gateName, options);
|
|
19
|
+
}, [gateName, renderVersion, options]);
|
|
26
20
|
return gate;
|
|
27
21
|
}
|
|
28
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,28 +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
|
-
|
|
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");
|
|
17
8
|
function default_1(layerName, options) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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)) {
|
|
12
|
+
return client.getLayer(layerName, options);
|
|
13
|
+
}
|
|
14
|
+
if ((options === null || options === void 0 ? void 0 : options.user) != null) {
|
|
15
|
+
return client.getLayer(layerName, options.user, options);
|
|
23
16
|
}
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
client_core_1.Log.warn(`useLayer hook failed to find a valid Statsig client for layer '${layerName}'.`);
|
|
18
|
+
return NoopEvaluationsClient_1.NoopEvaluationsClient.getLayer(layerName, options);
|
|
19
|
+
}, [layerName, renderVersion, options]);
|
|
26
20
|
return layer;
|
|
27
21
|
}
|
|
28
22
|
exports.default = default_1;
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
precomputedClient: PrecomputedEvaluationsInterface;
|
|
4
|
-
onDeviceClient: OnDeviceEvaluationsInterface;
|
|
5
|
-
};
|
|
1
|
+
import { PrecomputedEvaluationsInterface } from '@statsig/client-core';
|
|
2
|
+
export declare function useStatsigClient(): PrecomputedEvaluationsInterface;
|
package/src/useStatsigClient.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 } = (0, react_1.useContext)(StatsigContext_1.default);
|
|
11
|
+
if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvalClient)(client)) {
|
|
12
|
+
return client;
|
|
13
|
+
}
|
|
14
|
+
client_core_1.Log.warn('Attempting to retrive a Statsig StatsigClient but none was set.');
|
|
15
|
+
return NoopEvaluationsClient_1.NoopEvaluationsClient;
|
|
7
16
|
}
|
|
8
|
-
exports.
|
|
17
|
+
exports.useStatsigClient = useStatsigClient;
|
|
@@ -0,0 +1,17 @@
|
|
|
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 } = (0, react_1.useContext)(StatsigContext_1.default);
|
|
11
|
+
if (!(0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvalClient)(client)) {
|
|
12
|
+
return client;
|
|
13
|
+
}
|
|
14
|
+
client_core_1.Log.warn('Attempting to retrive a Statsig StatsigOnDeviceEvalClient but none was set.');
|
|
15
|
+
return NoopEvaluationsClient_1.NoopEvaluationsClient;
|
|
16
|
+
}
|
|
17
|
+
exports.useStatsigOnDeviceEvalClient = useStatsigOnDeviceEvalClient;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { StatsigUser } from '@statsig/client-core';
|
|
2
|
+
export type UseStatsigUserResult = {
|
|
3
|
+
user: StatsigUser;
|
|
4
|
+
updateUserSync: (fn: (prevState: StatsigUser) => StatsigUser) => void;
|
|
5
|
+
updateUserAsync: (fn: (prevState: StatsigUser) => StatsigUser) => Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare function useStatsigUser(): UseStatsigUserResult;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useStatsigUser = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const useStatsigClient_1 = require("./useStatsigClient");
|
|
6
|
+
function useStatsigUser() {
|
|
7
|
+
const client = (0, useStatsigClient_1.useStatsigClient)();
|
|
8
|
+
const memoUser = (0, react_1.useMemo)(() => {
|
|
9
|
+
return client.getCurrentUser();
|
|
10
|
+
}, [client, client.getCurrentUser()]);
|
|
11
|
+
return {
|
|
12
|
+
user: memoUser,
|
|
13
|
+
updateUserSync: (fn) => {
|
|
14
|
+
const user = fn(memoUser);
|
|
15
|
+
client.updateUserSync(user);
|
|
16
|
+
},
|
|
17
|
+
updateUserAsync: (fn) => {
|
|
18
|
+
const user = fn(memoUser);
|
|
19
|
+
return client.updateUserAsync(user);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.useStatsigUser = useStatsigUser;
|