@ttoss/react-feature-flags 0.1.14 → 0.2.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/esm/index.js +1 -1
- package/package.json +7 -7
- package/dist/index.d.mts +0 -26
- package/dist/index.js +0 -117
package/dist/esm/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import * as React2 from "react";
|
|
|
6
6
|
// src/FeatureFlagsProvider.tsx
|
|
7
7
|
import * as React from "react";
|
|
8
8
|
import { jsx } from "react/jsx-runtime";
|
|
9
|
-
var FeatureFlagsContext =
|
|
9
|
+
var FeatureFlagsContext = React.createContext({
|
|
10
10
|
features: [],
|
|
11
11
|
setFeatures: () => {}
|
|
12
12
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/react-feature-flags",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "React Feature Flags",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"url": "https://github.com/ttoss/ttoss.git",
|
|
12
12
|
"directory": "packages/react-feature-flags"
|
|
13
13
|
},
|
|
14
|
+
"type": "module",
|
|
14
15
|
"exports": {
|
|
15
16
|
".": {
|
|
16
17
|
"import": "./dist/esm/index.js",
|
|
17
|
-
"require": "./dist/index.js",
|
|
18
18
|
"types": "./dist/index.d.ts"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"react": ">=16.8.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/react": "^18.3.
|
|
29
|
+
"@types/react": "^18.3.7",
|
|
30
30
|
"jest": "^29.7.0",
|
|
31
31
|
"react": "^18.3.1",
|
|
32
|
-
"tsup": "^8.
|
|
33
|
-
"@ttoss/
|
|
34
|
-
"@ttoss/
|
|
32
|
+
"tsup": "^8.3.0",
|
|
33
|
+
"@ttoss/test-utils": "^2.1.14",
|
|
34
|
+
"@ttoss/config": "^1.32.10"
|
|
35
35
|
},
|
|
36
36
|
"keywords": [
|
|
37
37
|
"feature-flags",
|
|
@@ -43,6 +43,6 @@
|
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "tsup",
|
|
46
|
-
"test": "jest"
|
|
46
|
+
"test": "jest --projects tests/unit"
|
|
47
47
|
}
|
|
48
48
|
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
|
|
4
|
-
interface FeatureFlagProps {
|
|
5
|
-
name: FeatureFlags;
|
|
6
|
-
children: React.ReactNode;
|
|
7
|
-
fallback?: React.ReactNode;
|
|
8
|
-
}
|
|
9
|
-
declare const FeatureFlag: ({ name, children, fallback, }: FeatureFlagProps) => string | number | boolean | Iterable<React.ReactNode> | react_jsx_runtime.JSX.Element | null;
|
|
10
|
-
|
|
11
|
-
declare const FeatureFlagsProvider: ({ children, loadFeatures, }: {
|
|
12
|
-
children: React.ReactNode;
|
|
13
|
-
loadFeatures?: () => Promise<FeatureFlags[]>;
|
|
14
|
-
}) => react_jsx_runtime.JSX.Element;
|
|
15
|
-
|
|
16
|
-
declare const useFeatureFlag: (name: FeatureFlags) => boolean;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* If you want to update the feature flags on React environment
|
|
20
|
-
* (after the initial render and providers), you can use this hook.
|
|
21
|
-
*/
|
|
22
|
-
declare const useUpdateFeatures: () => {
|
|
23
|
-
updateFeatures: (features: FeatureFlags[]) => void;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export { FeatureFlag, FeatureFlagsProvider, useFeatureFlag, useUpdateFeatures };
|
package/dist/index.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
var __create = Object.create;
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __export = (target, all) => {
|
|
11
|
-
for (var name in all) __defProp(target, name, {
|
|
12
|
-
get: all[name],
|
|
13
|
-
enumerable: true
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
var __copyProps = (to, from, except, desc) => {
|
|
17
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
-
get: () => from[key],
|
|
20
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
return to;
|
|
24
|
-
};
|
|
25
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
26
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
31
|
-
value: mod,
|
|
32
|
-
enumerable: true
|
|
33
|
-
}) : target, mod));
|
|
34
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
35
|
-
value: true
|
|
36
|
-
}), mod);
|
|
37
|
-
|
|
38
|
-
// src/index.ts
|
|
39
|
-
var src_exports = {};
|
|
40
|
-
__export(src_exports, {
|
|
41
|
-
FeatureFlag: () => FeatureFlag,
|
|
42
|
-
FeatureFlagsProvider: () => FeatureFlagsProvider,
|
|
43
|
-
useFeatureFlag: () => useFeatureFlag,
|
|
44
|
-
useUpdateFeatures: () => useUpdateFeatures
|
|
45
|
-
});
|
|
46
|
-
module.exports = __toCommonJS(src_exports);
|
|
47
|
-
|
|
48
|
-
// src/useFeatureFlag.ts
|
|
49
|
-
var React2 = __toESM(require("react"));
|
|
50
|
-
|
|
51
|
-
// src/FeatureFlagsProvider.tsx
|
|
52
|
-
var React = __toESM(require("react"));
|
|
53
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
54
|
-
var FeatureFlagsContext = React.createContext({
|
|
55
|
-
features: [],
|
|
56
|
-
setFeatures: () => {}
|
|
57
|
-
});
|
|
58
|
-
var FeatureFlagsProvider = ({
|
|
59
|
-
children,
|
|
60
|
-
loadFeatures
|
|
61
|
-
}) => {
|
|
62
|
-
const [features, setFeatures] = React.useState([]);
|
|
63
|
-
React.useEffect(() => {
|
|
64
|
-
loadFeatures?.().then(features2 => {
|
|
65
|
-
return setFeatures(features2);
|
|
66
|
-
});
|
|
67
|
-
}, [loadFeatures]);
|
|
68
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(FeatureFlagsContext.Provider, {
|
|
69
|
-
value: {
|
|
70
|
-
features,
|
|
71
|
-
setFeatures
|
|
72
|
-
},
|
|
73
|
-
children
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// src/useFeatureFlag.ts
|
|
78
|
-
var useFeatureFlag = name => {
|
|
79
|
-
const {
|
|
80
|
-
features
|
|
81
|
-
} = React2.useContext(FeatureFlagsContext);
|
|
82
|
-
return features.includes(name);
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
// src/FeatureFlag.tsx
|
|
86
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
87
|
-
var FeatureFlag = ({
|
|
88
|
-
name,
|
|
89
|
-
children,
|
|
90
|
-
fallback = null
|
|
91
|
-
}) => {
|
|
92
|
-
const isEnabled = useFeatureFlag(name);
|
|
93
|
-
if (!isEnabled) {
|
|
94
|
-
return fallback;
|
|
95
|
-
}
|
|
96
|
-
return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, {
|
|
97
|
-
children
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
// src/useUpdateFeatures.ts
|
|
102
|
-
var React3 = __toESM(require("react"));
|
|
103
|
-
var useUpdateFeatures = () => {
|
|
104
|
-
const {
|
|
105
|
-
setFeatures
|
|
106
|
-
} = React3.useContext(FeatureFlagsContext);
|
|
107
|
-
return {
|
|
108
|
-
updateFeatures: setFeatures
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
-
0 && (module.exports = {
|
|
113
|
-
FeatureFlag,
|
|
114
|
-
FeatureFlagsProvider,
|
|
115
|
-
useFeatureFlag,
|
|
116
|
-
useUpdateFeatures
|
|
117
|
-
});
|