@hackler/react-sdk 11.1.0 → 11.3.0
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/lib/Context.d.ts +1 -0
- package/lib/Context.d.ts.map +1 -1
- package/lib/Experiment.d.ts.map +1 -1
- package/lib/Feature.d.ts.map +1 -1
- package/lib/Provider.d.ts +2 -1
- package/lib/Provider.d.ts.map +1 -1
- package/lib/config.d.ts +1 -1
- package/lib/hooks.d.ts +20 -5
- package/lib/hooks.d.ts.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +111 -17
- package/lib/index.js +114 -16
- package/lib/index.umd.js +1 -1
- package/package.json +2 -2
- package/CHANGELOG.md +0 -6
package/lib/Context.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { HackleReactSDKClient } from "./client";
|
|
|
4
4
|
interface HackleContext {
|
|
5
5
|
hackle: HackleReactSDKClient | undefined;
|
|
6
6
|
user?: User;
|
|
7
|
+
initialized: boolean;
|
|
7
8
|
}
|
|
8
9
|
export declare const HackleContext: import("react").Context<HackleContext>;
|
|
9
10
|
export declare const HackleContextConsumer: import("react").Consumer<HackleContext>;
|
package/lib/Context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../src/Context.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAE9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAE/C,UAAU,aAAa;IACrB,MAAM,EAAE,oBAAoB,GAAG,SAAS,CAAA;IACxC,IAAI,CAAC,EAAE,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../src/Context.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAE9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAE/C,UAAU,aAAa;IACrB,MAAM,EAAE,oBAAoB,GAAG,SAAS,CAAA;IACxC,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,WAAW,EAAE,OAAO,CAAA;CACrB;AAED,eAAO,MAAM,aAAa,wCAIxB,CAAA;AAEF,eAAO,MAAM,qBAAqB,yCAAyB,CAAA;AAC3D,eAAO,MAAM,qBAAqB,yCAAyB,CAAA"}
|
package/lib/Experiment.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Experiment.d.ts","sourceRoot":"","sources":["../src/Experiment.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B;AACD,iBAAS,UAAU,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"Experiment.d.ts","sourceRoot":"","sources":["../src/Experiment.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B;AACD,iBAAS,UAAU,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,EAAE,eAAe,OAyB/D;AAED,eAAO,MAAM,gBAAgB,mBAAa,CAAA"}
|
package/lib/Feature.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Feature.d.ts","sourceRoot":"","sources":["../src/Feature.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,oBAAY,gBAAgB,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK,KAAK,CAAC,SAAS,CAAA;AAEjE,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,gBAAgB,CAAA;CAC3B;
|
|
1
|
+
{"version":3,"file":"Feature.d.ts","sourceRoot":"","sources":["../src/Feature.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,oBAAY,gBAAgB,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK,KAAK,CAAC,SAAS,CAAA;AAEjE,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,gBAAgB,CAAA;CAC3B;AAYD,eAAO,MAAM,aAAa,uCAAU,CAAA"}
|
package/lib/Provider.d.ts
CHANGED
|
@@ -5,8 +5,9 @@ interface ProviderProps {
|
|
|
5
5
|
hackleClient: HackleReactSDKClient;
|
|
6
6
|
user?: User;
|
|
7
7
|
timeout?: number;
|
|
8
|
+
supportSSR?: boolean;
|
|
8
9
|
children?: ReactNode;
|
|
9
10
|
}
|
|
10
|
-
export declare function HackleProvider({ hackleClient, user, timeout, children }: ProviderProps): JSX.Element | null;
|
|
11
|
+
export declare function HackleProvider({ hackleClient, user, timeout, supportSSR, children }: ProviderProps): JSX.Element | null;
|
|
11
12
|
export {};
|
|
12
13
|
//# sourceMappingURL=Provider.d.ts.map
|
package/lib/Provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../src/Provider.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAE9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAE/C,UAAU,aAAa;IACrB,YAAY,EAAE,oBAAoB,CAAA;IAClC,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB;AAED,wBAAgB,cAAc,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,OAAc,EAAE,QAAQ,EAAE,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../src/Provider.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAE9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAE/C,UAAU,aAAa;IACrB,YAAY,EAAE,oBAAoB,CAAA;IAClC,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB;AAED,wBAAgB,cAAc,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,OAAc,EAAE,UAAkB,EAAE,QAAQ,EAAE,EAAE,aAAa,sBAiDjH"}
|
package/lib/config.d.ts
CHANGED
package/lib/hooks.d.ts
CHANGED
|
@@ -1,15 +1,30 @@
|
|
|
1
|
-
import { Decision, FeatureFlagDecision, HackleEvent
|
|
1
|
+
import { Decision, FeatureFlagDecision, HackleEvent } from "@hackler/javascript-sdk";
|
|
2
|
+
interface Loadable {
|
|
3
|
+
isLoading: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface VariationResult extends Loadable {
|
|
6
|
+
variation: string;
|
|
7
|
+
}
|
|
8
|
+
export interface VariationDetailResult extends Loadable {
|
|
9
|
+
decision: Decision;
|
|
10
|
+
}
|
|
11
|
+
export interface FeatureFlagResult extends Loadable {
|
|
12
|
+
isOn: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface FeatureFlagDetailResult extends Loadable {
|
|
15
|
+
decision: FeatureFlagDecision;
|
|
16
|
+
}
|
|
2
17
|
export declare function useVariation(experimentKey: number, defaultVariation?: string): string;
|
|
3
18
|
export declare function useVariationDetail(experimentKey: number, defaultVariation?: string): Decision;
|
|
19
|
+
export declare function useLoadableVariation(experimentKey: number, defaultVariation?: string): VariationResult;
|
|
20
|
+
export declare function useLoadableVariationDetail(experimentKey: number, defaultVariation?: string): VariationDetailResult;
|
|
4
21
|
export declare function useFeature(featureKey: number): boolean;
|
|
5
22
|
export declare function useFeatureFlagDetail(featureKey: number): FeatureFlagDecision;
|
|
23
|
+
export declare function useLoadableFeature(featureKey: number): FeatureFlagResult;
|
|
24
|
+
export declare function useLoadableFeatureDetail(featureKey: number): FeatureFlagDetailResult;
|
|
6
25
|
interface Track {
|
|
7
26
|
(event: HackleEvent): void;
|
|
8
27
|
}
|
|
9
28
|
export declare function useTrack(): Track;
|
|
10
|
-
interface TrackPageView {
|
|
11
|
-
(option?: PageView): void;
|
|
12
|
-
}
|
|
13
|
-
export declare function usePageView(): TrackPageView;
|
|
14
29
|
export {};
|
|
15
30
|
//# sourceMappingURL=hooks.d.ts.map
|
package/lib/hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAkB,mBAAmB,EAAE,WAAW,EAAgB,MAAM,yBAAyB,CAAA;AAOlH,UAAU,QAAQ;IAChB,SAAS,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,eAAgB,SAAQ,QAAQ;IAC/C,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,qBAAsB,SAAQ,QAAQ;IACrD,QAAQ,EAAE,QAAQ,CAAA;CACnB;AAED,MAAM,WAAW,iBAAkB,SAAQ,QAAQ;IACjD,IAAI,EAAE,OAAO,CAAA;CACd;AAED,MAAM,WAAW,uBAAwB,SAAQ,QAAQ;IACvD,QAAQ,EAAE,mBAAmB,CAAA;CAC9B;AAED,wBAAgB,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,gBAAgB,SAAM,GAAG,MAAM,CA+BlF;AAED,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,EAAE,gBAAgB,SAAM,GAAG,QAAQ,CA6B1F;AAED,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE,gBAAgB,SAAM,GAAG,eAAe,CAOnG;AAED,wBAAgB,0BAA0B,CAAC,aAAa,EAAE,MAAM,EAAE,gBAAgB,SAAM,GAAG,qBAAqB,CAmC/G;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CA6BtD;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,mBAAmB,CA6B5E;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,CAOxE;AAED,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,uBAAuB,CAkCpF;AAED,UAAU,KAAK;IACb,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAA;CAC3B;AACD,wBAAgB,QAAQ,IAAI,KAAK,CAShC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export * from "@hackler/javascript-sdk";
|
|
|
2
2
|
export { createInstance } from "./client";
|
|
3
3
|
export { HackleProvider } from "./Provider";
|
|
4
4
|
export { HackleContext, HackleContextProvider, HackleContextConsumer } from "./Context";
|
|
5
|
-
export { useVariation, useVariationDetail, useTrack, useFeature, useFeatureFlagDetail } from "./hooks";
|
|
5
|
+
export { useVariation, useVariationDetail, useTrack, useFeature, useFeatureFlagDetail, useLoadableVariation, useLoadableVariationDetail, useLoadableFeature, useLoadableFeatureDetail, VariationResult, VariationDetailResult, FeatureFlagResult, FeatureFlagDetailResult } from "./hooks";
|
|
6
6
|
export { HackleExperiment } from "./Experiment";
|
|
7
7
|
export { HackleVariation } from "./Variation";
|
|
8
8
|
export { HackleFeature } from "./Feature";
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AAEvC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA;AACvF,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AAEvC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA;AACvF,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACR,UAAU,EACV,oBAAoB,EACpB,oBAAoB,EACpB,0BAA0B,EAC1B,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA"}
|
package/lib/index.es.js
CHANGED
|
@@ -48,7 +48,7 @@ function __read(o, n) {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
var SDK_NAME_HEADER = "react-sdk";
|
|
51
|
-
var SDK_VERSION_HEADER = "11.
|
|
51
|
+
var SDK_VERSION_HEADER = "11.3.0";
|
|
52
52
|
|
|
53
53
|
var HackleReactSDKClient = /** @class */ (function () {
|
|
54
54
|
function HackleReactSDKClient(sdkKey, config) {
|
|
@@ -87,17 +87,18 @@ function createInstance(sdkKey, config) {
|
|
|
87
87
|
var HackleContext = createContext({
|
|
88
88
|
hackle: undefined,
|
|
89
89
|
user: undefined,
|
|
90
|
+
initialized: false,
|
|
90
91
|
});
|
|
91
92
|
var HackleContextConsumer = HackleContext.Consumer;
|
|
92
93
|
var HackleContextProvider = HackleContext.Provider;
|
|
93
94
|
|
|
94
95
|
function HackleProvider(_a) {
|
|
95
|
-
var hackleClient = _a.hackleClient, user = _a.user, _b = _a.timeout, timeout = _b === void 0 ? 3000 : _b, children = _a.children;
|
|
96
|
+
var hackleClient = _a.hackleClient, user = _a.user, _b = _a.timeout, timeout = _b === void 0 ? 3000 : _b, _c = _a.supportSSR, supportSSR = _c === void 0 ? false : _c, children = _a.children;
|
|
96
97
|
var state = {
|
|
97
98
|
hackle: hackleClient,
|
|
98
99
|
user: user,
|
|
100
|
+
initialized: false
|
|
99
101
|
};
|
|
100
|
-
var _c = __read(useState(false), 2), ready = _c[0], setReady = _c[1];
|
|
101
102
|
var _d = __read(useState(state), 2), value = _d[0], setValue = _d[1];
|
|
102
103
|
useEffect(function () {
|
|
103
104
|
setValue(function (prevState) {
|
|
@@ -107,21 +108,32 @@ function HackleProvider(_a) {
|
|
|
107
108
|
useEffect(function () {
|
|
108
109
|
hackleClient.onInitialized({ timeout: timeout })
|
|
109
110
|
.then(function () {
|
|
110
|
-
|
|
111
|
+
setValue(function (prevState) {
|
|
112
|
+
return __assign(__assign({}, prevState), { initialized: true });
|
|
113
|
+
});
|
|
111
114
|
}, function () {
|
|
112
|
-
|
|
115
|
+
setValue(function (prevState) {
|
|
116
|
+
return __assign(__assign({}, prevState), { initialized: true });
|
|
117
|
+
});
|
|
118
|
+
}).catch(function () {
|
|
119
|
+
setValue(function (prevState) {
|
|
120
|
+
return __assign(__assign({}, prevState), { initialized: true });
|
|
121
|
+
});
|
|
113
122
|
});
|
|
114
123
|
}, [hackleClient]);
|
|
115
|
-
|
|
124
|
+
if (supportSSR) {
|
|
125
|
+
return React__default.createElement(HackleContextProvider, { value: value }, children);
|
|
126
|
+
}
|
|
127
|
+
return value.initialized ? React__default.createElement(HackleContextProvider, { value: value }, children) : null;
|
|
116
128
|
}
|
|
117
129
|
|
|
118
130
|
var log = Logger.log;
|
|
119
131
|
function useVariation(experimentKey, defaultVariation) {
|
|
120
132
|
if (defaultVariation === void 0) { defaultVariation = "A"; }
|
|
121
|
-
var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user;
|
|
133
|
+
var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user, initialized = _a.initialized;
|
|
122
134
|
var getVariation = useCallback(function () {
|
|
123
|
-
return (hackle === null || hackle === void 0 ? void 0 : hackle.variation(experimentKey, user)) || defaultVariation;
|
|
124
|
-
}, [defaultVariation, experimentKey, user, hackle]);
|
|
135
|
+
return initialized && (hackle === null || hackle === void 0 ? void 0 : hackle.variation(experimentKey, user)) || defaultVariation;
|
|
136
|
+
}, [defaultVariation, experimentKey, user, hackle, initialized]);
|
|
125
137
|
var _b = __read(useState(function () {
|
|
126
138
|
if (notExistClient(hackle)) {
|
|
127
139
|
if ((typeof window) !== "undefined") {
|
|
@@ -133,7 +145,8 @@ function useVariation(experimentKey, defaultVariation) {
|
|
|
133
145
|
}), 2), variation = _b[0], setVariation = _b[1];
|
|
134
146
|
var currentInput = {
|
|
135
147
|
key: experimentKey,
|
|
136
|
-
user: user
|
|
148
|
+
user: user,
|
|
149
|
+
initialized: initialized
|
|
137
150
|
};
|
|
138
151
|
var _c = __read(useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
|
|
139
152
|
if (!isInputEqual(prevInput, currentInput)) {
|
|
@@ -168,6 +181,45 @@ function useVariationDetail(experimentKey, defaultVariation) {
|
|
|
168
181
|
}
|
|
169
182
|
return variationDetail;
|
|
170
183
|
}
|
|
184
|
+
function useLoadableVariation(experimentKey, defaultVariation) {
|
|
185
|
+
if (defaultVariation === void 0) { defaultVariation = "A"; }
|
|
186
|
+
var _a = useLoadableVariationDetail(experimentKey, defaultVariation), isLoading = _a.isLoading, decision = _a.decision;
|
|
187
|
+
return {
|
|
188
|
+
isLoading: isLoading,
|
|
189
|
+
variation: decision.variation
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function useLoadableVariationDetail(experimentKey, defaultVariation) {
|
|
193
|
+
if (defaultVariation === void 0) { defaultVariation = "A"; }
|
|
194
|
+
var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user, initialized = _a.initialized;
|
|
195
|
+
var getVariationDetail = useCallback(function () {
|
|
196
|
+
if (!initialized) {
|
|
197
|
+
return Decision.of(defaultVariation, DecisionReason.SDK_NOT_READY);
|
|
198
|
+
}
|
|
199
|
+
return (hackle === null || hackle === void 0 ? void 0 : hackle.variationDetail(experimentKey, user)) || Decision.of(defaultVariation, DecisionReason.EXCEPTION);
|
|
200
|
+
}, [defaultVariation, experimentKey, user, hackle, initialized]);
|
|
201
|
+
var _b = __read(useState(function () {
|
|
202
|
+
if (notExistClient(hackle)) {
|
|
203
|
+
log.error("HackleClient is not existed");
|
|
204
|
+
return Decision.of(defaultVariation, DecisionReason.EXCEPTION);
|
|
205
|
+
}
|
|
206
|
+
return getVariationDetail();
|
|
207
|
+
}), 2), variationDetail = _b[0], setVariationDetail = _b[1];
|
|
208
|
+
var currentInput = {
|
|
209
|
+
key: experimentKey,
|
|
210
|
+
user: user,
|
|
211
|
+
initialized: initialized
|
|
212
|
+
};
|
|
213
|
+
var _c = __read(useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
|
|
214
|
+
if (!isInputEqual(prevInput, currentInput)) {
|
|
215
|
+
setPrevInput(currentInput);
|
|
216
|
+
setVariationDetail(getVariationDetail());
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
isLoading: !initialized,
|
|
220
|
+
decision: variationDetail
|
|
221
|
+
};
|
|
222
|
+
}
|
|
171
223
|
function useFeature(featureKey) {
|
|
172
224
|
var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user;
|
|
173
225
|
var getIsOn = useCallback(function () {
|
|
@@ -218,12 +270,47 @@ function useFeatureFlagDetail(featureKey) {
|
|
|
218
270
|
}
|
|
219
271
|
return featureDetail;
|
|
220
272
|
}
|
|
273
|
+
function useLoadableFeature(featureKey) {
|
|
274
|
+
var _a = useLoadableFeatureDetail(featureKey), isLoading = _a.isLoading, decision = _a.decision;
|
|
275
|
+
return {
|
|
276
|
+
isLoading: isLoading,
|
|
277
|
+
isOn: decision.isOn
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
function useLoadableFeatureDetail(featureKey) {
|
|
281
|
+
var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user, initialized = _a.initialized;
|
|
282
|
+
var getFeatureDetail = useCallback(function () {
|
|
283
|
+
if (!initialized) {
|
|
284
|
+
return FeatureFlagDecision.off(DecisionReason.SDK_NOT_READY);
|
|
285
|
+
}
|
|
286
|
+
return (hackle === null || hackle === void 0 ? void 0 : hackle.featureFlagDetail(featureKey, user)) || FeatureFlagDecision.off(DecisionReason.EXCEPTION);
|
|
287
|
+
}, [featureKey, user, hackle]);
|
|
288
|
+
var _b = __read(useState(function () {
|
|
289
|
+
if (notExistClient(hackle)) {
|
|
290
|
+
log.error("HackleClient is not existed");
|
|
291
|
+
return FeatureFlagDecision.off(DecisionReason.EXCEPTION);
|
|
292
|
+
}
|
|
293
|
+
return getFeatureDetail();
|
|
294
|
+
}), 2), featureDetail = _b[0], setFeatureDetail = _b[1];
|
|
295
|
+
var currentInput = {
|
|
296
|
+
key: featureKey,
|
|
297
|
+
user: user,
|
|
298
|
+
initialized: initialized
|
|
299
|
+
};
|
|
300
|
+
var _c = __read(useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
|
|
301
|
+
if (!isInputEqual(prevInput, currentInput)) {
|
|
302
|
+
setPrevInput(currentInput);
|
|
303
|
+
setFeatureDetail(getFeatureDetail());
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
isLoading: !initialized,
|
|
307
|
+
decision: featureDetail
|
|
308
|
+
};
|
|
309
|
+
}
|
|
221
310
|
function useTrack() {
|
|
222
311
|
var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user;
|
|
223
312
|
if (notExistClient(hackle)) {
|
|
224
|
-
|
|
225
|
-
log.error("HackleClient is not existed");
|
|
226
|
-
}
|
|
313
|
+
log.error("HackleClient is not existed");
|
|
227
314
|
return function () { };
|
|
228
315
|
}
|
|
229
316
|
return function (event) { return hackle === null || hackle === void 0 ? void 0 : hackle.track(event, user); };
|
|
@@ -233,7 +320,8 @@ function notExistClient(hackle) {
|
|
|
233
320
|
}
|
|
234
321
|
function isInputEqual(prev, current) {
|
|
235
322
|
var _a, _b, _c, _d;
|
|
236
|
-
return (prev.
|
|
323
|
+
return (prev.initialized === current.initialized &&
|
|
324
|
+
prev.key === current.key &&
|
|
237
325
|
((_a = prev.user) === null || _a === void 0 ? void 0 : _a.id) === ((_b = current.user) === null || _b === void 0 ? void 0 : _b.id) &&
|
|
238
326
|
arePropertiesEqual((_c = prev.user) === null || _c === void 0 ? void 0 : _c.properties, (_d = current.user) === null || _d === void 0 ? void 0 : _d.properties));
|
|
239
327
|
}
|
|
@@ -258,7 +346,10 @@ function coerceUnknownToProperties(props) {
|
|
|
258
346
|
|
|
259
347
|
function Experiment(_a) {
|
|
260
348
|
var experimentKey = _a.experimentKey, children = _a.children;
|
|
261
|
-
var
|
|
349
|
+
var _b = useLoadableVariation(experimentKey), isLoading = _b.isLoading, variation = _b.variation;
|
|
350
|
+
if (isLoading) {
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
262
353
|
if (!!children && typeof children === "function") {
|
|
263
354
|
return children(variation);
|
|
264
355
|
}
|
|
@@ -287,9 +378,12 @@ function Variation(_a) {
|
|
|
287
378
|
var HackleVariation = Variation;
|
|
288
379
|
|
|
289
380
|
var Feature = function (props) {
|
|
290
|
-
var
|
|
381
|
+
var _a = useLoadableFeature(props.featureKey), isLoading = _a.isLoading, featureOn = _a.isOn;
|
|
382
|
+
if (isLoading) {
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
291
385
|
return React__default.createElement(React__default.Fragment, null, props.children(featureOn));
|
|
292
386
|
};
|
|
293
387
|
var HackleFeature = Feature;
|
|
294
388
|
|
|
295
|
-
export { HackleContext, HackleContextConsumer, HackleContextProvider, HackleExperiment, HackleFeature, HackleProvider, HackleVariation, createInstance, useFeature, useFeatureFlagDetail, useTrack, useVariation, useVariationDetail };
|
|
389
|
+
export { HackleContext, HackleContextConsumer, HackleContextProvider, HackleExperiment, HackleFeature, HackleProvider, HackleVariation, createInstance, useFeature, useFeatureFlagDetail, useLoadableFeature, useLoadableFeatureDetail, useLoadableVariation, useLoadableVariationDetail, useTrack, useVariation, useVariationDetail };
|
package/lib/index.js
CHANGED
|
@@ -73,7 +73,7 @@ function __read(o, n) {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
var SDK_NAME_HEADER = "react-sdk";
|
|
76
|
-
var SDK_VERSION_HEADER = "11.
|
|
76
|
+
var SDK_VERSION_HEADER = "11.3.0";
|
|
77
77
|
|
|
78
78
|
var HackleReactSDKClient = /** @class */ (function () {
|
|
79
79
|
function HackleReactSDKClient(sdkKey, config) {
|
|
@@ -112,17 +112,18 @@ function createInstance(sdkKey, config) {
|
|
|
112
112
|
var HackleContext = React.createContext({
|
|
113
113
|
hackle: undefined,
|
|
114
114
|
user: undefined,
|
|
115
|
+
initialized: false,
|
|
115
116
|
});
|
|
116
117
|
var HackleContextConsumer = HackleContext.Consumer;
|
|
117
118
|
var HackleContextProvider = HackleContext.Provider;
|
|
118
119
|
|
|
119
120
|
function HackleProvider(_a) {
|
|
120
|
-
var hackleClient = _a.hackleClient, user = _a.user, _b = _a.timeout, timeout = _b === void 0 ? 3000 : _b, children = _a.children;
|
|
121
|
+
var hackleClient = _a.hackleClient, user = _a.user, _b = _a.timeout, timeout = _b === void 0 ? 3000 : _b, _c = _a.supportSSR, supportSSR = _c === void 0 ? false : _c, children = _a.children;
|
|
121
122
|
var state = {
|
|
122
123
|
hackle: hackleClient,
|
|
123
124
|
user: user,
|
|
125
|
+
initialized: false
|
|
124
126
|
};
|
|
125
|
-
var _c = __read(React.useState(false), 2), ready = _c[0], setReady = _c[1];
|
|
126
127
|
var _d = __read(React.useState(state), 2), value = _d[0], setValue = _d[1];
|
|
127
128
|
React.useEffect(function () {
|
|
128
129
|
setValue(function (prevState) {
|
|
@@ -132,21 +133,32 @@ function HackleProvider(_a) {
|
|
|
132
133
|
React.useEffect(function () {
|
|
133
134
|
hackleClient.onInitialized({ timeout: timeout })
|
|
134
135
|
.then(function () {
|
|
135
|
-
|
|
136
|
+
setValue(function (prevState) {
|
|
137
|
+
return __assign(__assign({}, prevState), { initialized: true });
|
|
138
|
+
});
|
|
136
139
|
}, function () {
|
|
137
|
-
|
|
140
|
+
setValue(function (prevState) {
|
|
141
|
+
return __assign(__assign({}, prevState), { initialized: true });
|
|
142
|
+
});
|
|
143
|
+
}).catch(function () {
|
|
144
|
+
setValue(function (prevState) {
|
|
145
|
+
return __assign(__assign({}, prevState), { initialized: true });
|
|
146
|
+
});
|
|
138
147
|
});
|
|
139
148
|
}, [hackleClient]);
|
|
140
|
-
|
|
149
|
+
if (supportSSR) {
|
|
150
|
+
return React__default["default"].createElement(HackleContextProvider, { value: value }, children);
|
|
151
|
+
}
|
|
152
|
+
return value.initialized ? React__default["default"].createElement(HackleContextProvider, { value: value }, children) : null;
|
|
141
153
|
}
|
|
142
154
|
|
|
143
155
|
var log = Hackle.Logger.log;
|
|
144
156
|
function useVariation(experimentKey, defaultVariation) {
|
|
145
157
|
if (defaultVariation === void 0) { defaultVariation = "A"; }
|
|
146
|
-
var _a = React.useContext(HackleContext), hackle = _a.hackle, user = _a.user;
|
|
158
|
+
var _a = React.useContext(HackleContext), hackle = _a.hackle, user = _a.user, initialized = _a.initialized;
|
|
147
159
|
var getVariation = React.useCallback(function () {
|
|
148
|
-
return (hackle === null || hackle === void 0 ? void 0 : hackle.variation(experimentKey, user)) || defaultVariation;
|
|
149
|
-
}, [defaultVariation, experimentKey, user, hackle]);
|
|
160
|
+
return initialized && (hackle === null || hackle === void 0 ? void 0 : hackle.variation(experimentKey, user)) || defaultVariation;
|
|
161
|
+
}, [defaultVariation, experimentKey, user, hackle, initialized]);
|
|
150
162
|
var _b = __read(React.useState(function () {
|
|
151
163
|
if (notExistClient(hackle)) {
|
|
152
164
|
if ((typeof window) !== "undefined") {
|
|
@@ -158,7 +170,8 @@ function useVariation(experimentKey, defaultVariation) {
|
|
|
158
170
|
}), 2), variation = _b[0], setVariation = _b[1];
|
|
159
171
|
var currentInput = {
|
|
160
172
|
key: experimentKey,
|
|
161
|
-
user: user
|
|
173
|
+
user: user,
|
|
174
|
+
initialized: initialized
|
|
162
175
|
};
|
|
163
176
|
var _c = __read(React.useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
|
|
164
177
|
if (!isInputEqual(prevInput, currentInput)) {
|
|
@@ -193,6 +206,45 @@ function useVariationDetail(experimentKey, defaultVariation) {
|
|
|
193
206
|
}
|
|
194
207
|
return variationDetail;
|
|
195
208
|
}
|
|
209
|
+
function useLoadableVariation(experimentKey, defaultVariation) {
|
|
210
|
+
if (defaultVariation === void 0) { defaultVariation = "A"; }
|
|
211
|
+
var _a = useLoadableVariationDetail(experimentKey, defaultVariation), isLoading = _a.isLoading, decision = _a.decision;
|
|
212
|
+
return {
|
|
213
|
+
isLoading: isLoading,
|
|
214
|
+
variation: decision.variation
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
function useLoadableVariationDetail(experimentKey, defaultVariation) {
|
|
218
|
+
if (defaultVariation === void 0) { defaultVariation = "A"; }
|
|
219
|
+
var _a = React.useContext(HackleContext), hackle = _a.hackle, user = _a.user, initialized = _a.initialized;
|
|
220
|
+
var getVariationDetail = React.useCallback(function () {
|
|
221
|
+
if (!initialized) {
|
|
222
|
+
return Hackle.Decision.of(defaultVariation, Hackle.DecisionReason.SDK_NOT_READY);
|
|
223
|
+
}
|
|
224
|
+
return (hackle === null || hackle === void 0 ? void 0 : hackle.variationDetail(experimentKey, user)) || Hackle.Decision.of(defaultVariation, Hackle.DecisionReason.EXCEPTION);
|
|
225
|
+
}, [defaultVariation, experimentKey, user, hackle, initialized]);
|
|
226
|
+
var _b = __read(React.useState(function () {
|
|
227
|
+
if (notExistClient(hackle)) {
|
|
228
|
+
log.error("HackleClient is not existed");
|
|
229
|
+
return Hackle.Decision.of(defaultVariation, Hackle.DecisionReason.EXCEPTION);
|
|
230
|
+
}
|
|
231
|
+
return getVariationDetail();
|
|
232
|
+
}), 2), variationDetail = _b[0], setVariationDetail = _b[1];
|
|
233
|
+
var currentInput = {
|
|
234
|
+
key: experimentKey,
|
|
235
|
+
user: user,
|
|
236
|
+
initialized: initialized
|
|
237
|
+
};
|
|
238
|
+
var _c = __read(React.useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
|
|
239
|
+
if (!isInputEqual(prevInput, currentInput)) {
|
|
240
|
+
setPrevInput(currentInput);
|
|
241
|
+
setVariationDetail(getVariationDetail());
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
isLoading: !initialized,
|
|
245
|
+
decision: variationDetail
|
|
246
|
+
};
|
|
247
|
+
}
|
|
196
248
|
function useFeature(featureKey) {
|
|
197
249
|
var _a = React.useContext(HackleContext), hackle = _a.hackle, user = _a.user;
|
|
198
250
|
var getIsOn = React.useCallback(function () {
|
|
@@ -243,12 +295,47 @@ function useFeatureFlagDetail(featureKey) {
|
|
|
243
295
|
}
|
|
244
296
|
return featureDetail;
|
|
245
297
|
}
|
|
298
|
+
function useLoadableFeature(featureKey) {
|
|
299
|
+
var _a = useLoadableFeatureDetail(featureKey), isLoading = _a.isLoading, decision = _a.decision;
|
|
300
|
+
return {
|
|
301
|
+
isLoading: isLoading,
|
|
302
|
+
isOn: decision.isOn
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function useLoadableFeatureDetail(featureKey) {
|
|
306
|
+
var _a = React.useContext(HackleContext), hackle = _a.hackle, user = _a.user, initialized = _a.initialized;
|
|
307
|
+
var getFeatureDetail = React.useCallback(function () {
|
|
308
|
+
if (!initialized) {
|
|
309
|
+
return Hackle.FeatureFlagDecision.off(Hackle.DecisionReason.SDK_NOT_READY);
|
|
310
|
+
}
|
|
311
|
+
return (hackle === null || hackle === void 0 ? void 0 : hackle.featureFlagDetail(featureKey, user)) || Hackle.FeatureFlagDecision.off(Hackle.DecisionReason.EXCEPTION);
|
|
312
|
+
}, [featureKey, user, hackle]);
|
|
313
|
+
var _b = __read(React.useState(function () {
|
|
314
|
+
if (notExistClient(hackle)) {
|
|
315
|
+
log.error("HackleClient is not existed");
|
|
316
|
+
return Hackle.FeatureFlagDecision.off(Hackle.DecisionReason.EXCEPTION);
|
|
317
|
+
}
|
|
318
|
+
return getFeatureDetail();
|
|
319
|
+
}), 2), featureDetail = _b[0], setFeatureDetail = _b[1];
|
|
320
|
+
var currentInput = {
|
|
321
|
+
key: featureKey,
|
|
322
|
+
user: user,
|
|
323
|
+
initialized: initialized
|
|
324
|
+
};
|
|
325
|
+
var _c = __read(React.useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
|
|
326
|
+
if (!isInputEqual(prevInput, currentInput)) {
|
|
327
|
+
setPrevInput(currentInput);
|
|
328
|
+
setFeatureDetail(getFeatureDetail());
|
|
329
|
+
}
|
|
330
|
+
return {
|
|
331
|
+
isLoading: !initialized,
|
|
332
|
+
decision: featureDetail
|
|
333
|
+
};
|
|
334
|
+
}
|
|
246
335
|
function useTrack() {
|
|
247
336
|
var _a = React.useContext(HackleContext), hackle = _a.hackle, user = _a.user;
|
|
248
337
|
if (notExistClient(hackle)) {
|
|
249
|
-
|
|
250
|
-
log.error("HackleClient is not existed");
|
|
251
|
-
}
|
|
338
|
+
log.error("HackleClient is not existed");
|
|
252
339
|
return function () { };
|
|
253
340
|
}
|
|
254
341
|
return function (event) { return hackle === null || hackle === void 0 ? void 0 : hackle.track(event, user); };
|
|
@@ -258,7 +345,8 @@ function notExistClient(hackle) {
|
|
|
258
345
|
}
|
|
259
346
|
function isInputEqual(prev, current) {
|
|
260
347
|
var _a, _b, _c, _d;
|
|
261
|
-
return (prev.
|
|
348
|
+
return (prev.initialized === current.initialized &&
|
|
349
|
+
prev.key === current.key &&
|
|
262
350
|
((_a = prev.user) === null || _a === void 0 ? void 0 : _a.id) === ((_b = current.user) === null || _b === void 0 ? void 0 : _b.id) &&
|
|
263
351
|
arePropertiesEqual((_c = prev.user) === null || _c === void 0 ? void 0 : _c.properties, (_d = current.user) === null || _d === void 0 ? void 0 : _d.properties));
|
|
264
352
|
}
|
|
@@ -283,7 +371,10 @@ function coerceUnknownToProperties(props) {
|
|
|
283
371
|
|
|
284
372
|
function Experiment(_a) {
|
|
285
373
|
var experimentKey = _a.experimentKey, children = _a.children;
|
|
286
|
-
var
|
|
374
|
+
var _b = useLoadableVariation(experimentKey), isLoading = _b.isLoading, variation = _b.variation;
|
|
375
|
+
if (isLoading) {
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
287
378
|
if (!!children && typeof children === "function") {
|
|
288
379
|
return children(variation);
|
|
289
380
|
}
|
|
@@ -312,7 +403,10 @@ function Variation(_a) {
|
|
|
312
403
|
var HackleVariation = Variation;
|
|
313
404
|
|
|
314
405
|
var Feature = function (props) {
|
|
315
|
-
var
|
|
406
|
+
var _a = useLoadableFeature(props.featureKey), isLoading = _a.isLoading, featureOn = _a.isOn;
|
|
407
|
+
if (isLoading) {
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
316
410
|
return React__default["default"].createElement(React__default["default"].Fragment, null, props.children(featureOn));
|
|
317
411
|
};
|
|
318
412
|
var HackleFeature = Feature;
|
|
@@ -327,6 +421,10 @@ exports.HackleVariation = HackleVariation;
|
|
|
327
421
|
exports.createInstance = createInstance;
|
|
328
422
|
exports.useFeature = useFeature;
|
|
329
423
|
exports.useFeatureFlagDetail = useFeatureFlagDetail;
|
|
424
|
+
exports.useLoadableFeature = useLoadableFeature;
|
|
425
|
+
exports.useLoadableFeatureDetail = useLoadableFeatureDetail;
|
|
426
|
+
exports.useLoadableVariation = useLoadableVariation;
|
|
427
|
+
exports.useLoadableVariationDetail = useLoadableVariationDetail;
|
|
330
428
|
exports.useTrack = useTrack;
|
|
331
429
|
exports.useVariation = useVariation;
|
|
332
430
|
exports.useVariationDetail = useVariationDetail;
|