Skip to content

Commit 8f5f6f5

Browse files
Merge pull request #3 from HichemTab-tech/fix-logs
Fix logs and put dev mode manipulation in exported configuration
2 parents cc42ca4 + 5d386bb commit 8f5f6f5

File tree

7 files changed

+21
-4
lines changed

7 files changed

+21
-4
lines changed

demo/vite.config.demo.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ export default defineConfig({
1919
plugins: [
2020
react(),
2121
],
22+
define: {
23+
__REACT_SHARED_STATES_DEV__: process.env.NODE_ENV === 'development' ? 'true' : 'false',
24+
}
2225
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-shared-states",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"type": "module",
55
"description": "Global state made as simple as useState, with zero config, built-in async caching, and automatic scoping.",
66
"keywords": [

src/config/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export let isDevMode = false;
2+
3+
// noinspection JSUnusedGlobalSymbols
4+
export const setDevMode = (value: boolean) => {
5+
isDevMode = value;
6+
};

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from "./context";
22
export * from "./hooks";
3-
export * from "./types";
3+
export * from "./types";
4+
export * from "./config";

src/lib/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type {NonEmptyString} from "../types";
2+
import {isDevMode} from "../config";
23

34
export const log = (...args: any[]) => {
4-
if (process.env.NODE_ENV !== 'development') return;
5+
if ((typeof __REACT_SHARED_STATES_DEV__ === "undefined" || !__REACT_SHARED_STATES_DEV__) && !isDevMode) return;
56
console.log(
67
'%c[react-shared-states]',
78
'color: #007acc; font-weight: bold',

src/vite-env.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/// <reference types="vite/client" />
2+
3+
declare const __REACT_SHARED_STATES_DEV__ : boolean;

vite.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@ export default defineConfig({
4141
exclude: ['node_modules', 'dist'], // Exclude unnecessary files
4242
})
4343

44-
]
44+
],
45+
define: {
46+
__REACT_SHARED_STATES_DEV__: process.env.NODE_ENV === 'development' ? 'true' : 'false',
47+
}
4548
});

0 commit comments

Comments
 (0)