@statsig/react-bindings 0.0.1-beta.1 → 0.0.1-beta.10
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 +15 -5
- package/src/OnDeviceVsPrecomputedUtils.d.ts +3 -1
- package/src/OnDeviceVsPrecomputedUtils.js +4 -1
- package/src/StatsigContext.d.ts +2 -3
- package/src/StatsigContext.js +1 -2
- package/src/StatsigProvider.d.ts +5 -10
- package/src/StatsigProvider.js +12 -38
- package/src/index.d.ts +6 -2
- package/src/index.js +9 -3
- package/src/useConfigImpl.d.ts +5 -0
- package/src/useConfigImpl.js +36 -0
- package/src/useDynamicConfig.d.ts +3 -4
- package/src/useDynamicConfig.js +2 -10
- package/src/useExperiment.d.ts +2 -2
- package/src/useExperiment.js +2 -3
- package/src/useGate.js +11 -5
- package/src/useLayer.js +11 -5
- package/src/useStatsigOnDeviceEvaluationsClient.d.ts +2 -0
- package/src/useStatsigOnDeviceEvaluationsClient.js +16 -0
- package/src/useStatsigPrecomputedEvaluationsClient.d.ts +2 -0
- package/src/useStatsigPrecomputedEvaluationsClient.js +16 -0
- package/src/useStatsigUser.d.ts +7 -0
- package/src/useStatsigUser.js +18 -0
- package/src/useStatsigClient.d.ts +0 -5
- package/src/useStatsigClient.js +0 -8
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ var client_core_1 = require("@statsig/client-core");
|
|
|
5
5
|
var noop = function () {
|
|
6
6
|
// noop
|
|
7
7
|
};
|
|
8
|
+
var NOOP_DETAILS = { reason: 'Error' };
|
|
8
9
|
var defaultEvaluation = function (type) {
|
|
9
10
|
return function () {
|
|
10
11
|
var args = [];
|
|
@@ -14,20 +15,28 @@ var defaultEvaluation = function (type) {
|
|
|
14
15
|
var name = typeof args[0] === 'string' ? args[0] : args[1];
|
|
15
16
|
switch (type) {
|
|
16
17
|
case 'gate':
|
|
17
|
-
return (0, client_core_1.makeFeatureGate)(name,
|
|
18
|
+
return (0, client_core_1.makeFeatureGate)(name, NOOP_DETAILS);
|
|
18
19
|
case 'config':
|
|
19
|
-
return (0, client_core_1.makeDynamicConfig)(name,
|
|
20
|
+
return (0, client_core_1.makeDynamicConfig)(name, NOOP_DETAILS);
|
|
20
21
|
case 'layer':
|
|
21
|
-
return (0, client_core_1.makeLayer)(name,
|
|
22
|
+
return (0, client_core_1.makeLayer)(name, NOOP_DETAILS);
|
|
22
23
|
}
|
|
23
24
|
};
|
|
24
25
|
};
|
|
26
|
+
var noopDataAdapter = {
|
|
27
|
+
_setInMemoryCache: noop,
|
|
28
|
+
attach: noop,
|
|
29
|
+
getDataSync: function () { return null; },
|
|
30
|
+
getDataAsync: function () { return Promise.resolve(null); },
|
|
31
|
+
};
|
|
25
32
|
var client = {
|
|
26
33
|
isNoop: true,
|
|
27
34
|
loadingStatus: 'Uninitialized',
|
|
28
|
-
|
|
35
|
+
initializeSync: noop,
|
|
36
|
+
initializeAsync: function () { return Promise.resolve(); },
|
|
29
37
|
shutdown: function () { return Promise.resolve(); },
|
|
30
|
-
|
|
38
|
+
updateUserSync: noop,
|
|
39
|
+
updateUserAsync: function (_u) { return Promise.resolve(); },
|
|
31
40
|
getCurrentUser: function () { return ({ userID: '' }); },
|
|
32
41
|
checkGate: function () { return false; },
|
|
33
42
|
getFeatureGate: defaultEvaluation('gate'),
|
|
@@ -37,5 +46,6 @@ var client = {
|
|
|
37
46
|
logEvent: noop,
|
|
38
47
|
on: noop,
|
|
39
48
|
off: noop,
|
|
49
|
+
getDataAdapter: function () { return noopDataAdapter; },
|
|
40
50
|
};
|
|
41
51
|
exports.NoopEvaluationsClient = client;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { OnDeviceEvaluationsInterface, PrecomputedEvaluationsInterface } from '@statsig/client-core';
|
|
2
|
-
export declare function isPrecomputedEvaluationsClient(client: OnDeviceEvaluationsInterface | PrecomputedEvaluationsInterface
|
|
2
|
+
export declare function isPrecomputedEvaluationsClient(client: OnDeviceEvaluationsInterface | PrecomputedEvaluationsInterface | {
|
|
3
|
+
isNoop: true;
|
|
4
|
+
}): client is PrecomputedEvaluationsInterface;
|
|
3
5
|
export declare function logMissingStatsigUserWarning(): void;
|
|
@@ -3,7 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.logMissingStatsigUserWarning = exports.isPrecomputedEvaluationsClient = void 0;
|
|
4
4
|
var client_core_1 = require("@statsig/client-core");
|
|
5
5
|
function isPrecomputedEvaluationsClient(client) {
|
|
6
|
-
|
|
6
|
+
if ('isNoop' in client) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
return 'updateUserSync' in client;
|
|
7
10
|
}
|
|
8
11
|
exports.isPrecomputedEvaluationsClient = isPrecomputedEvaluationsClient;
|
|
9
12
|
function logMissingStatsigUserWarning() {
|
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
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(props: StatsigProviderProps): JSX.Element;
|
package/src/StatsigProvider.js
CHANGED
|
@@ -1,55 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StatsigProvider = void 0;
|
|
3
4
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
5
|
var react_1 = require("react");
|
|
5
6
|
var client_core_1 = require("@statsig/client-core");
|
|
6
|
-
var NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
|
|
7
|
-
var OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
|
|
8
7
|
var StatsigContext_1 = require("./StatsigContext");
|
|
9
8
|
function StatsigProvider(props) {
|
|
10
|
-
var precomputedClient;
|
|
11
|
-
var onDeviceClient;
|
|
12
|
-
if ('client' in props) {
|
|
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
9
|
var _a = (0, react_1.useState)(0), renderVersion = _a[0], setRenderVersion = _a[1];
|
|
25
|
-
var
|
|
10
|
+
var client = props.client, children = props.children;
|
|
26
11
|
(0, react_1.useEffect)(function () {
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
setRenderVersion(function (v) { return v + 1; });
|
|
30
|
-
}
|
|
12
|
+
var onValuesUpdated = function () {
|
|
13
|
+
setRenderVersion(function (v) { return v + 1; });
|
|
31
14
|
};
|
|
32
|
-
|
|
33
|
-
client.on('status_change', onStatusChange);
|
|
34
|
-
client.initialize().catch(function (error) {
|
|
35
|
-
client_core_1.Log.error('An error occurred during initialization', error);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
15
|
+
client.on('values_updated', onValuesUpdated);
|
|
38
16
|
return function () {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
client_core_1.Log.error('An error occured during shutdown', error);
|
|
42
|
-
});
|
|
43
|
-
client.off('status_change', onStatusChange);
|
|
17
|
+
client.shutdown().catch(function (error) {
|
|
18
|
+
client_core_1.Log.error('An error occured during shutdown', error);
|
|
44
19
|
});
|
|
20
|
+
client.off('values_updated', onValuesUpdated);
|
|
45
21
|
};
|
|
46
|
-
},
|
|
47
|
-
return ((0, jsx_runtime_1.jsx)(StatsigContext_1.default.Provider, { value: { renderVersion: renderVersion,
|
|
48
|
-
? props.children
|
|
49
|
-
: null }));
|
|
22
|
+
}, [client]);
|
|
23
|
+
return ((0, jsx_runtime_1.jsx)(StatsigContext_1.default.Provider, { value: { renderVersion: renderVersion, client: client }, children: _shouldRender(client) ? children : null }));
|
|
50
24
|
}
|
|
51
|
-
exports.
|
|
52
|
-
function
|
|
25
|
+
exports.StatsigProvider = StatsigProvider;
|
|
26
|
+
function _shouldRender(client) {
|
|
53
27
|
if ('isNoop' in client) {
|
|
54
28
|
return true;
|
|
55
29
|
}
|
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 useStatsigOnDeviceEvaluationsClient from './useStatsigOnDeviceEvaluationsClient';
|
|
8
|
+
import useStatsigPrecomputedEvaluationsClient from './useStatsigPrecomputedEvaluationsClient';
|
|
9
|
+
import useStatsigUser from './useStatsigUser';
|
|
10
|
+
export type { StatsigProviderProps };
|
|
11
|
+
export { StatsigContext, StatsigProvider, useGate, useDynamicConfig, useExperiment, useLayer, useStatsigUser, useStatsigOnDeviceEvaluationsClient, useStatsigPrecomputedEvaluationsClient, };
|
package/src/index.js
CHANGED
|
@@ -11,11 +11,11 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.useLayer = exports.useExperiment = exports.useDynamicConfig = exports.useGate = exports.StatsigProvider = exports.StatsigContext = void 0;
|
|
14
|
+
exports.useStatsigPrecomputedEvaluationsClient = exports.useStatsigOnDeviceEvaluationsClient = exports.useStatsigUser = exports.useLayer = exports.useExperiment = exports.useDynamicConfig = exports.useGate = exports.StatsigProvider = exports.StatsigContext = void 0;
|
|
15
15
|
var StatsigContext_1 = require("./StatsigContext");
|
|
16
16
|
exports.StatsigContext = StatsigContext_1.default;
|
|
17
17
|
var StatsigProvider_1 = require("./StatsigProvider");
|
|
18
|
-
exports
|
|
18
|
+
Object.defineProperty(exports, "StatsigProvider", { enumerable: true, get: function () { return StatsigProvider_1.StatsigProvider; } });
|
|
19
19
|
var useDynamicConfig_1 = require("./useDynamicConfig");
|
|
20
20
|
exports.useDynamicConfig = useDynamicConfig_1.default;
|
|
21
21
|
var useExperiment_1 = require("./useExperiment");
|
|
@@ -24,4 +24,10 @@ var useGate_1 = require("./useGate");
|
|
|
24
24
|
exports.useGate = useGate_1.default;
|
|
25
25
|
var useLayer_1 = require("./useLayer");
|
|
26
26
|
exports.useLayer = useLayer_1.default;
|
|
27
|
-
|
|
27
|
+
var useStatsigOnDeviceEvaluationsClient_1 = require("./useStatsigOnDeviceEvaluationsClient");
|
|
28
|
+
exports.useStatsigOnDeviceEvaluationsClient = useStatsigOnDeviceEvaluationsClient_1.default;
|
|
29
|
+
var useStatsigPrecomputedEvaluationsClient_1 = require("./useStatsigPrecomputedEvaluationsClient");
|
|
30
|
+
exports.useStatsigPrecomputedEvaluationsClient = useStatsigPrecomputedEvaluationsClient_1.default;
|
|
31
|
+
var useStatsigUser_1 = require("./useStatsigUser");
|
|
32
|
+
exports.useStatsigUser = useStatsigUser_1.default;
|
|
33
|
+
__STATSIG__ = __assign(__assign({}, __STATSIG__), { StatsigContext: StatsigContext_1.default, StatsigProvider: StatsigProvider_1.StatsigProvider, useGate: useGate_1.default, useDynamicConfig: useDynamicConfig_1.default, useExperiment: useExperiment_1.default, useLayer: useLayer_1.default, useStatsigOnDeviceEvaluationsClient: useStatsigOnDeviceEvaluationsClient_1.default, useStatsigPrecomputedEvaluationsClient: useStatsigPrecomputedEvaluationsClient_1.default });
|
|
@@ -0,0 +1,5 @@
|
|
|
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;
|
|
@@ -0,0 +1,36 @@
|
|
|
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;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { DynamicConfig
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
1
|
+
import { DynamicConfig } from '@statsig/client-core';
|
|
2
|
+
import { UseConfigOptions } from './useConfigImpl';
|
|
3
|
+
export type UseDynamicConfigOptions = UseConfigOptions;
|
|
5
4
|
export default function (configName: string, options?: UseDynamicConfigOptions): DynamicConfig;
|
package/src/useDynamicConfig.js
CHANGED
|
@@ -11,18 +11,10 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
var react_1 = require("react");
|
|
15
14
|
var client_core_1 = require("@statsig/client-core");
|
|
16
|
-
var
|
|
15
|
+
var useConfigImpl_1 = require("./useConfigImpl");
|
|
17
16
|
function default_1(configName, options) {
|
|
18
17
|
if (options === void 0) { options = __assign(__assign({}, client_core_1.DEFAULT_EVAL_OPTIONS), { user: null }); }
|
|
19
|
-
|
|
20
|
-
var config = (0, react_1.useMemo)(function () {
|
|
21
|
-
if (options.user == null) {
|
|
22
|
-
return precomputedClient.getDynamicConfig(configName, options);
|
|
23
|
-
}
|
|
24
|
-
return onDeviceClient.getDynamicConfig(configName, options.user, options);
|
|
25
|
-
}, [precomputedClient.loadingStatus, onDeviceClient.loadingStatus, options]);
|
|
26
|
-
return config;
|
|
18
|
+
return (0, useConfigImpl_1.useConfigImpl)('useDynamicConfig', configName, options);
|
|
27
19
|
}
|
|
28
20
|
exports.default = default_1;
|
package/src/useExperiment.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Experiment } from '@statsig/client-core';
|
|
2
|
-
import {
|
|
3
|
-
export type UseExperimentOptions =
|
|
2
|
+
import { UseConfigOptions } from './useConfigImpl';
|
|
3
|
+
export type UseExperimentOptions = UseConfigOptions;
|
|
4
4
|
export default function (experimentName: string, options?: UseExperimentOptions): Experiment;
|
package/src/useExperiment.js
CHANGED
|
@@ -12,10 +12,9 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
var client_core_1 = require("@statsig/client-core");
|
|
15
|
-
var
|
|
15
|
+
var useConfigImpl_1 = require("./useConfigImpl");
|
|
16
16
|
function default_1(experimentName, options) {
|
|
17
17
|
if (options === void 0) { options = __assign(__assign({}, client_core_1.DEFAULT_EVAL_OPTIONS), { user: null }); }
|
|
18
|
-
|
|
19
|
-
return config;
|
|
18
|
+
return (0, useConfigImpl_1.useConfigImpl)('useExperiment', experimentName, options);
|
|
20
19
|
}
|
|
21
20
|
exports.default = default_1;
|
package/src/useGate.js
CHANGED
|
@@ -13,16 +13,22 @@ var __assign = (this && this.__assign) || function () {
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
var react_1 = require("react");
|
|
15
15
|
var client_core_1 = require("@statsig/client-core");
|
|
16
|
+
var NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
|
|
17
|
+
var OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
|
|
16
18
|
var StatsigContext_1 = require("./StatsigContext");
|
|
17
19
|
function default_1(gateName, options) {
|
|
18
20
|
if (options === void 0) { options = __assign(__assign({}, client_core_1.DEFAULT_EVAL_OPTIONS), { user: null }); }
|
|
19
|
-
var
|
|
21
|
+
var client = (0, react_1.useContext)(StatsigContext_1.default).client;
|
|
20
22
|
var gate = (0, react_1.useMemo)(function () {
|
|
21
|
-
if (
|
|
22
|
-
return
|
|
23
|
+
if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvaluationsClient)(client)) {
|
|
24
|
+
return client.getFeatureGate(gateName, options);
|
|
23
25
|
}
|
|
24
|
-
|
|
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]);
|
|
26
32
|
return gate;
|
|
27
33
|
}
|
|
28
34
|
exports.default = default_1;
|
package/src/useLayer.js
CHANGED
|
@@ -13,16 +13,22 @@ var __assign = (this && this.__assign) || function () {
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
var react_1 = require("react");
|
|
15
15
|
var client_core_1 = require("@statsig/client-core");
|
|
16
|
+
var NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
|
|
17
|
+
var OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
|
|
16
18
|
var StatsigContext_1 = require("./StatsigContext");
|
|
17
19
|
function default_1(layerName, options) {
|
|
18
20
|
if (options === void 0) { options = __assign(__assign({}, client_core_1.DEFAULT_EVAL_OPTIONS), { user: null }); }
|
|
19
|
-
var
|
|
21
|
+
var client = (0, react_1.useContext)(StatsigContext_1.default).client;
|
|
20
22
|
var layer = (0, react_1.useMemo)(function () {
|
|
21
|
-
if (
|
|
22
|
-
return
|
|
23
|
+
if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvaluationsClient)(client)) {
|
|
24
|
+
return client.getLayer(layerName, options);
|
|
23
25
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
if (options.user != null) {
|
|
27
|
+
return client.getLayer(layerName, options.user, options);
|
|
28
|
+
}
|
|
29
|
+
client_core_1.Log.warn("useLayer hook failed to find a valid Statsig client for layer '".concat(layerName, "'."));
|
|
30
|
+
return NoopEvaluationsClient_1.NoopEvaluationsClient.getLayer(layerName, options);
|
|
31
|
+
}, [client.loadingStatus, options]);
|
|
26
32
|
return layer;
|
|
27
33
|
}
|
|
28
34
|
exports.default = default_1;
|
|
@@ -0,0 +1,16 @@
|
|
|
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;
|
|
@@ -0,0 +1,16 @@
|
|
|
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;
|
|
@@ -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 default function (): UseStatsigUserResult;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var useStatsigPrecomputedEvaluationsClient_1 = require("./useStatsigPrecomputedEvaluationsClient");
|
|
4
|
+
function default_1() {
|
|
5
|
+
var client = (0, useStatsigPrecomputedEvaluationsClient_1.default)();
|
|
6
|
+
return {
|
|
7
|
+
user: client.getCurrentUser(),
|
|
8
|
+
updateUserSync: function (fn) {
|
|
9
|
+
var user = fn(client.getCurrentUser());
|
|
10
|
+
client.updateUserSync(user);
|
|
11
|
+
},
|
|
12
|
+
updateUserAsync: function (fn) {
|
|
13
|
+
var user = fn(client.getCurrentUser());
|
|
14
|
+
return client.updateUserAsync(user);
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
exports.default = default_1;
|
package/src/useStatsigClient.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var react_1 = require("react");
|
|
4
|
-
var StatsigContext_1 = require("./StatsigContext");
|
|
5
|
-
function default_1() {
|
|
6
|
-
return (0, react_1.useContext)(StatsigContext_1.default);
|
|
7
|
-
}
|
|
8
|
-
exports.default = default_1;
|