scope-state 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.
package/README.md CHANGED
@@ -5,8 +5,6 @@ A tiny reactive state manager with global reach and local clarity. Built for mod
5
5
 
6
6
  Built for developers who hate Redux and love clarity.
7
7
 
8
-
9
-
10
8
  ## Why Scope State?
11
9
 
12
10
  Scope State gives you **global reactive state** with:
@@ -18,19 +16,56 @@ Scope State gives you **global reactive state** with:
18
16
 
19
17
  Just write:
20
18
 
21
- ```ts
22
- import { $, useScope } from 'scope-state';
19
+ ```tsx
20
+ import { useScope, configure } from 'scope-state';
23
21
 
24
- export const ProfilePage = () => {
25
- const name = useScope(() => $.user.name);
26
- return <h1>{name}</h1>
22
+ const $ = configure({
23
+ initialState: {
24
+ counter: {
25
+ count: 0,
26
+ },
27
+ user: {
28
+ name: 'John',
29
+ age: 30
30
+ }
31
+ }
32
+ });
33
+
34
+ const CounterComponent = () => {
35
+
36
+ const count = useScope(() => $.counter.count); // subscribe to only the count
37
+
38
+ const handleCountIncrement = () => {
39
+ // You can mutate the state directly
40
+ $.counter.count++;
41
+ // OR use the updater function
42
+ $.counter.$update("count", (count) => count + 1);
43
+ }
44
+
45
+ const resetCount = () => {
46
+ // use the $set method to replace the entire object
47
+ $.counter.$set({ count: 0 });
48
+ // OR use the $merge method to merge the new properties with the existing ones
49
+ $.counter.$merge({ count: 0 });
50
+ // OR use the $reset method to reset the entire object
51
+ $.counter.$reset();
52
+ // OR literally replace the count with a direct assignment
53
+ $.counter.count = 0;
54
+ }
55
+
56
+ return (
57
+ <div>
58
+ <h1>{count}</h1>
59
+ <button onClick={handleCountIncrement}>+ Increment</button>
60
+ <button onClick={resetCount}>🔄 Reset</button>
61
+ </div>
62
+ )
27
63
  }
28
64
  ```
29
65
 
30
66
  That's it. It tracks dependencies automatically and re-renders only what changed.
31
67
 
32
68
 
33
-
34
69
  ## What Makes It Different?
35
70
 
36
71
  - **Fully reactive** — inspired by proxies, not reducers
@@ -42,7 +77,6 @@ That's it. It tracks dependencies automatically and re-renders only what changed
42
77
  - **Read and set states *independently* —** outside of functional components or custom hooks
43
78
 
44
79
 
45
-
46
80
  ## Getting Started
47
81
 
48
82
  ### Installation