-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tsx
More file actions
145 lines (137 loc) · 2.65 KB
/
Copy pathmain.tsx
File metadata and controls
145 lines (137 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import * as React from "react";
import { createRoot } from "react-dom/client";
import createStore from "./src";
import { xv } from "xanv";
const rows = [
{
container: "ROOT",
name: "nax",
email: "nax@gamil.com",
// age: 10
},
{
container: "ROOT",
name: "nax",
email: "nax@gamil.com",
age: 10,
},
{
container: "ROOT",
name: "nax",
email: "nax1@gamil.com",
age: 3,
},
{
container: "service",
name: "nax",
email: "nax1@gamil.com",
age: 4,
},
{
container: "service",
name: "najrul",
email: "najrul@gamil.com",
age: 30,
},
{
container: "service",
name: "nax1",
email: "nax1@gamil.com",
age: 40,
},
];
const store = createStore(
{
container: xv.string(),
name: xv.string().min(3).max(50),
email: xv.string().min(5).max(100),
age: xv.number().optional().min(1).max(150),
fn: xv.function({ returns: xv.any(), args: [] }).optional(),
},
{
appName: xv.string().default("React Rock App"),
version: xv.string().default("1.0.0"),
},
);
const d = store.createMany({
disableObservation: false,
data: rows,
});
function A() {
const [email, setEmail] = React.useState("nax@gamil.com");
const all = store.find({
where: {
container: "service",
},
});
console.log(all);
return (
<div>
{all.map((item, idx: any) => {
return (
<li key={idx}>
#{item.rid} - {item.email} - {item.name} {item.vid}
</li>
);
})}
<button
onClick={() => {
setEmail("nax1@gamil.com");
}}
>
Set Email
</button>
</div>
);
}
const App = () => {
return (
<div>
<A />
<button
onClick={() => {
store.create({
data: {
container: "service",
name: Math.random().toString(),
email: `${Math.random().toString()}@gmail.com`,
age: 20,
},
});
}}
>
Add+
</button>
<button
onClick={() => {
store.update({
data: {
email: `${Math.random().toString().substring(2, 5)}@gmail.com`,
},
where: {
name: "nax1",
},
});
}}
>
UPDATE
</button>
<button
onClick={() => {
store.delete({
where: {
name: "nax",
},
});
}}
>
Delete
</button>
</div>
);
};
const rootEle = document.getElementById("root");
if (rootEle) {
const root = createRoot(rootEle);
root.render(<App />);
}