@statsig/react-bindings 0.0.1-beta.10 → 0.0.1-beta.12

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 CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@statsig/react-bindings",
3
- "version": "0.0.1-beta.10",
3
+ "version": "0.0.1-beta.12",
4
4
  "dependencies": {
5
- "@statsig/client-core": "0.0.1-beta.10"
5
+ "@statsig/client-core": "0.0.1-beta.12"
6
6
  },
7
7
  "peerDependencies": {
8
8
  "react": "^16.6.3 || ^17.0.0 || ^18.0.0"
@@ -1,51 +1,51 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NoopEvaluationsClient = void 0;
4
- var client_core_1 = require("@statsig/client-core");
5
- var noop = function () {
4
+ const client_core_1 = require("@statsig/client-core");
5
+ const _noop = () => {
6
6
  // noop
7
7
  };
8
- var NOOP_DETAILS = { reason: 'Error' };
9
- var defaultEvaluation = function (type) {
10
- return function () {
11
- var args = [];
12
- for (var _i = 0; _i < arguments.length; _i++) {
13
- args[_i] = arguments[_i];
14
- }
15
- 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];
16
13
  switch (type) {
17
14
  case 'gate':
18
- return (0, client_core_1.makeFeatureGate)(name, NOOP_DETAILS);
15
+ return (0, client_core_1.makeFeatureGate)(name, NOOP_DETAILS, null);
19
16
  case 'config':
20
- return (0, client_core_1.makeDynamicConfig)(name, NOOP_DETAILS);
17
+ return (0, client_core_1.makeDynamicConfig)(name, NOOP_DETAILS, null);
21
18
  case 'layer':
22
- return (0, client_core_1.makeLayer)(name, NOOP_DETAILS);
19
+ return (0, client_core_1.makeLayer)(name, NOOP_DETAILS, null);
23
20
  }
24
21
  };
25
22
  };
26
- var noopDataAdapter = {
27
- _setInMemoryCache: noop,
28
- attach: noop,
29
- getDataSync: function () { return null; },
30
- getDataAsync: function () { return Promise.resolve(null); },
23
+ const _noopDataAdapter = {
24
+ __setInMemoryCache: _noop,
25
+ attach: _noop,
26
+ getDataSync: () => null,
27
+ getDataAsync: () => Promise.resolve(null),
28
+ setData: _noop,
29
+ prefetchData: _noopAsync,
31
30
  };
32
- var client = {
31
+ const _client = {
33
32
  isNoop: true,
34
33
  loadingStatus: 'Uninitialized',
35
- initializeSync: noop,
36
- initializeAsync: function () { return Promise.resolve(); },
37
- shutdown: function () { return Promise.resolve(); },
38
- updateUserSync: noop,
39
- updateUserAsync: function (_u) { return Promise.resolve(); },
40
- getCurrentUser: function () { return ({ userID: '' }); },
41
- checkGate: function () { return 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
- getDataAdapter: function () { return noopDataAdapter; },
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,
50
50
  };
51
- exports.NoopEvaluationsClient = client;
51
+ exports.NoopEvaluationsClient = _client;
@@ -1,5 +1,4 @@
1
1
  import { OnDeviceEvaluationsInterface, PrecomputedEvaluationsInterface } from '@statsig/client-core';
2
- export declare function isPrecomputedEvaluationsClient(client: OnDeviceEvaluationsInterface | PrecomputedEvaluationsInterface | {
3
- isNoop: true;
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.isPrecomputedEvaluationsClient = void 0;
4
- var client_core_1 = require("@statsig/client-core");
5
- function isPrecomputedEvaluationsClient(client) {
6
- if ('isNoop' in client) {
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.isPrecomputedEvaluationsClient = isPrecomputedEvaluationsClient;
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
  }
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var react_1 = require("react");
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
  });
@@ -4,4 +4,4 @@ export type StatsigProviderProps = {
4
4
  children: ReactNode | ReactNode[];
5
5
  client: StatsigClientInterface;
6
6
  };
7
- export declare function StatsigProvider(props: StatsigProviderProps): JSX.Element;
7
+ export declare function StatsigProvider({ client, children, }: StatsigProviderProps): JSX.Element;
@@ -1,26 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StatsigProvider = void 0;
4
- var jsx_runtime_1 = require("react/jsx-runtime");
5
- var react_1 = require("react");
6
- var client_core_1 = require("@statsig/client-core");
7
- var StatsigContext_1 = require("./StatsigContext");
8
- function StatsigProvider(props) {
9
- var _a = (0, react_1.useState)(0), renderVersion = _a[0], setRenderVersion = _a[1];
10
- var client = props.client, children = props.children;
11
- (0, react_1.useEffect)(function () {
12
- var onValuesUpdated = function () {
13
- setRenderVersion(function (v) { return v + 1; });
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);
14
13
  };
15
14
  client.on('values_updated', onValuesUpdated);
16
- return function () {
17
- client.shutdown().catch(function (error) {
15
+ return () => {
16
+ client.shutdown().catch((error) => {
18
17
  client_core_1.Log.error('An error occured during shutdown', error);
19
18
  });
20
19
  client.off('values_updated', onValuesUpdated);
21
20
  };
22
21
  }, [client]);
23
- return ((0, jsx_runtime_1.jsx)(StatsigContext_1.default.Provider, { value: { renderVersion: renderVersion, client: client }, children: _shouldRender(client) ? children : null }));
22
+ return ((0, jsx_runtime_1.jsx)(StatsigContext_1.default.Provider, { value: { renderVersion, client }, children: _shouldRender(client) ? children : null }));
24
23
  }
25
24
  exports.StatsigProvider = StatsigProvider;
26
25
  function _shouldRender(client) {
package/src/index.d.ts CHANGED
@@ -4,8 +4,8 @@ import useDynamicConfig from './useDynamicConfig';
4
4
  import useExperiment from './useExperiment';
5
5
  import useGate from './useGate';
6
6
  import useLayer from './useLayer';
7
- import useStatsigOnDeviceEvaluationsClient from './useStatsigOnDeviceEvaluationsClient';
8
- import useStatsigPrecomputedEvaluationsClient from './useStatsigPrecomputedEvaluationsClient';
9
- import useStatsigUser from './useStatsigUser';
7
+ import { useStatsigClient } from './useStatsigClient';
8
+ import { useStatsigOnDeviceEvalClient } from './useStatsigOnDeviceEvalClient';
9
+ import { useStatsigUser } from './useStatsigUser';
10
10
  export type { StatsigProviderProps };
11
- export { StatsigContext, StatsigProvider, useGate, useDynamicConfig, useExperiment, useLayer, useStatsigUser, useStatsigOnDeviceEvaluationsClient, useStatsigPrecomputedEvaluationsClient, };
11
+ export { StatsigContext, StatsigProvider, useDynamicConfig, useExperiment, useGate, useLayer, useStatsigOnDeviceEvalClient, useStatsigClient, useStatsigUser, };
package/src/index.js CHANGED
@@ -1,33 +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.useStatsigPrecomputedEvaluationsClient = exports.useStatsigOnDeviceEvaluationsClient = exports.useStatsigUser = exports.useLayer = exports.useExperiment = exports.useDynamicConfig = exports.useGate = exports.StatsigProvider = exports.StatsigContext = void 0;
15
- var StatsigContext_1 = require("./StatsigContext");
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
- var StatsigProvider_1 = require("./StatsigProvider");
6
+ const StatsigProvider_1 = require("./StatsigProvider");
18
7
  Object.defineProperty(exports, "StatsigProvider", { enumerable: true, get: function () { return StatsigProvider_1.StatsigProvider; } });
19
- var useDynamicConfig_1 = require("./useDynamicConfig");
8
+ const useDynamicConfig_1 = require("./useDynamicConfig");
20
9
  exports.useDynamicConfig = useDynamicConfig_1.default;
21
- var useExperiment_1 = require("./useExperiment");
10
+ const useExperiment_1 = require("./useExperiment");
22
11
  exports.useExperiment = useExperiment_1.default;
23
- var useGate_1 = require("./useGate");
12
+ const useGate_1 = require("./useGate");
24
13
  exports.useGate = useGate_1.default;
25
- var useLayer_1 = require("./useLayer");
14
+ const useLayer_1 = require("./useLayer");
26
15
  exports.useLayer = useLayer_1.default;
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 });
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,36 +1,24 @@
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
3
  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)) {
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 useConfigImpl(hook, configName, options = Object.assign(Object.assign({}, client_core_1.DEFAULT_EVAL_OPTIONS), { user: null })) {
10
+ const { client, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
11
+ const config = (0, react_1.useMemo)(() => {
12
+ if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvalClient)(client)) {
25
13
  return client.getDynamicConfig(configName, options);
26
14
  }
27
15
  if (options.user != null) {
28
16
  return client.getDynamicConfig(configName, options.user, options);
29
17
  }
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, "'."));
18
+ const type = hook === 'useDynamicConfig' ? 'dynamic config' : 'experiment';
19
+ client_core_1.Log.warn(`${hook} hook failed to find a valid Statsig client for ${type} '${configName}'.`);
32
20
  return NoopEvaluationsClient_1.NoopEvaluationsClient.getDynamicConfig(configName, options);
33
- }, [client.loadingStatus, options]);
21
+ }, [configName, renderVersion, options]);
34
22
  return config;
35
23
  }
