memorio 2.5.3 → 2.6.5
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/CODE_OF_CONDUCT.md +108 -0
- package/CONTRIBUTING.md +108 -0
- package/COPYRIGHT.md +6 -0
- package/README.md +14 -5
- package/SECURITY.md +3 -0
- package/index.cjs +581 -0
- package/index.js +581 -1
- package/package.json +80 -77
- package/types/memorio.d.ts +8 -0
- package/docs/CACHE.md +0 -77
- package/docs/DEVTOOLS.md +0 -120
- package/docs/IDB.md +0 -156
- package/docs/LOGGER.md +0 -145
- package/docs/OBSERVER.md +0 -180
- package/docs/SESSION.md +0 -129
- package/docs/STATE.md +0 -135
- package/docs/STORE.md +0 -137
- package/docs/SUMMARY.md +0 -25
- package/docs/USEOBSERVER.md +0 -156
package/docs/OBSERVER.md
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
# Observer - Memorio
|
|
2
|
-
|
|
3
|
-
> ⚠️ **DEPRECATED**: This function is deprecated and will be removed in future versions. Please use [`useObserver`](USEOBSERVER.md) instead.
|
|
4
|
-
|
|
5
|
-
Observer lets you react to state changes. When a state key changes, your callback function runs.
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install memorio
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
```javascript
|
|
14
|
-
import 'memorio';
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## Quick Examples
|
|
20
|
-
|
|
21
|
-
### Example 1: Basic Usage
|
|
22
|
-
|
|
23
|
-
```javascript
|
|
24
|
-
// Simple observer (DEPRECATED - use useObserver instead)
|
|
25
|
-
console.warn('observer() is deprecated. Please use useObserver() for React or memorio.dispatch for vanilla JS.');
|
|
26
|
-
|
|
27
|
-
observer('state.counter', (newValue) => {
|
|
28
|
-
console.log('Counter is now:', newValue);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
state.counter = 1;
|
|
32
|
-
// Output: "Counter is now: 1"
|
|
33
|
-
|
|
34
|
-
state.counter = 5;
|
|
35
|
-
// Output: "Counter is now: 5"
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
> **Note**: For new projects, use [`useObserver`](USEOBSERVER.md) for React or [`memorio.dispatch`](SUMMARY.md) for vanilla JS.
|
|
39
|
-
|
|
40
|
-
### Example 2: Intermediate
|
|
41
|
-
|
|
42
|
-
```javascript
|
|
43
|
-
// Observer with old value
|
|
44
|
-
observer('state.user', (newValue, oldValue) => {
|
|
45
|
-
console.log(`User changed from ${oldValue?.name} to ${newValue?.name}`);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
state.user = { name: 'Mario' };
|
|
49
|
-
// Output: "User changed from undefined to Mario"
|
|
50
|
-
|
|
51
|
-
state.user = { name: 'Luigi' };
|
|
52
|
-
// Output: "User changed from Mario to Luigi"
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### Example 3: Advanced
|
|
56
|
-
|
|
57
|
-
```javascript
|
|
58
|
-
// Multiple observers
|
|
59
|
-
const obs1 = observer('state.data', handler1);
|
|
60
|
-
const obs2 = observer('state.data', handler2);
|
|
61
|
-
|
|
62
|
-
// List all observers
|
|
63
|
-
console.log(observer.list);
|
|
64
|
-
// Output: [{ name: 'state.data', id: '...' }, ...]
|
|
65
|
-
|
|
66
|
-
// Remove specific observer
|
|
67
|
-
observer.remove('state.data');
|
|
68
|
-
|
|
69
|
-
// Remove all observers
|
|
70
|
-
observer.removeAll();
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
---
|
|
74
|
-
|
|
75
|
-
## API Reference
|
|
76
|
-
|
|
77
|
-
### observer(path, callback)
|
|
78
|
-
|
|
79
|
-
| Parameter | Type | Description |
|
|
80
|
-
|-----------|------|-------------|
|
|
81
|
-
| `path` | `string` | State path to watch (e.g., `'state.counter'`) |
|
|
82
|
-
| `callback` | `function` | Function called on change |
|
|
83
|
-
|
|
84
|
-
### Callback Parameters
|
|
85
|
-
|
|
86
|
-
```javascript
|
|
87
|
-
observer('state.key', (newValue, oldValue) => {
|
|
88
|
-
// newValue: the new value
|
|
89
|
-
// oldValue: the previous value
|
|
90
|
-
});
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
### Properties
|
|
94
|
-
|
|
95
|
-
| Property | Type | Description |
|
|
96
|
-
|----------|------|-------------|
|
|
97
|
-
| `observer.list` | `Array` | Get all active observers |
|
|
98
|
-
|
|
99
|
-
### Methods
|
|
100
|
-
|
|
101
|
-
| Method | Parameters | Description |
|
|
102
|
-
|--------|------------|-------------|
|
|
103
|
-
| `observer.remove(name)` | `string` | Remove observer for specific path |
|
|
104
|
-
| `observer.removeAll()` | none | Remove all observers |
|
|
105
|
-
|
|
106
|
-
---
|
|
107
|
-
|
|
108
|
-
## React Integration
|
|
109
|
-
|
|
110
|
-
### With useState
|
|
111
|
-
|
|
112
|
-
```javascript
|
|
113
|
-
const [count, setCount] = useState(0);
|
|
114
|
-
|
|
115
|
-
observer('state.counter', () => {
|
|
116
|
-
setCount(state.counter);
|
|
117
|
-
});
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
### With useEffect
|
|
121
|
-
|
|
122
|
-
```javascript
|
|
123
|
-
useEffect(() => {
|
|
124
|
-
const handleChange = (newVal) => {
|
|
125
|
-
console.log('Changed:', newVal);
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
observer('state.data', handleChange);
|
|
129
|
-
|
|
130
|
-
// Cleanup
|
|
131
|
-
return () => observer.remove('state.data');
|
|
132
|
-
}, []);
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
---
|
|
136
|
-
|
|
137
|
-
## How It Works
|
|
138
|
-
|
|
139
|
-
Observer subscribes to state changes via the Proxy's set trap. When `state.key = value` is called:
|
|
140
|
-
1. The Proxy intercepts the set
|
|
141
|
-
2. Fires all callbacks registered for that path
|
|
142
|
-
3. Callbacks receive newValue and oldValue
|
|
143
|
-
|
|
144
|
-
---
|
|
145
|
-
|
|
146
|
-
## Best Practices
|
|
147
|
-
|
|
148
|
-
1. Clean up observers in React `useEffect` return
|
|
149
|
-
2. Use specific paths: `'state.user.name'` not `'state'`
|
|
150
|
-
3. Remove observers when components unmount
|
|
151
|
-
4. Use `observer.removeAll()` on page navigation
|
|
152
|
-
|
|
153
|
-
---
|
|
154
|
-
|
|
155
|
-
## Common Patterns
|
|
156
|
-
|
|
157
|
-
### Form Validation
|
|
158
|
-
|
|
159
|
-
```javascript
|
|
160
|
-
observer('state.form.email', (email) => {
|
|
161
|
-
const isValid = email.includes('@');
|
|
162
|
-
state.form.isValid = isValid;
|
|
163
|
-
});
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
### Analytics
|
|
167
|
-
|
|
168
|
-
```javascript
|
|
169
|
-
observer('state.page', (page) => {
|
|
170
|
-
analytics.track('page_view', { page });
|
|
171
|
-
});
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
### Auto-save
|
|
175
|
-
|
|
176
|
-
```javascript
|
|
177
|
-
observer('state.draft', (content) => {
|
|
178
|
-
store.set('autosave', content);
|
|
179
|
-
});
|
|
180
|
-
```
|
package/docs/SESSION.md
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
# Session - Memorio
|
|
2
|
-
|
|
3
|
-
Session provides temporary storage using browser sessionStorage. Data persists until the tab or window is closed.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install memorio
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
```javascript
|
|
12
|
-
import 'memorio';
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
## Quick Examples
|
|
18
|
-
|
|
19
|
-
### Example 1: Basic Usage
|
|
20
|
-
|
|
21
|
-
```javascript
|
|
22
|
-
// Save session data
|
|
23
|
-
session.set('token', 'abc123');
|
|
24
|
-
session.set('userId', 42);
|
|
25
|
-
|
|
26
|
-
// Read session data
|
|
27
|
-
console.log(session.get('token')); // "abc123"
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### Example 2: Intermediate
|
|
31
|
-
|
|
32
|
-
```javascript
|
|
33
|
-
// Store objects
|
|
34
|
-
session.set('user', { name: 'Mario', role: 'admin' });
|
|
35
|
-
|
|
36
|
-
// Remove specific item
|
|
37
|
-
session.remove('token');
|
|
38
|
-
|
|
39
|
-
// Clear all session data
|
|
40
|
-
session.removeAll();
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### Example 3: Advanced
|
|
44
|
-
|
|
45
|
-
```javascript
|
|
46
|
-
// Check if session has data
|
|
47
|
-
if (session.get('authToken')) {
|
|
48
|
-
// User is logged in
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Get storage quota (returns Promise<[usage, quota]> in KB)
|
|
52
|
-
const [used, total] = await session.quota();
|
|
53
|
-
console.log(`Using ${used} out of ${total} KB`);
|
|
54
|
-
|
|
55
|
-
// Get total size in characters
|
|
56
|
-
const size = session.size();
|
|
57
|
-
console.log(`${size} bytes`);
|
|
58
|
-
|
|
59
|
-
// Handle session expiry
|
|
60
|
-
window.addEventListener('storage', (e) => {
|
|
61
|
-
if (e.key === 'session' && !e.newValue) {
|
|
62
|
-
// Session cleared
|
|
63
|
-
redirectToLogin();
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
---
|
|
69
|
-
|
|
70
|
-
## API Reference
|
|
71
|
-
|
|
72
|
-
### Methods
|
|
73
|
-
|
|
74
|
-
| Method | Parameters | Returns | Description |
|
|
75
|
-
|--------|------------|---------|-------------|
|
|
76
|
-
| `session.get(name)` | `name: string` | `any` | Get value from session |
|
|
77
|
-
| `session.set(name, value)` | `name: string, value: any` | `void` | Save value to session |
|
|
78
|
-
| `session.remove(name)` | `name: string` | `boolean` | Remove single item |
|
|
79
|
-
| `session.delete(name)` | `name: string` | `boolean` | Alias for remove |
|
|
80
|
-
| `session.removeAll()` | `none` | `boolean` | Clear all session data |
|
|
81
|
-
| `session.clearAll()` | `none` | `boolean` | Alias for removeAll |
|
|
82
|
-
| `session.size()` | `none` | `number` | Get total size in characters |
|
|
83
|
-
| `session.quota()` | `none` | `Promise<[number, number]>` | Get storage usage/quota in KB |
|
|
84
|
-
|
|
85
|
-
---
|
|
86
|
-
|
|
87
|
-
## Store vs Session
|
|
88
|
-
|
|
89
|
-
| Feature | Store | Session |
|
|
90
|
-
|---------|-------|---------|
|
|
91
|
-
| Storage | localStorage | sessionStorage |
|
|
92
|
-
| Lifetime | Forever | Until tab closes |
|
|
93
|
-
| Use case | User preferences | Temporary auth |
|
|
94
|
-
| Shared across tabs | Yes | No |
|
|
95
|
-
|
|
96
|
-
---
|
|
97
|
-
|
|
98
|
-
## Best Practices
|
|
99
|
-
|
|
100
|
-
1. Use for auth tokens: `session.set('token', jwt)`
|
|
101
|
-
2. Clear on logout: `session.removeAll()`
|
|
102
|
-
3. Don't use for persistent data
|
|
103
|
-
4. Check for null: `session.get('key') || defaultValue`
|
|
104
|
-
|
|
105
|
-
---
|
|
106
|
-
|
|
107
|
-
## Common Use Cases
|
|
108
|
-
|
|
109
|
-
### Authentication
|
|
110
|
-
|
|
111
|
-
```javascript
|
|
112
|
-
// Login
|
|
113
|
-
session.set('authToken', response.token);
|
|
114
|
-
session.set('user', response.user);
|
|
115
|
-
|
|
116
|
-
// Logout
|
|
117
|
-
session.removeAll();
|
|
118
|
-
router.push('/login');
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### Form Progress
|
|
122
|
-
|
|
123
|
-
```javascript
|
|
124
|
-
// Save form draft
|
|
125
|
-
session.set('formDraft', formData);
|
|
126
|
-
|
|
127
|
-
// Restore on page refresh
|
|
128
|
-
const draft = session.get('formDraft');
|
|
129
|
-
if (draft) restoreForm(draft);
|
package/docs/STATE.md
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
# State - Memorio
|
|
2
|
-
|
|
3
|
-
State is a reactive global state manager using JavaScript Proxies. It's simple, powerful, and requires no setup. Data persists only in memory during the session.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install memorio
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
```javascript
|
|
12
|
-
import 'memorio';
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
That's it. `state` is now global.
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## Quick Examples
|
|
20
|
-
|
|
21
|
-
### Example 1: Basic Usage
|
|
22
|
-
|
|
23
|
-
```javascript
|
|
24
|
-
// Set a value
|
|
25
|
-
state.name = 'Mario';
|
|
26
|
-
state.age = 25;
|
|
27
|
-
|
|
28
|
-
// Get a value
|
|
29
|
-
console.log(state.name); // "Mario"
|
|
30
|
-
|
|
31
|
-
// Simple object
|
|
32
|
-
state.user = { name: 'Luigi', level: 1 };
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### Example 2: Intermediate
|
|
36
|
-
|
|
37
|
-
```javascript
|
|
38
|
-
// Array operations
|
|
39
|
-
state.items = [1, 2, 3];
|
|
40
|
-
state.items.push(4);
|
|
41
|
-
console.log(state.items); // [1, 2, 3, 4]
|
|
42
|
-
|
|
43
|
-
// Nested objects
|
|
44
|
-
state.config = { theme: 'dark', lang: 'en' };
|
|
45
|
-
state.config.theme = 'light';
|
|
46
|
-
|
|
47
|
-
// List all states
|
|
48
|
-
console.log(state.list);
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Example 3: Advanced
|
|
52
|
-
|
|
53
|
-
```javascript
|
|
54
|
-
// Lock state to prevent modifications
|
|
55
|
-
state.frozenConfig = { maxUsers: 100 };
|
|
56
|
-
state.frozenConfig.lock();
|
|
57
|
-
// Now state.frozenConfig cannot be modified
|
|
58
|
-
|
|
59
|
-
// Path tracking
|
|
60
|
-
const path = state.user.path;
|
|
61
|
-
console.log(path.name); // "user"
|
|
62
|
-
console.log(path.profile.name); // "user.profile"
|
|
63
|
-
|
|
64
|
-
// Get full path as string
|
|
65
|
-
console.log(state.user.__path); // "state.user"
|
|
66
|
-
|
|
67
|
-
// Protected keys (internal use)
|
|
68
|
-
console.log(protect); // Array of protected keys
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
---
|
|
72
|
-
|
|
73
|
-
## API Reference
|
|
74
|
-
|
|
75
|
-
### Properties
|
|
76
|
-
|
|
77
|
-
| Property | Type | Description |
|
|
78
|
-
|----------|------|-------------|
|
|
79
|
-
| `state.list` | Array | Get all current state keys (deep copy) |
|
|
80
|
-
| `state.path` | Object | Get path tracker for current location |
|
|
81
|
-
| `state.__path` | string | Get full path as string |
|
|
82
|
-
|
|
83
|
-
### Methods
|
|
84
|
-
|
|
85
|
-
| Method | Parameters | Description |
|
|
86
|
-
|--------|------------|-------------|
|
|
87
|
-
| `state.remove(key)` | `key: string` | Remove a specific state |
|
|
88
|
-
| `state.removeAll()` | none | Clear all states |
|
|
89
|
-
|
|
90
|
-
### Lock
|
|
91
|
-
|
|
92
|
-
```javascript
|
|
93
|
-
// Lock an object or array
|
|
94
|
-
state.myArray = [1, 2, 3];
|
|
95
|
-
state.myArray.lock();
|
|
96
|
-
|
|
97
|
-
// Now any modification will fail
|
|
98
|
-
state.myArray.push(4); // Error: state 'myArray' is locked
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
---
|
|
102
|
-
|
|
103
|
-
## How It Works
|
|
104
|
-
|
|
105
|
-
Memorio uses JavaScript `Proxy` to intercept get/set operations on the global `state` object. This allows:
|
|
106
|
-
|
|
107
|
-
1. **Reactivity** - Any change can trigger observers
|
|
108
|
-
2. **Nested objects** - Deep path tracking
|
|
109
|
-
3. **Type safety** - Full TypeScript support
|
|
110
|
-
|
|
111
|
-
---
|
|
112
|
-
|
|
113
|
-
## Best Practices
|
|
114
|
-
|
|
115
|
-
1. Use descriptive keys: `state.userProfile` not `state.up`
|
|
116
|
-
2. Group related data: `state.cart.items` not `state.cartItems`
|
|
117
|
-
3. Lock static config: `state.appConfig.lock()`
|
|
118
|
-
4. Clean up on logout: `state.removeAll()`
|
|
119
|
-
5. Use path tracking for debugging: `state.myData.__path`
|
|
120
|
-
|
|
121
|
-
---
|
|
122
|
-
|
|
123
|
-
## Common Errors
|
|
124
|
-
|
|
125
|
-
```javascript
|
|
126
|
-
// Error: protected key
|
|
127
|
-
state._internal = 'value';
|
|
128
|
-
// Output: "key _internal is protected"
|
|
129
|
-
|
|
130
|
-
// Error: locked state
|
|
131
|
-
state.locked = { x: 1 };
|
|
132
|
-
state.locked.lock();
|
|
133
|
-
state.locked.x = 2;
|
|
134
|
-
// Output: "Error: state 'locked' is locked"
|
|
135
|
-
```
|
package/docs/STORE.md
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
# Store - Memorio
|
|
2
|
-
|
|
3
|
-
Store provides persistent localStorage management with a simple API. Data survives page refreshes and browser restarts.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install memorio
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
```javascript
|
|
12
|
-
import 'memorio';
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
## Quick Examples
|
|
18
|
-
|
|
19
|
-
### Example 1: Basic Usage
|
|
20
|
-
|
|
21
|
-
```javascript
|
|
22
|
-
// Save data
|
|
23
|
-
store.set('username', 'Mario');
|
|
24
|
-
store.set('score', 1500);
|
|
25
|
-
|
|
26
|
-
// Read data
|
|
27
|
-
console.log(store.get('username')); // "Mario"
|
|
28
|
-
console.log(store.get('score')); // 1500
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
### Example 2: Intermediate
|
|
32
|
-
|
|
33
|
-
```javascript
|
|
34
|
-
// Store objects
|
|
35
|
-
store.set('user', { name: 'Luigi', level: 5 });
|
|
36
|
-
const user = store.get('user');
|
|
37
|
-
console.log(user.name); // "Luigi"
|
|
38
|
-
|
|
39
|
-
// Remove single item
|
|
40
|
-
store.remove('username');
|
|
41
|
-
|
|
42
|
-
// Check size
|
|
43
|
-
const totalSize = store.size();
|
|
44
|
-
console.log(`${totalSize} bytes`);
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Example 3: Advanced
|
|
48
|
-
|
|
49
|
-
```javascript
|
|
50
|
-
// Get storage quota (returns Promise<[usage, quota]> in KB)
|
|
51
|
-
const [used, total] = await store.quota();
|
|
52
|
-
console.log(`Using ${used} out of ${total} KB`);
|
|
53
|
-
|
|
54
|
-
// Get total size in characters
|
|
55
|
-
const size = store.size();
|
|
56
|
-
console.log(`${size} bytes`);
|
|
57
|
-
|
|
58
|
-
// Clear all data
|
|
59
|
-
store.removeAll();
|
|
60
|
-
// or use alias
|
|
61
|
-
store.clearAll();
|
|
62
|
-
|
|
63
|
-
// Handle errors gracefully
|
|
64
|
-
try {
|
|
65
|
-
store.set('largeData', hugeObject);
|
|
66
|
-
} catch (err) {
|
|
67
|
-
console.error('Storage full:', err);
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
---
|
|
72
|
-
|
|
73
|
-
## API Reference
|
|
74
|
-
|
|
75
|
-
### Methods
|
|
76
|
-
|
|
77
|
-
| Method | Parameters | Returns | Description |
|
|
78
|
-
|--------|------------|---------|-------------|
|
|
79
|
-
| `store.get(name)` | `name: string` | `any` | Get value from storage |
|
|
80
|
-
| `store.set(name, value)` | `name: string, value: any` | `void` | Save value to storage |
|
|
81
|
-
| `store.remove(name)` | `name: string` | `boolean` | Remove single item |
|
|
82
|
-
| `store.delete(name)` | `name: string` | `boolean` | Alias for remove |
|
|
83
|
-
| `store.removeAll()` | none | `boolean` | Clear all storage |
|
|
84
|
-
| `store.clearAll()` | none | `boolean` | Alias for removeAll |
|
|
85
|
-
| `store.size()` | none | `number` | Get total size in characters |
|
|
86
|
-
| `store.quota()` | none | `Promise<[number, number]>` | Get storage usage/quota in KB |
|
|
87
|
-
|
|
88
|
-
### Supported Types
|
|
89
|
-
|
|
90
|
-
```javascript
|
|
91
|
-
// All JSON-serializable types work
|
|
92
|
-
store.set('string', 'hello');
|
|
93
|
-
store.set('number', 42);
|
|
94
|
-
store.set('boolean', true);
|
|
95
|
-
store.set('array', [1, 2, 3]);
|
|
96
|
-
store.set('object', { key: 'value' });
|
|
97
|
-
store.set('null', null);
|
|
98
|
-
store.set('undefined', null); // converted to null
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
### Not Supported
|
|
102
|
-
|
|
103
|
-
```javascript
|
|
104
|
-
// Functions will log an error
|
|
105
|
-
store.set('myFunc', () => {});
|
|
106
|
-
// Output: "It's not secure to store functions."
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
---
|
|
110
|
-
|
|
111
|
-
## How It Works
|
|
112
|
-
|
|
113
|
-
Store wraps the browser's `localStorage` API with:
|
|
114
|
-
|
|
115
|
-
- Automatic JSON serialization/deserialization
|
|
116
|
-
- Error handling for parse failures
|
|
117
|
-
- Size calculation
|
|
118
|
-
- Quota monitoring
|
|
119
|
-
|
|
120
|
-
---
|
|
121
|
-
|
|
122
|
-
## Storage Limits
|
|
123
|
-
|
|
124
|
-
- **Chrome/Safari**: ~5-10 MB
|
|
125
|
-
- **Firefox**: ~10 MB
|
|
126
|
-
- **Edge**: ~5-10 MB
|
|
127
|
-
|
|
128
|
-
Use `store.quota()` to monitor usage.
|
|
129
|
-
|
|
130
|
-
---
|
|
131
|
-
|
|
132
|
-
## Best Practices
|
|
133
|
-
|
|
134
|
-
1. Prefix keys: `store.set('app_username', '...')`
|
|
135
|
-
2. Check before set: `if (store.get('key')) { ... }`
|
|
136
|
-
3. Handle quota: Try/catch around large data
|
|
137
|
-
4. Clean up: `store.removeAll()` on logout
|
package/docs/SUMMARY.md
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# Table of contents
|
|
2
|
-
|
|
3
|
-
* [README](../README.md)
|
|
4
|
-
|
|
5
|
-
## Core Modules
|
|
6
|
-
|
|
7
|
-
* [State](STATE.md) - Reactive global state management
|
|
8
|
-
* [Observer](OBSERVER.md) - ⚠️ Deprecated (use useObserver)
|
|
9
|
-
* [useObserver](USEOBSERVER.md) - React hook for state observation
|
|
10
|
-
* [Cache](CACHE.md) - In-memory caching (lost on refresh)
|
|
11
|
-
* [Store](STORE.md) - Persistent localStorage management
|
|
12
|
-
* [Session](SESSION.md) - Temporary sessionStorage management
|
|
13
|
-
* [IDB](IDB.md) - IndexedDB for large data storage
|
|
14
|
-
|
|
15
|
-
## Additional Resources
|
|
16
|
-
|
|
17
|
-
* [License](../LICENSE.md)
|
|
18
|
-
* [Contributing](../CONTRIBUTING.md)
|
|
19
|
-
* [Code of Conduct](../CODE_OF_CONDUCT.md)
|
|
20
|
-
* [Security](../SECURITY.md)
|
|
21
|
-
|
|
22
|
-
## Changelog
|
|
23
|
-
|
|
24
|
-
* [Changelog](../CHANGELOG.md)
|
|
25
|
-
* [History](../HISTORY.md)
|