react-rock 3.1.1 → 3.1.3

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
@@ -1,94 +1,195 @@
1
- ### React Rock
2
- `react-rock` is a very powerfull react state management system library. you can use it with your small and big application.
1
+ # React Rock Documentation
3
2
 
3
+ **React Rock** is a lightweight state management library designed for React applications. It simplifies state handling with a straightforward API, allowing developers to efficiently manage complex states.
4
4
 
5
- ### How to use
6
- `UserHandler.js`
7
- ```js
8
- import {createState} from 'react-rock'
5
+ - **NPM**: [react-rock](https://www.npmjs.com/package/react-rock)
6
+ - **GitHub**: [React Rock Repository](https://github.com/devnax/react-rock)
9
7
 
10
- const User = createState()
8
+ ---
11
9
 
12
- export default User
10
+ ## Installation
11
+
12
+ To get started, install React Rock via npm:
13
+
14
+ ```bash
15
+ npm install react-rock
13
16
  ```
14
17
 
15
- ```jsx
16
- import User from 'UserHandler'
18
+ ## Core Concept
19
+
20
+ The core of React Rock is the `createStore` function. It enables developers to manage application state using an intuitive API for creating, updating, deleting, and querying state records.
21
+
22
+ ---
23
+
24
+ ## Usage
17
25
 
