@pulse-js/react 0.1.0 → 0.1.2

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.
Files changed (2) hide show
  1. package/README.md +79 -79
  2. package/package.json +7 -2
package/README.md CHANGED
@@ -1,79 +1,79 @@
1
- # @pulse-js/react
2
-
3
- React integration for the Pulse reactivity ecosystem. Provides hooks and utilities to consume Pulse Sources and Guards within React components efficiently.
4
-
5
- ## Features
6
-
7
- - **Concurrent Mode Compatible**: Built with `useSyncExternalStore` for compatibility with React 18+ concurrent features.
8
- - **Zero Polling**: Logic driven by direct subscriptions to the Pulse core, ensuring updates happen exactly when state changes.
9
- - **Type Safety**: Full TypeScript support for inferred types from Sources and Guards.
10
-
11
- ## Installation
12
-
13
- ```bash
14
- npm install @pulse-js/react @pulse-js/core
15
- ```
16
-
17
- ## Usage
18
-
19
- The primary API is the `usePulse` hook. It adapts automatically depending on whether you pass it a Source or a Guard.
20
-
21
- ### Using Sources
22
-
23
- When used with a **Source**, `usePulse` returns the current value and triggers a re-render whenever that value updates.
24
-
25
- ```jsx
26
- import { source } from "@pulse-js/core";
27
- import { usePulse } from "@pulse-js/react";
28
-
29
- const counter = source(0);
30
-
31
- function Counter() {
32
- const value = usePulse(counter);
33
-
34
- return (
35
- <button onClick={() => counter.update((n) => n + 1)}>Count: {value}</button>
36
- );
37
- }
38
- ```
39
-
40
- ### Using Guards
41
-
42
- When used with a **Guard**, `usePulse` returns the complete `GuardState` object, which includes `status`, `value`, and `reason`. This allows you to handle loading and error states declaratively.
43
-
44
- ```tsx
45
- import { guard } from "@pulse-js/core";
46
- import { usePulse } from "@pulse-js/react";
47
-
48
- const isAuthorized = guard("auth-check", async () => {
49
- // ... async logic
50
- });
51
-
52
- function ProtectedRoute() {
53
- const { status, reason } = usePulse(isAuthorized);
54
-
55
- if (status === "pending") {
56
- return <LoadingSpinner />;
57
- }
58
-
59
- if (status === "fail") {
60
- return <AccessDenied message={reason} />;
61
- }
62
-
63
- return <AdminDashboard />;
64
- }
65
- ```
66
-
67
- ## API
68
-
69
- ### `usePulse<T>(unit: PulseUnit<T>): T | GuardState<T>`
70
-
71
- - **Arguments**:
72
- - `unit`: A Pulse Source or Guard.
73
- - **Returns**:
74
- - For Sources: The inner value `T`.
75
- - For Guards: An object `{ status: 'ok' | 'fail' | 'pending', value?: T, reason?: string }`.
76
-
77
- ## Performance
78
-
79
- `@pulse-js/react` leverages modern React 18 patterns to ensure optimal performance. It avoids unnecessary re-renders by strictly tracking object references and using the `useSyncExternalStore` API to integrate with React's scheduling system.
1
+ # @pulse-js/react
2
+
3
+ React integration for the Pulse reactivity ecosystem. Provides hooks and utilities to consume Pulse Sources and Guards within React components efficiently.
4
+
5
+ ## Features
6
+
7
+ - **Concurrent Mode Compatible**: Built with `useSyncExternalStore` for compatibility with React 18+ concurrent features.
8
+ - **Zero Polling**: Logic driven by direct subscriptions to the Pulse core, ensuring updates happen exactly when state changes.
9
+ - **Type Safety**: Full TypeScript support for inferred types from Sources and Guards.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install @pulse-js/react @pulse-js/core
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ The primary API is the `usePulse` hook. It adapts automatically depending on whether you pass it a Source or a Guard.
20
+
21
+ ### Using Sources
22
+
23
+ When used with a **Source**, `usePulse` returns the current value and triggers a re-render whenever that value updates.
24
+
25
+ ```jsx
26
+ import { source } from "@pulse-js/core";
27
+ import { usePulse } from "@pulse-js/react";
28
+
29
+ const counter = source(0);
30
+
31
+ function Counter() {
32
+ const value = usePulse(counter);
33
+
34
+ return (
35
+ <button onClick={() => counter.update((n) => n + 1)}>Count: {value}</button>
36
+ );
37
+ }
38
+ ```
39
+
40
+ ### Using Guards
41
+
42
+ When used with a **Guard**, `usePulse` returns the complete `GuardState` object, which includes `status`, `value`, and `reason`. This allows you to handle loading and error states declaratively.
43
+
44
+ ```tsx
45
+ import { guard } from "@pulse-js/core";
46
+ import { usePulse } from "@pulse-js/react";
47
+
48
+ const isAuthorized = guard("auth-check", async () => {
49
+ // ... async logic
50
+ });
51
+
52
+ function ProtectedRoute() {
53
+ const { status, reason } = usePulse(isAuthorized);
54
+
55
+ if (status === "pending") {
56
+ return <LoadingSpinner />;
57
+ }
58
+
59
+ if (status === "fail") {
60
+ return <AccessDenied message={reason} />;
61
+ }
62
+
63
+ return <AdminDashboard />;
64
+ }
65
+ ```
66
+
67
+ ## API
68
+
69
+ ### `usePulse<T>(unit: PulseUnit<T>): T | GuardState<T>`
70
+
71
+ - **Arguments**:
72
+ - `unit`: A Pulse Source or Guard.
73
+ - **Returns**:
74
+ - For Sources: The inner value `T`.
75
+ - For Guards: An object `{ status: 'ok' | 'fail' | 'pending', value?: T, reason?: string }`.
76
+
77
+ ## Performance
78
+
79
+ `@pulse-js/react` leverages modern React 18 patterns to ensure optimal performance. It avoids unnecessary re-renders by strictly tracking object references and using the `useSyncExternalStore` API to integrate with React's scheduling system.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pulse-js/react",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -16,6 +16,11 @@
16
16
  "react": "^19.2.3"
17
17
  },
18
18
  "dependencies": {
19
- "@pulse-js/core": "^0.1.0"
19
+ "@pulse-js/core": "^0.1.5"
20
+ },
21
+ "devDependencies": {
22
+ "@types/bun": "latest",
23
+ "@types/react": "^19.2.8",
24
+ "@types/react-dom": "^19.2.3"
20
25
  }
21
26
  }