memorio 4.6.6 → 4.6.8
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/package.json +3 -2
- package/types/cache.d.ts +1 -1
- package/types/idb.d.ts +1 -1
- package/types/observer.d.ts +1 -1
- package/types/useObserver.d.ts +1 -1
- package/COPYRIGHT.md +0 -6
- package/SECURITY.md +0 -48
- package/SUMMARY.md +0 -28
- package/examples/basic.ts +0 -115
- package/examples/browser-vanilla.html +0 -358
- package/examples/cache.ts +0 -72
- package/examples/idb.ts +0 -109
- package/examples/node-server.ts +0 -308
- package/examples/observer.ts +0 -60
- package/examples/platform.ts +0 -115
- package/examples/react-app.tsx +0 -362
- package/examples/session-advanced.ts +0 -91
- package/examples/state-advanced.ts +0 -89
- package/examples/store-advanced.ts +0 -117
- package/examples/useObserver.tsx +0 -141
- package/index.cjs +0 -1371
- package/index.d.ts +0 -18
- package/index.js +0 -1346
- package/llms.txt +0 -405
- package/markdown/CACHE.md +0 -90
- package/markdown/CHANGELOG.md +0 -161
- package/markdown/DEVTOOLS.md +0 -122
- package/markdown/DISPATCH.md +0 -168
- package/markdown/IDB.md +0 -169
- package/markdown/IMPORT.md +0 -139
- package/markdown/LOGGER.md +0 -147
- package/markdown/OBSERVER.md +0 -200
- package/markdown/PLATFORM.md +0 -265
- package/markdown/SECURITY.md +0 -323
- package/markdown/SESSION.md +0 -154
- package/markdown/STATE.md +0 -153
- package/markdown/STORE.md +0 -164
- package/markdown/USEOBSERVER.md +0 -259
package/examples/useObserver.tsx
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Memorio useObserver Example
|
|
3
|
-
*
|
|
4
|
-
* This example demonstrates the useObserver hook for React.
|
|
5
|
-
* useObserver automatically tracks state changes and triggers re-renders.
|
|
6
|
-
*
|
|
7
|
-
* Note: This example requires React to be present in the environment.
|
|
8
|
-
* Run in a React environment.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import 'memorio'
|
|
12
|
-
|
|
13
|
-
// ============================================
|
|
14
|
-
// BASIC USEOBSERVER
|
|
15
|
-
// ============================================
|
|
16
|
-
|
|
17
|
-
// Example 1: Watch single value
|
|
18
|
-
useObserver(callback, [state.value])
|
|
19
|
-
|
|
20
|
-
function Counter() {
|
|
21
|
-
useObserver(() => {
|
|
22
|
-
console.debug('Count changed:', state.count)
|
|
23
|
-
}, [state.count])
|
|
24
|
-
|
|
25
|
-
return <div>{state.count} </div>
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// ============================================
|
|
29
|
-
// MULTIPLE DEPENDENCIES
|
|
30
|
-
// ============================================
|
|
31
|
-
|
|
32
|
-
// Example 2: Watch multiple values
|
|
33
|
-
function UserProfile() {
|
|
34
|
-
useObserver(() => {
|
|
35
|
-
console.debug('User or theme changed')
|
|
36
|
-
}, [state.user, state.theme])
|
|
37
|
-
|
|
38
|
-
return <div>{state.user.name} </div>
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// ============================================
|
|
42
|
-
// AUTO-DISCOVERY
|
|
43
|
-
// ============================================
|
|
44
|
-
|
|
45
|
-
// Example 3: No dependencies - auto-discovers all state access
|
|
46
|
-
function AutoDiscovery() {
|
|
47
|
-
useObserver(() => {
|
|
48
|
-
// Automatically tracks state.user, state.items, state.count
|
|
49
|
-
console.debug('Changed:', state.user.name, state.items.length, state.count)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
return <div>{state.user.name} </div>
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// ============================================
|
|
56
|
-
// SYNC WITH USESTATE
|
|
57
|
-
// ============================================
|
|
58
|
-
|
|
59
|
-
// Example 4: Sync with useState
|
|
60
|
-
function SyncedComponent() {
|
|
61
|
-
const [localData, setLocalData] = useState(null)
|
|
62
|
-
|
|
63
|
-
useObserver((newValue) => {
|
|
64
|
-
setLocalData(newValue)
|
|
65
|
-
}, [state.data])
|
|
66
|
-
|
|
67
|
-
return <div>{localData} </div>
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// ============================================
|
|
71
|
-
// PRACTICAL EXAMPLE
|
|
72
|
-
// ============================================
|
|
73
|
-
|
|
74
|
-
// Real-world React component example:
|
|
75
|
-
import 'memorio'
|
|
76
|
-
|
|
77
|
-
function TodoApp() {
|
|
78
|
-
// Track todos
|
|
79
|
-
useObserver(() => {
|
|
80
|
-
console.debug('Todos updated:', state.todos)
|
|
81
|
-
// Optionally save to store
|
|
82
|
-
store.set('todos', state.todos)
|
|
83
|
-
}, [state.todos])
|
|
84
|
-
|
|
85
|
-
// Track filter
|
|
86
|
-
useObserver(() => {
|
|
87
|
-
console.debug('Filter changed:', state.filter)
|
|
88
|
-
}, [state.filter])
|
|
89
|
-
|
|
90
|
-
const addTodo = (text) => {
|
|
91
|
-
state.todos = [...(state.todos || []), { text, done: false }]
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const toggleTodo = (index) => {
|
|
95
|
-
const todos = [...state.todos]
|
|
96
|
-
todos[index].done = !todos[index].done
|
|
97
|
-
state.todos = todos
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const filteredTodos = (state.todos || []).filter(t =>
|
|
101
|
-
state.filter === 'all' ||
|
|
102
|
-
(state.filter === 'done' && t.done) ||
|
|
103
|
-
(state.filter === 'todo' && !t.done)
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
return (
|
|
107
|
-
<div>
|
|
108
|
-
<select
|
|
109
|
-
value={state.filter}
|
|
110
|
-
onChange={e => state.filter = e.target.value}
|
|
111
|
-
>
|
|
112
|
-
<option value="all" > All </option>
|
|
113
|
-
< option value="done" > Done </option>
|
|
114
|
-
< option value="todo" > Todo </option>
|
|
115
|
-
</select>
|
|
116
|
-
<ul>
|
|
117
|
-
{
|
|
118
|
-
filteredTodos.map((todo, i) => (
|
|
119
|
-
<li
|
|
120
|
-
key={i}
|
|
121
|
-
onClick={() => toggleTodo(i)}
|
|
122
|
-
style={{ textDecoration: todo.done ? 'line-through' : 'none' }
|
|
123
|
-
}
|
|
124
|
-
>
|
|
125
|
-
{todo.text}
|
|
126
|
-
</li>
|
|
127
|
-
))}
|
|
128
|
-
</ul>
|
|
129
|
-
< input
|
|
130
|
-
onKeyDown={e => {
|
|
131
|
-
if (e.key === 'Enter') {
|
|
132
|
-
addTodo(e.target.value)
|
|
133
|
-
e.target.value = ''
|
|
134
|
-
}
|
|
135
|
-
}}
|
|
136
|
-
/>
|
|
137
|
-
</div>
|
|
138
|
-
)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
console.debug('useObserver example - run in React environment!')
|