18
- const App = () => {
19
- const items = User.getAll()
26
+ ### Creating a Store
20
27
 
21
- return(
22
- <div>
23
- <ul>
24
- {
25
- items.map(item => ...)
26
- }
27
- </ul>
28
- <button onClick={() => {
29
- User.insert({
30
- name: "",
31
- email: ""
32
- })
33
- }}>Add Item</button>
34
- </div>
35
- )
28
+ ```tsx
29
+ import { createStore } from "react-rock";
30
+
31
+ // Define the shape of your state
32
+ interface Todo {
33
+ title: string;
34
+ completed: boolean;
36
35
  }
37
36
 
37
+ // Create a store for managing Todos
38
+ const todoStore = createStore<Todo>();
38
39
  ```
39
40
 
40
- ## How to use in class component
41
- ```js
42
- import {StateComponent} from 'react-rock'
43
- import User from 'UserHandler'
44
-
45
- class View extends StateComponent{
46
-
47
- render(){
48
- const items = User.getAll()
49
-
50
- return (
51
- <div>
52
- <ul>
53
- {
54
- items.map(item => ...)
55
- }
56
- </ul>
57
- <button onClick={() => {
58
- User.insert({
59
- name: "",
60
- email: ""
61
- })
62
- }}>Add Item</button>
63
- </div>
64
- )
65
- }
66
- }
41
+ ### Adding Data
42
+
43
+ #### Single Record
44
+
45
+ ```tsx
46
+ todoStore.create({ title: "Learn React Rock", completed: false });
47
+ ```
48
+
49
+ #### Multiple Records
50
+
51
+ ```tsx
52
+ todoStore.createMany([
53
+ { title: "Write Documentation", completed: true },
54
+ { title: "Push to GitHub", completed: false },
55
+ ]);
56
+ ```
57
+
58
+ ### Querying Data
59
+
60
+ #### Retrieve All Records
61
+
62
+ ```tsx
63
+ const allTodos = todoStore.getAll();
64
+ ```
65
+
66
+ #### Find Records by Criteria
67
+
68
+ ```tsx
69
+ const completedTodos = todoStore.find({ completed: true });
70
+ ```
71
+
72
+ #### Find a Single Record by ID
73
+
74
+ ```tsx
75
+ const todo = todoStore.findById("unique_id");
76
+ ```
77
+
78
+ ### Updating Data
79
+
80
+ #### Update Matching Records
81
+
82
+ ```tsx
83
+ todoStore.update({ completed: true }, { title: "Push to GitHub" });
84
+ ```
85
+
86
+ #### Update All Records
87
+
88
+ ```tsx
89
+ todoStore.updateAll({ completed: false });
90
+ ```
91
+
92
+ ### Deleting Data
93
+
94
+ #### Delete Matching Records
95
+
96
+ ```tsx
97
+ todoStore.delete({ completed: true });
98
+ ```
99
+
100
+ #### Delete All Records
67
101
 
102
+ ```tsx
103
+ todoStore.clearAll();
68
104
  ```
69
105
 
70
- ## Methods
106
+ ### Meta Data Management
107
+
108
+ React Rock supports storing metadata alongside your state:
109
+
110
+ #### Set Metadata
111
+
112
+ ```tsx
113
+ todoStore.setMeta("lastUpdated", new Date());
114
+ ```
115
+
116
+ #### Get Metadata
117
+
118
+ ```tsx
119
+ const lastUpdated = todoStore.getMeta("lastUpdated");
120
+ ```
121
+
122
+ #### Clear Metadata
123
+
124
+ ```tsx
125
+ todoStore.clearMeta();
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Advanced Examples
131
+
132
+ ### Pagination
133
+
134
+ ```tsx
135
+ const paginatedTodos = todoStore.getAll({ skip: 0, take: 5 });
136
+ ```
137
+
138
+ ### Moving Records
139
+
140
+ ```tsx
141
+ todoStore.move(0, 1); // Move record from index 0 to index 1
142
+ ```
143
+
144
+ ### Observing State Changes
145
+
146
+ React Rock integrates seamlessly with React hooks for real-time updates:
147
+
148
+ ```tsx
149
+ const TodoList = () => {
150
+ const todos = todoStore.getAll();
151
+
152
+ return (
153
+ <ul>
154
+ {todos.map(todo => (
155
+ <li key={todo._id}>{todo.title}</li>
156
+ ))}
157
+ </ul>
158
+ );
159
+ };
160
+ ```
161
+
162
+ ---
163
+
164
+ ## API Reference
165
+
166
+ ### `createStore`
167
+
168
+ Creates a new store for managing state.
169
+
170
+ #### Methods
171
+
172
+ - **`create(row: Row)`**: Adds a new record.
173
+ - **`createMany(rows: Row[])`**: Adds multiple records.
174
+ - **`update(row: Partial<Row>, where: WhereType<Row>)`**: Updates matching records.
175
+ - **`updateAll(row: Partial<Row>)`**: Updates all records.
176
+ - **`delete(where: WhereType<Row>)`**: Deletes matching records.
177
+ - **`clearAll()`**: Clears all records.
178
+ - **`find(where: WhereType<Row>)`**: Finds matching records.
179
+ - **`findById(id: string)`**: Finds a record by its ID.
180
+ - **`setMeta(key, value)`**: Sets metadata.
181
+ - **`getMeta(key)`**: Retrieves metadata.
182
+ - **`clearMeta()`**: Clears metadata.
183
+
184
+ ---
185
+
186
+ ## Contributing
71
187
 
72
- ```js
73
- import User from 'UserHandler'
74
- const users = User.find({name: "nax"})
188
+ Contributions are welcome! Feel free to open an issue or submit a pull request on the [GitHub repository](https://github.com/devnax/react-rock).
75
189
 
76
- const users = User.find({
77
- name: {
78
- contain: "abc",
79
- startWith: "a",
80
- endWith: "@",
81
- }
82
- })
190
+ ---
83
191
 
84
- const users = User.find({
85
- age: {
86
- lt: 20,
87
- gt: 10,
192
+ ## License
88
193
 
89
- lte: 20,
90
- gte: 10
91
- }
92
- })
194
+ React Rock is licensed under the MIT License.
93
195
 
94
- ```
package/dist/index.d.ts CHANGED
@@ -4,4 +4,4 @@ export * from './types';
4
4
  export declare class StateComponent<P = {}, S = {}, SS = any> extends Component<P, S, SS> {
5
5
  constructor(props: P);
6
6
  }
7
- export declare const createState: <Row extends object, MetaProps extends object = {}>() => IStateHandler<Row, MetaProps>;
7
+ export declare const createStore: <Row extends object, MetaProps extends object = {}>() => IStateHandler<Row, MetaProps>;
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ const _row = (row) => {
16
16
  throw new Error(`State row must be an object. given ${typeof row}: ${row}`);
17
17
  return { ...row, _id: row._id || _uid(), _observe: row._observe || _random() };
18
18
  };
19
- export const createState = () => {
19
+ export const createStore = () => {
20
20
  const factory = {
21
21
  data: {
22
22
  state: [],
package/dist/types.d.ts CHANGED
@@ -36,9 +36,11 @@ export interface IStateHandler<Row, MetaProps> {
36
36
  clearMeta(freeze?: boolean): void;
37
37
  }
38
38
  export type QueryValueType = {
39
- contain?: string | number;
39
+ contain?: string | number | boolean | null | undefined;
40
40
  startWith?: string | number;
41
41
  endWith?: string | number;
42
+ equalWith?: string | number | boolean | null | undefined;
43
+ notEqualWith?: string | number | boolean | null | undefined;
42
44
  gt?: number;
43
45
  lt?: number;
44
46
  gte?: number;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.1.1",
2
+ "version": "3.1.3",
3
3
  "name": "react-rock",
4
4
  "author": "Naxrul Ahmed",
5
5
  "license": "MIT",
@@ -34,4 +34,4 @@
34
34
  "react-dom": "^18.3.1",
35
35
  "typescript": "^5.5.3"
36
36
  }
37
- }
37
+ }