@obelism/improve-sdk-react 0.3.6 → 0.5.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/dist/index.d.mts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +5 -3
package/dist/index.d.mts
CHANGED
|
@@ -10,11 +10,14 @@ type ImproveContextType = {
|
|
|
10
10
|
getTestValue: ImproveClientSDK['getTestValue'];
|
|
11
11
|
postAnalytic: ImproveClientSDK['postAnalytic'];
|
|
12
12
|
};
|
|
13
|
+
type ImproveStatus = 'loading' | 'setup' | 'error';
|
|
13
14
|
declare const generateImproveProvider: (improveSetupArgs: ImproveSetupArgs) => {
|
|
14
15
|
ImproveProvider: ({ children }: ImproveProviderProps) => react_jsx_runtime.JSX.Element;
|
|
16
|
+
useImproveStatus: () => ImproveStatus;
|
|
15
17
|
usePostAnalytic: (testSlug: string) => (event: string, message?: string) => Promise<Response>;
|
|
16
|
-
useTestValue: (testSlug: string) => string;
|
|
17
|
-
useFlagValue: (flagSlug: string) => string;
|
|
18
|
+
useTestValue: (testSlug: string, fallback?: string) => string;
|
|
19
|
+
useFlagValue: (flagSlug: string, fallback?: string) => string;
|
|
18
20
|
};
|
|
19
21
|
|
|
20
|
-
export {
|
|
22
|
+
export { generateImproveProvider };
|
|
23
|
+
export type { ImproveContextType, ImproveProviderProps };
|
package/dist/index.d.ts
CHANGED
|
@@ -10,11 +10,14 @@ type ImproveContextType = {
|
|
|
10
10
|
getTestValue: ImproveClientSDK['getTestValue'];
|
|
11
11
|
postAnalytic: ImproveClientSDK['postAnalytic'];
|
|
12
12
|
};
|
|
13
|
+
type ImproveStatus = 'loading' | 'setup' | 'error';
|
|
13
14
|
declare const generateImproveProvider: (improveSetupArgs: ImproveSetupArgs) => {
|
|
14
15
|
ImproveProvider: ({ children }: ImproveProviderProps) => react_jsx_runtime.JSX.Element;
|
|
16
|
+
useImproveStatus: () => ImproveStatus;
|
|
15
17
|
usePostAnalytic: (testSlug: string) => (event: string, message?: string) => Promise<Response>;
|
|
16
|
-
useTestValue: (testSlug: string) => string;
|
|
17
|
-
useFlagValue: (flagSlug: string) => string;
|
|
18
|
+
useTestValue: (testSlug: string, fallback?: string) => string;
|
|
19
|
+
useFlagValue: (flagSlug: string, fallback?: string) => string;
|
|
18
20
|
};
|
|
19
21
|
|
|
20
|
-
export {
|
|
22
|
+
export { generateImproveProvider };
|
|
23
|
+
export type { ImproveContextType, ImproveProviderProps };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react");
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react");let r={getFlagValue:()=>null,getTestValue:()=>null,postAnalytic:()=>null},u=t.createContext("loading"),n=t.createContext(r);exports.generateImproveProvider=l=>({ImproveProvider:({children:a})=>{let[s,o]=t.useState("loading"),c=t.useRef(!1),i=t.useRef(null);t.useEffect(()=>{if(i.current||c.current)return;c.current=!0;let e=!1,t=!1;return import("@obelism/improve-sdk/client").then(async({ImproveClientSDK:r})=>{t||(i.current=new r(l),l.config||await i.current.fetchConfig(),t||(e=!0,o("setup")))}).catch(e=>{c.current=!1,console.error(e),o("error")}),()=>{e||(c.current=!1,t=!0)}},[]);let g=t.useMemo(()=>"setup"===s&&i.current?{getTestValue:i.current.getTestValue,postAnalytic:i.current.postAnalytic,getFlagValue:i.current.getFlagValue}:r,[s]);return e.jsx(u.Provider,{value:s,children:e.jsx(n.Provider,{value:g,children:a})})},useImproveStatus:()=>t.useContext(u),usePostAnalytic:e=>{let{postAnalytic:r}=t.useContext(n);return t.useCallback((t,u)=>r(e,t,u),[r,e])},useTestValue:(e,r)=>{let{getTestValue:u}=t.useContext(n);return u(e)||r},useFlagValue:(e,r)=>{let{getFlagValue:u}=t.useContext(n);return u(e)||r}});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e}from"react/jsx-runtime";import{useState as r,useRef as t,useEffect as l,useMemo as
|
|
1
|
+
import{jsx as e}from"react/jsx-runtime";import{useState as r,useRef as t,useEffect as l,useMemo as u,useContext as n,useCallback as a,createContext as o}from"react";let c={getFlagValue:()=>null,getTestValue:()=>null,postAnalytic:()=>null},i=o("loading"),s=o(c),g=o=>({ImproveProvider:({children:n})=>{let[a,g]=r("loading"),p=t(!1),m=t(null);l(()=>{if(m.current||p.current)return;p.current=!0;let e=!1,r=!1;return import("@obelism/improve-sdk/client").then(async({ImproveClientSDK:t})=>{r||(m.current=new t(o),o.config||await m.current.fetchConfig(),r||(e=!0,g("setup")))}).catch(e=>{p.current=!1,console.error(e),g("error")}),()=>{e||(p.current=!1,r=!0)}},[]);let v=u(()=>"setup"===a&&m.current?{getTestValue:m.current.getTestValue,postAnalytic:m.current.postAnalytic,getFlagValue:m.current.getFlagValue}:c,[a]);return e(i.Provider,{value:a,children:e(s.Provider,{value:v,children:n})})},useImproveStatus:()=>n(i),usePostAnalytic:e=>{let{postAnalytic:r}=n(s);return a((t,l)=>r(e,t,l),[r,e])},useTestValue:(e,r)=>{let{getTestValue:t}=n(s);return t(e)||r},useFlagValue:(e,r)=>{let{getFlagValue:t}=n(s);return t(e)||r}});export{g as generateImproveProvider};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@obelism/improve-sdk-react",
|
|
3
3
|
"description": "Obelism Improve React SDK",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ab-tests",
|
|
7
7
|
"feature-flags",
|
|
@@ -13,8 +13,10 @@
|
|
|
13
13
|
"author": "Obelism <hello@obelism.studio> (https://www.obelism.studio)",
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
16
|
-
"url": "https://github.com/Obelism/improve-sdk
|
|
16
|
+
"url": "https://github.com/Obelism/improve-sdk",
|
|
17
|
+
"directory": "packages/react-sdk"
|
|
17
18
|
},
|
|
19
|
+
"sideEffects": false,
|
|
18
20
|
"files": [
|
|
19
21
|
"dist"
|
|
20
22
|
],
|
|
@@ -61,6 +63,6 @@
|
|
|
61
63
|
"react": ">=18.0.0"
|
|
62
64
|
},
|
|
63
65
|
"dependencies": {
|
|
64
|
-
"@obelism/improve-sdk": "^0.
|
|
66
|
+
"@obelism/improve-sdk": "^0.5.0"
|
|
65
67
|
}
|
|
66
68
|
}
|