react-rock 3.1.5 → 3.1.7
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 +1 -1
- package/readme.md +9 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-rock",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.7",
|
|
4
4
|
"author": "Naxrul Ahmed",
|
|
5
5
|
"description": "React-Rock is a modern, lightweight state management library designed to simplify handling global state in React applications. With a minimal API and powerful features like freezing data updates for optimized re-renders, React-Rock allows you to manage state more efficiently while ensuring your app remains fast and responsive.",
|
|
6
6
|
"main": "./index.js",
|
package/readme.md
CHANGED
|
@@ -32,10 +32,11 @@ import { createStore } from 'react-rock';
|
|
|
32
32
|
|
|
33
33
|
// Define RowType and MetaType
|
|
34
34
|
type RowType = { name: string, age: number };
|
|
35
|
-
type MetaType = {
|
|
35
|
+
type MetaType = { anykey: any };
|
|
36
36
|
|
|
37
|
+
const defaut_rows = [{ name: '', age: 0 }]
|
|
37
38
|
// Create a store
|
|
38
|
-
const users = createStore<RowType, MetaType>({
|
|
39
|
+
const users = createStore<RowType, MetaType>(defaut_rows, { anykey: '' });
|
|
39
40
|
|
|
40
41
|
// Add a new row to the store
|
|
41
42
|
users.create({ name: 'John Doe', age: 30 });
|
|
@@ -83,7 +84,7 @@ Here’s a table with all available methods and their descriptions:
|
|
|
83
84
|
The `find` method allows you to search for rows in the store based on specific conditions:
|
|
84
85
|
|
|
85
86
|
```typescript
|
|
86
|
-
const foundUsers = users.find({ name:
|
|
87
|
+
const foundUsers = users.find({ name: 'John Doe' } );
|
|
87
88
|
console.log(foundUsers);
|
|
88
89
|
```
|
|
89
90
|
|
|
@@ -157,10 +158,10 @@ class UserList extends StoreComponent {
|
|
|
157
158
|
users.create({ name: 'Alice', age: 25 });
|
|
158
159
|
|
|
159
160
|
// Update a user
|
|
160
|
-
users.update({ age: 26 }, { name:
|
|
161
|
+
users.update({ age: 26 }, { name: 'Alice' } );
|
|
161
162
|
|
|
162
163
|
// Delete a user
|
|
163
|
-
users.delete({ name:
|
|
164
|
+
users.delete({ name: 'Alice' } );
|
|
164
165
|
```
|
|
165
166
|
|
|
166
167
|
## Examples with `find` and Query
|
|
@@ -171,7 +172,7 @@ const usersOver25 = users.find({ age: { gt: 25 } });
|
|
|
171
172
|
console.log(usersOver25);
|
|
172
173
|
|
|
173
174
|
// Find the first user with the name 'Alice'
|
|
174
|
-
const alice = users.findFirst({ name:
|
|
175
|
+
const alice = users.findFirst({ name: 'Alice' } );
|
|
175
176
|
console.log(alice);
|
|
176
177
|
```
|
|
177
178
|
|
|
@@ -184,7 +185,7 @@ import { StoreComponent } from 'react-rock';
|
|
|
184
185
|
|
|
185
186
|
class UserList extends StoreComponent {
|
|
186
187
|
render() {
|
|
187
|
-
const users =
|
|
188
|
+
const users = users.getAll();
|
|
188
189
|
return (
|
|
189
190
|
<div>
|
|
190
191
|
{users.map(user => <div key={user._id}>{user.name}</div>)}
|
|
@@ -195,7 +196,7 @@ class UserList extends StoreComponent {
|
|
|
195
196
|
|
|
196
197
|
class UserProfile extends StoreComponent {
|
|
197
198
|
render() {
|
|
198
|
-
const user =
|
|
199
|
+
const user = users.findFirst({ name: 'John Doe' });
|
|
199
200
|
return <div>{user ? user.name : 'User not found'}</div>;
|
|
200
201
|
}
|
|
201
202
|
}
|