@vexillo/react-sdk 2.0.2 → 2.1.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/dist/index.cjs +37 -4
- package/dist/index.mjs +34 -2
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -27,7 +27,7 @@ __export(src_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(src_exports);
|
|
28
28
|
|
|
29
29
|
// src/provider.tsx
|
|
30
|
-
var
|
|
30
|
+
var import_react2 = require("react");
|
|
31
31
|
|
|
32
32
|
// src/fetch-flags.ts
|
|
33
33
|
async function fetchFlags(baseUrl, apiKey) {
|
|
@@ -53,9 +53,42 @@ async function fetchFlags(baseUrl, apiKey) {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
// src/use-promise.ts
|
|
57
|
+
var import_react = require("react");
|
|
58
|
+
function usePromise(promise) {
|
|
59
|
+
const major = parseInt(import_react.version.split(".")[0], 10);
|
|
60
|
+
if (major >= 19 && typeof import_react.use === "function") {
|
|
61
|
+
return (0, import_react.use)(promise);
|
|
62
|
+
}
|
|
63
|
+
return readPromise(promise);
|
|
64
|
+
}
|
|
65
|
+
function readPromise(promise) {
|
|
66
|
+
if (promise.status === "fulfilled") {
|
|
67
|
+
return promise.value;
|
|
68
|
+
}
|
|
69
|
+
if (promise.status === "rejected") {
|
|
70
|
+
throw promise.reason;
|
|
71
|
+
}
|
|
72
|
+
if (promise.status === "pending") {
|
|
73
|
+
throw promise;
|
|
74
|
+
}
|
|
75
|
+
promise.status = "pending";
|
|
76
|
+
promise.then(
|
|
77
|
+
(value) => {
|
|
78
|
+
promise.status = "fulfilled";
|
|
79
|
+
promise.value = value;
|
|
80
|
+
},
|
|
81
|
+
(reason) => {
|
|
82
|
+
promise.status = "rejected";
|
|
83
|
+
promise.reason = reason;
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
throw promise;
|
|
87
|
+
}
|
|
88
|
+
|
|
56
89
|
// src/provider.tsx
|
|
57
90
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
58
|
-
var VexilloContext = (0,
|
|
91
|
+
var VexilloContext = (0, import_react2.createContext)(null);
|
|
59
92
|
var clientCache = /* @__PURE__ */ new Map();
|
|
60
93
|
function getOrCreateFlagPromise(baseUrl, apiKey) {
|
|
61
94
|
const key = `${baseUrl}__${apiKey}`;
|
|
@@ -85,11 +118,11 @@ function VexilloProvider({
|
|
|
85
118
|
} else {
|
|
86
119
|
flagPromise = getOrCreateFlagPromise(baseUrl, apiKey);
|
|
87
120
|
}
|
|
88
|
-
const flags = (
|
|
121
|
+
const flags = usePromise(flagPromise);
|
|
89
122
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(VexilloContext.Provider, { value: { flags, fallbacks }, children });
|
|
90
123
|
}
|
|
91
124
|
function useVexilloContext() {
|
|
92
|
-
const ctx = (0,
|
|
125
|
+
const ctx = (0, import_react2.useContext)(VexilloContext);
|
|
93
126
|
if (ctx === null) {
|
|
94
127
|
throw new Error("useFlag must be called inside a <VexilloProvider>.");
|
|
95
128
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// src/provider.tsx
|
|
2
2
|
import {
|
|
3
3
|
createContext,
|
|
4
|
-
use,
|
|
5
4
|
useContext
|
|
6
5
|
} from "react";
|
|
7
6
|
|
|
@@ -29,6 +28,39 @@ async function fetchFlags(baseUrl, apiKey) {
|
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
30
|
|
|
31
|
+
// src/use-promise.ts
|
|
32
|
+
import { use, version } from "react";
|
|
33
|
+
function usePromise(promise) {
|
|
34
|
+
const major = parseInt(version.split(".")[0], 10);
|
|
35
|
+
if (major >= 19 && typeof use === "function") {
|
|
36
|
+
return use(promise);
|
|
37
|
+
}
|
|
38
|
+
return readPromise(promise);
|
|
39
|
+
}
|
|
40
|
+
function readPromise(promise) {
|
|
41
|
+
if (promise.status === "fulfilled") {
|
|
42
|
+
return promise.value;
|
|
43
|
+
}
|
|
44
|
+
if (promise.status === "rejected") {
|
|
45
|
+
throw promise.reason;
|
|
46
|
+
}
|
|
47
|
+
if (promise.status === "pending") {
|
|
48
|
+
throw promise;
|
|
49
|
+
}
|
|
50
|
+
promise.status = "pending";
|
|
51
|
+
promise.then(
|
|
52
|
+
(value) => {
|
|
53
|
+
promise.status = "fulfilled";
|
|
54
|
+
promise.value = value;
|
|
55
|
+
},
|
|
56
|
+
(reason) => {
|
|
57
|
+
promise.status = "rejected";
|
|
58
|
+
promise.reason = reason;
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
throw promise;
|
|
62
|
+
}
|
|
63
|
+
|
|
32
64
|
// src/provider.tsx
|
|
33
65
|
import { jsx } from "react/jsx-runtime";
|
|
34
66
|
var VexilloContext = createContext(null);
|
|
@@ -61,7 +93,7 @@ function VexilloProvider({
|
|
|
61
93
|
} else {
|
|
62
94
|
flagPromise = getOrCreateFlagPromise(baseUrl, apiKey);
|
|
63
95
|
}
|
|
64
|
-
const flags =
|
|
96
|
+
const flags = usePromise(flagPromise);
|
|
65
97
|
return /* @__PURE__ */ jsx(VexilloContext.Provider, { value: { flags, fallbacks }, children });
|
|
66
98
|
}
|
|
67
99
|
function useVexilloContext() {
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vexillo/react-sdk",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"registry": "https://registry.npmjs.org",
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
10
|
+
"main": "./dist/index.cjs",
|
|
10
11
|
"types": "./dist/index.d.ts",
|
|
11
12
|
"exports": {
|
|
12
13
|
".": {
|
|
@@ -20,8 +21,8 @@
|
|
|
20
21
|
"README.md"
|
|
21
22
|
],
|
|
22
23
|
"peerDependencies": {
|
|
23
|
-
"react": "^19",
|
|
24
|
-
"react-dom": "^19"
|
|
24
|
+
"react": "^18 || ^19",
|
|
25
|
+
"react-dom": "^18 || ^19"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"@testing-library/react": "^16",
|