36
24
  exports.useConfigImpl = useConfigImpl;
@@ -1,20 +1,8 @@
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
- var client_core_1 = require("@statsig/client-core");
15
- var useConfigImpl_1 = require("./useConfigImpl");
16
- function default_1(configName, options) {
17
- if (options === void 0) { options = __assign(__assign({}, client_core_1.DEFAULT_EVAL_OPTIONS), { user: null }); }
3
+ const client_core_1 = require("@statsig/client-core");
4
+ const useConfigImpl_1 = require("./useConfigImpl");
5
+ function default_1(configName, options = Object.assign(Object.assign({}, client_core_1.DEFAULT_EVAL_OPTIONS), { user: null })) {
18
6
  return (0, useConfigImpl_1.useConfigImpl)('useDynamicConfig', configName, options);
19
7
  }
20
8
  exports.default = default_1;
@@ -1,20 +1,8 @@
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
- var client_core_1 = require("@statsig/client-core");
15
- var useConfigImpl_1 = require("./useConfigImpl");
16
- function default_1(experimentName, options) {
17
- if (options === void 0) { options = __assign(__assign({}, client_core_1.DEFAULT_EVAL_OPTIONS), { user: null }); }
3
+ const client_core_1 = require("@statsig/client-core");
4
+ const useConfigImpl_1 = require("./useConfigImpl");
5
+ function default_1(experimentName, options = Object.assign(Object.assign({}, client_core_1.DEFAULT_EVAL_OPTIONS), { user: null })) {
18
6
  return (0, useConfigImpl_1.useConfigImpl)('useExperiment', experimentName, options);
19
7
  }
20
8
  exports.default = default_1;
package/src/useGate.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
- 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)) {
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 = Object.assign(Object.assign({}, client_core_1.DEFAULT_EVAL_OPTIONS), { user: null })) {
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)) {
24
12
  return client.getFeatureGate(gateName, options);
25
13
  }
