@pulse-js/react 0.1.9 → 0.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/dist/devtools.cjs +7 -2
- package/dist/devtools.js +7 -1
- package/dist/index.cjs +14 -2
- package/dist/index.d.cts +24 -2
- package/dist/index.d.ts +24 -2
- package/dist/index.js +12 -1
- package/package.json +3 -3
package/dist/devtools.cjs
CHANGED
|
@@ -25,8 +25,13 @@ __export(devtools_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(devtools_exports);
|
|
26
26
|
var import_tools = require("@pulse-js/tools");
|
|
27
27
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
28
|
-
var
|
|
29
|
-
|
|
28
|
+
var isDev = (() => {
|
|
29
|
+
try {
|
|
30
|
+
return process.env.NODE_ENV === "development";
|
|
31
|
+
} catch (e) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
})();
|
|
30
35
|
if (isDev && typeof document !== "undefined") {
|
|
31
36
|
if (!document.querySelector("pulse-inspector")) {
|
|
32
37
|
const inspector = document.createElement("pulse-inspector");
|
package/dist/devtools.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
// src/devtools.tsx
|
|
2
2
|
import "@pulse-js/tools";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
-
var isDev =
|
|
4
|
+
var isDev = (() => {
|
|
5
|
+
try {
|
|
6
|
+
return process.env.NODE_ENV === "development";
|
|
7
|
+
} catch (e) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
})();
|
|
5
11
|
if (isDev && typeof document !== "undefined") {
|
|
6
12
|
if (!document.querySelector("pulse-inspector")) {
|
|
7
13
|
const inspector = document.createElement("pulse-inspector");
|
package/dist/index.cjs
CHANGED
|
@@ -22,7 +22,8 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
formatReason: () => formatReason,
|
|
24
24
|
useGuard: () => useGuard,
|
|
25
|
-
usePulse: () => usePulse
|
|
25
|
+
usePulse: () => usePulse,
|
|
26
|
+
usePulseObject: () => usePulseObject
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(index_exports);
|
|
28
29
|
var import_react = require("react");
|
|
@@ -72,6 +73,16 @@ function useGuard(guard, options) {
|
|
|
72
73
|
}
|
|
73
74
|
return state;
|
|
74
75
|
}
|
|
76
|
+
function usePulseObject(pulseObj) {
|
|
77
|
+
if (isServer) {
|
|
78
|
+
return pulseObj.$snapshot();
|
|
79
|
+
}
|
|
80
|
+
return (0, import_react.useSyncExternalStore)(
|
|
81
|
+
pulseObj.$subscribe,
|
|
82
|
+
() => pulseObj,
|
|
83
|
+
() => pulseObj.$snapshot()
|
|
84
|
+
);
|
|
85
|
+
}
|
|
75
86
|
function formatReason(reason) {
|
|
76
87
|
if (!reason) return "";
|
|
77
88
|
if (typeof reason === "string") return reason;
|
|
@@ -81,5 +92,6 @@ function formatReason(reason) {
|
|
|
81
92
|
0 && (module.exports = {
|
|
82
93
|
formatReason,
|
|
83
94
|
useGuard,
|
|
84
|
-
usePulse
|
|
95
|
+
usePulse,
|
|
96
|
+
usePulseObject
|
|
85
97
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Source, Guard, GuardState } from '@pulse-js/core';
|
|
1
|
+
import { Source, Guard, GuardState, PulseObject } from '@pulse-js/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Hook to consume a Pulse Unit (Source or Guard) in a React component.
|
|
@@ -44,6 +44,28 @@ interface UseGuardOptions {
|
|
|
44
44
|
* const { ok, value, reason } = useGuard(authGuard, { suspend: true });
|
|
45
45
|
*/
|
|
46
46
|
declare function useGuard<T>(guard: Guard<T>, options?: UseGuardOptions): GuardState<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Hook for Pulse Objects (v2 Proxy-based reactive objects).
|
|
49
|
+
*
|
|
50
|
+
* Returns a snapshot of the reactive object that triggers re-renders
|
|
51
|
+
* when any property changes.
|
|
52
|
+
*
|
|
53
|
+
* @template T The type of the Pulse object.
|
|
54
|
+
* @param pulseObj A Pulse object created with pulse().
|
|
55
|
+
* @returns The current state of the object.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```tsx
|
|
59
|
+
* const auth = pulse({ user: null, loading: false });
|
|
60
|
+
*
|
|
61
|
+
* function Profile() {
|
|
62
|
+
* const state = usePulseObject(auth);
|
|
63
|
+
* if (state.loading) return <Spinner />;
|
|
64
|
+
* return <div>{state.user?.name}</div>;
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
declare function usePulseObject<T extends object>(pulseObj: PulseObject<T>): T;
|
|
47
69
|
/**
|
|
48
70
|
* Formats a guard reason for display in React components.
|
|
49
71
|
* Handles both string reasons and GuardReason objects.
|
|
@@ -61,4 +83,4 @@ declare function formatReason(reason: string | {
|
|
|
61
83
|
toString(): string;
|
|
62
84
|
} | undefined): string;
|
|
63
85
|
|
|
64
|
-
export { type UseGuardOptions, formatReason, useGuard, usePulse };
|
|
86
|
+
export { type UseGuardOptions, formatReason, useGuard, usePulse, usePulseObject };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Source, Guard, GuardState } from '@pulse-js/core';
|
|
1
|
+
import { Source, Guard, GuardState, PulseObject } from '@pulse-js/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Hook to consume a Pulse Unit (Source or Guard) in a React component.
|
|
@@ -44,6 +44,28 @@ interface UseGuardOptions {
|
|
|
44
44
|
* const { ok, value, reason } = useGuard(authGuard, { suspend: true });
|
|
45
45
|
*/
|
|
46
46
|
declare function useGuard<T>(guard: Guard<T>, options?: UseGuardOptions): GuardState<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Hook for Pulse Objects (v2 Proxy-based reactive objects).
|
|
49
|
+
*
|
|
50
|
+
* Returns a snapshot of the reactive object that triggers re-renders
|
|
51
|
+
* when any property changes.
|
|
52
|
+
*
|
|
53
|
+
* @template T The type of the Pulse object.
|
|
54
|
+
* @param pulseObj A Pulse object created with pulse().
|
|
55
|
+
* @returns The current state of the object.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```tsx
|
|
59
|
+
* const auth = pulse({ user: null, loading: false });
|
|
60
|
+
*
|
|
61
|
+
* function Profile() {
|
|
62
|
+
* const state = usePulseObject(auth);
|
|
63
|
+
* if (state.loading) return <Spinner />;
|
|
64
|
+
* return <div>{state.user?.name}</div>;
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
declare function usePulseObject<T extends object>(pulseObj: PulseObject<T>): T;
|
|
47
69
|
/**
|
|
48
70
|
* Formats a guard reason for display in React components.
|
|
49
71
|
* Handles both string reasons and GuardReason objects.
|
|
@@ -61,4 +83,4 @@ declare function formatReason(reason: string | {
|
|
|
61
83
|
toString(): string;
|
|
62
84
|
} | undefined): string;
|
|
63
85
|
|
|
64
|
-
export { type UseGuardOptions, formatReason, useGuard, usePulse };
|
|
86
|
+
export { type UseGuardOptions, formatReason, useGuard, usePulse, usePulseObject };
|
package/dist/index.js
CHANGED
|
@@ -46,6 +46,16 @@ function useGuard(guard, options) {
|
|
|
46
46
|
}
|
|
47
47
|
return state;
|
|
48
48
|
}
|
|
49
|
+
function usePulseObject(pulseObj) {
|
|
50
|
+
if (isServer) {
|
|
51
|
+
return pulseObj.$snapshot();
|
|
52
|
+
}
|
|
53
|
+
return useSyncExternalStore(
|
|
54
|
+
pulseObj.$subscribe,
|
|
55
|
+
() => pulseObj,
|
|
56
|
+
() => pulseObj.$snapshot()
|
|
57
|
+
);
|
|
58
|
+
}
|
|
49
59
|
function formatReason(reason) {
|
|
50
60
|
if (!reason) return "";
|
|
51
61
|
if (typeof reason === "string") return reason;
|
|
@@ -54,5 +64,6 @@ function formatReason(reason) {
|
|
|
54
64
|
export {
|
|
55
65
|
formatReason,
|
|
56
66
|
useGuard,
|
|
57
|
-
usePulse
|
|
67
|
+
usePulse,
|
|
68
|
+
usePulseObject
|
|
58
69
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pulse-js/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"react": "^19.2.3"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@pulse-js/core": "^0.
|
|
32
|
-
"@pulse-js/tools": "^0.
|
|
31
|
+
"@pulse-js/core": "^0.3.0",
|
|
32
|
+
"@pulse-js/tools": "^0.3.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/bun": "latest",
|