@statsig/react-bindings 1.6.0 → 1.8.0-beta.1

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": "1.6.0",
3
+ "version": "1.8.0-beta.1",
4
4
  "dependencies": {
5
- "@statsig/client-core": "1.6.0"
5
+ "@statsig/client-core": "1.8.0-beta.1"
6
6
  },
7
7
  "peerDependencies": {
8
8
  "react": "^16.6.3 || ^17.0.0 || ^18.0.0"
@@ -1,13 +1,4 @@
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
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.NoopEvaluationsClient = void 0;
13
4
  const client_core_1 = require("@statsig/client-core");
@@ -15,7 +6,7 @@ const _noop = () => {
15
6
  // noop
16
7
  };
17
8
  const _noopAsync = () => Promise.resolve();
18
- const NOOP_DETAILS = { reason: 'Error' };
9
+ const NOOP_DETAILS = { reason: 'Error:NoClient' };
19
10
  const _defaultEvaluation = (type) => {
20
11
  return (...args) => {
21
12
  const name = typeof args[0] === 'string' ? args[0] : args[1];
@@ -46,6 +37,11 @@ const context = {
46
37
  values: null,
47
38
  user: { userID: '' },
48
39
  errorBoundary: {},
40
+ session: {
41
+ data: { sessionID: '', startTime: 0, lastUpdate: 0 },
42
+ sdkKey: '',
43
+ },
44
+ stableID: '',
49
45
  };
50
46
  const _client = {
51
47
  isNoop: true,
@@ -58,12 +54,6 @@ const _client = {
58
54
  updateUserSync: _noop,
59
55
  updateUserAsync: _noopAsync,
60
56
  getContext: () => (Object.assign({}, context)),
61
- getAsyncContext: () => __awaiter(void 0, void 0, void 0, function* () {
62
- return (Object.assign(Object.assign({}, context), { session: {
63
- data: { sessionID: '', startTime: 0, lastUpdate: 0 },
64
- sdkKey: '',
65
- }, stableID: '' }));
66
- }),
67
57
  checkGate: () => false,
68
58
  getFeatureGate: _defaultEvaluation('gate'),
69
59
  getDynamicConfig: _defaultEvaluation('config'),
@@ -14,9 +14,9 @@ function StatsigProvider({ client, children, loadingComponent, }) {
14
14
  client_core_1.SDKType._setBindingType('react');
15
15
  client.$on('values_updated', onValuesUpdated);
16
16
  return () => {
17
- client.shutdown().catch((error) => {
18
- client_core_1.Log.error('An error occured during shutdown', error);
19
- });
17
+ client
18
+ .flush()
19
+ .catch((err) => client_core_1.Log.error('An error occured during flush', err));
20
20
  client.off('values_updated', onValuesUpdated);
21
21
  };
22
22
  }, [client]);
@@ -1,6 +1,7 @@
1
1
  import { PrecomputedEvaluationsInterface } from '@statsig/client-core';
2
2
  type HositedFuncs = Pick<PrecomputedEvaluationsInterface, 'checkGate' | 'getFeatureGate' | 'getDynamicConfig' | 'getExperiment' | 'getLayer' | 'logEvent'>;
3
- export declare function useStatsigClient(): HositedFuncs & {
3
+ type Output = HositedFuncs & {
4
4
  client: PrecomputedEvaluationsInterface;
5
5
  };
6
+ export declare function useStatsigClient(): Output;
6
7
  export {};
@@ -16,29 +16,45 @@ function useStatsigClient() {
16
16
  return NoopEvaluationsClient_1.NoopEvaluationsClient;
17
17
  }, [anyClient, renderVersion]);
18
18
  const deps = [client, renderVersion];
19
- return {
19
+ const checkGate = (0, react_1.useCallback)((name, options) => {
20
+ return client.checkGate(name, options);
21
+ }, deps);
22
+ const getFeatureGate = (0, react_1.useCallback)((name, options) => {
23
+ return client.getFeatureGate(name, options);
24
+ }, deps);
25
+ const getDynamicConfig = (0, react_1.useCallback)((name, options) => {
26
+ return client.getDynamicConfig(name, options);
27
+ }, deps);
28
+ const getExperiment = (0, react_1.useCallback)((name, options) => {
29
+ return client.getExperiment(name, options);
30
+ }, deps);
31
+ const getLayer = (0, react_1.useCallback)((name, options) => {
32
+ return client.getLayer(name, options);
33
+ }, deps);
34
+ const logEvent = (0, react_1.useCallback)((eventName, value, metadata) => {
35
+ if (typeof eventName === 'string') {
36
+ return client.logEvent(eventName, value, metadata);
37
+ }
38
+ return client.logEvent(eventName);
39
+ }, deps);
40
+ return (0, react_1.useMemo)(() => {
41
+ return {
42
+ client,
43
+ checkGate,
44
+ getFeatureGate,
45
+ getDynamicConfig,
46
+ getExperiment,
47
+ getLayer,
48
+ logEvent,
49
+ };
50
+ }, [
20
51
  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
- };
52
+ checkGate,
53
+ getFeatureGate,
54
+ getDynamicConfig,
55
+ getExperiment,
56
+ getLayer,
57
+ logEvent,
58
+ ]);
43
59
  }
44
60
  exports.useStatsigClient = useStatsigClient;