26
14
  if (options.user != null) {
27
15
  return client.getFeatureGate(gateName, options.user, options);
28
16
  }
29
- client_core_1.Log.warn("useGate hook failed to find a valid Statsig client for gate '".concat(gateName, "'."));
17
+ client_core_1.Log.warn(`useGate hook failed to find a valid Statsig client for gate '${gateName}'.`);
30
18
  return NoopEvaluationsClient_1.NoopEvaluationsClient.getFeatureGate(gateName, options);
31
- }, [client.loadingStatus, options]);
19
+ }, [gateName, renderVersion, options]);
32
20
  return gate;
33
21
  }
34
22
  exports.default = default_1;
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
- 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(layerName, 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 layer = (0, react_1.useMemo)(function () {
23
- if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvaluationsClient)(client)) {
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(layerName, options = Object.assign(Object.assign({}, client_core_1.DEFAULT_EVAL_OPTIONS), { user: null })) {
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
14
  if (options.user != null) {
27
15
  return client.getLayer(layerName, options.user, options);
28
16
  }
29
- client_core_1.Log.warn("useLayer hook failed to find a valid Statsig client for layer '".concat(layerName, "'."));
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.loadingStatus, options]);
19
+ }, [layerName, renderVersion, options]);
32
20
  return layer;
33
21
  }
34
22
  exports.default = default_1;
@@ -0,0 +1,2 @@
1
+ import { PrecomputedEvaluationsInterface } from '@statsig/client-core';
2
+ export declare function useStatsigClient(): PrecomputedEvaluationsInterface;
@@ -0,0 +1,17 @@
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 } = (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;
16
+ }
17
+ exports.useStatsigClient = useStatsigClient;
@@ -0,0 +1,2 @@
1
+ import { OnDeviceEvaluationsInterface } from '@statsig/client-core';
2
+ export declare function useStatsigOnDeviceEvalClient(): OnDeviceEvaluationsInterface;
@@ -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;
@@ -4,4 +4,4 @@ export type UseStatsigUserResult = {
4
4
  updateUserSync: (fn: (prevState: StatsigUser) => StatsigUser) => void;
5
5
  updateUserAsync: (fn: (prevState: StatsigUser) => StatsigUser) => Promise<void>;
6
6
  };
7
- export default function (): UseStatsigUserResult;
7
+ export declare function useStatsigUser(): UseStatsigUserResult;
@@ -1,18 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var useStatsigPrecomputedEvaluationsClient_1 = require("./useStatsigPrecomputedEvaluationsClient");
4
- function default_1() {
5
- var client = (0, useStatsigPrecomputedEvaluationsClient_1.default)();
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()]);
6
11
  return {
7
- user: client.getCurrentUser(),
8
- updateUserSync: function (fn) {
9
- var user = fn(client.getCurrentUser());
12
+ user: memoUser,
13
+ updateUserSync: (fn) => {
14
+ const user = fn(memoUser);
10
15
  client.updateUserSync(user);
11
16
  },
12
- updateUserAsync: function (fn) {
13
- var user = fn(client.getCurrentUser());
17
+ updateUserAsync: (fn) => {
18
+ const user = fn(memoUser);
14
19
  return client.updateUserAsync(user);
15
20
  },
16
21
  };
17
22
  }
18
- exports.default = default_1;
23
+ exports.useStatsigUser = useStatsigUser;
@@ -1,2 +0,0 @@
1
- import { OnDeviceEvaluationsInterface } from '@statsig/client-core';
2
- export default function (): OnDeviceEvaluationsInterface;
@@ -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,2 +0,0 @@
1
- import { PrecomputedEvaluationsInterface } from '@statsig/client-core';
2
- export default function (): PrecomputedEvaluationsInterface;
@@ -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;