frontend-hamroun 1.2.50 → 1.2.51
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 +92 -42
- package/package.json +1 -1
package/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Frontend Hamroun
|
2
2
|
|
3
|
-
A lightweight JavaScript framework with Virtual DOM and hooks implementation inspired by modern frameworks.
|
3
|
+
A lightweight full-stack JavaScript framework with Virtual DOM and hooks implementation inspired by modern frameworks.
|
4
4
|
|
5
5
|

|
6
6
|

|
@@ -9,24 +9,6 @@ A lightweight JavaScript framework with Virtual DOM and hooks implementation ins
|
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
12
|
```bash
|
31
13
|
npm install frontend-hamroun
|
32
14
|
```
|
@@ -38,8 +20,9 @@ Create a new project using:
|
|
38
20
|
```bash
|
39
21
|
npx create-frontend-app my-app
|
40
22
|
# or
|
41
|
-
|
23
|
+
npx frontend-hamroun create my-app
|
42
24
|
```
|
25
|
+
|
43
26
|
Then:
|
44
27
|
|
45
28
|
```bash
|
@@ -68,31 +51,36 @@ render(<App />, document.getElementById('root'));
|
|
68
51
|
|
69
52
|
## Features
|
70
53
|
|
71
|
-
- Lightweight (<5KB gzipped)
|
54
|
+
- Lightweight full-stack framework (<5KB gzipped core)
|
72
55
|
- Virtual DOM with efficient diffing algorithm
|
73
56
|
- Hooks API (useState, useEffect, useMemo, useRef)
|
74
|
-
- Context API
|
57
|
+
- Context API for state management
|
75
58
|
- Server-Side Rendering
|
59
|
+
- Built-in API server with Express
|
60
|
+
- Database integration (MongoDB, MySQL, PostgreSQL)
|
61
|
+
- Authentication with JWT
|
76
62
|
- Error Boundaries
|
77
63
|
- JSX support
|
78
64
|
- TypeScript support
|
79
|
-
-
|
65
|
+
- Interactive CLI for project scaffolding
|
66
|
+
|
67
|
+
## Client-side Features
|
80
68
|
|
81
|
-
|
69
|
+
### Hooks
|
82
70
|
|
83
|
-
|
71
|
+
#### useState
|
84
72
|
Manages component state.
|
85
73
|
|
86
|
-
```
|
74
|
+
```jsx
|
87
75
|
const [count, setCount] = useState(0);
|
88
76
|
setCount(count + 1); // Direct value
|
89
77
|
setCount(prev => prev + 1); // Using callback
|
90
78
|
```
|
91
79
|
|
92
|
-
|
80
|
+
#### useEffect
|
93
81
|
Handles side effects in components.
|
94
82
|
|
95
|
-
```
|
83
|
+
```jsx
|
96
84
|
useEffect(() => {
|
97
85
|
document.title = `Count: ${count}`;
|
98
86
|
|
@@ -103,28 +91,28 @@ useEffect(() => {
|
|
103
91
|
}, [count]); // Only re-run when count changes
|
104
92
|
```
|
105
93
|
|
106
|
-
|
94
|
+
#### useMemo
|
107
95
|
Memoizes expensive computations.
|
108
96
|
|
109
|
-
```
|
97
|
+
```jsx
|
110
98
|
const doubled = useMemo(() => {
|
111
99
|
console.log('Computing doubled value');
|
112
100
|
return count * 2;
|
113
101
|
}, [count]);
|
114
102
|
```
|
115
103
|
|
116
|
-
|
104
|
+
#### useRef
|
117
105
|
Creates a mutable reference that persists across renders.
|
118
106
|
|
119
|
-
```
|
107
|
+
```jsx
|
120
108
|
const renderCount = useRef(0);
|
121
109
|
renderCount.current += 1; // Update without triggering re-render
|
122
110
|
```
|
123
111
|
|
124
|
-
|
112
|
+
#### useErrorBoundary
|
125
113
|
Handles component errors.
|
126
114
|
|
127
|
-
```
|
115
|
+
```jsx
|
128
116
|
const [error, resetError] = useErrorBoundary();
|
129
117
|
|
130
118
|
if (error) {
|
@@ -137,11 +125,11 @@ if (error) {
|
|
137
125
|
}
|
138
126
|
```
|
139
127
|
|
140
|
-
|
128
|
+
### Context API
|
141
129
|
|
142
130
|
Share state across components without prop drilling.
|
143
131
|
|
144
|
-
```
|
132
|
+
```jsx
|
145
133
|
// Create context
|
146
134
|
const ThemeContext = createContext('light');
|
147
135
|
|
@@ -168,13 +156,56 @@ function ThemedComponent() {
|
|
168
156
|
}
|
169
157
|
```
|
170
158
|
|
159
|
+
## Server-Side Features
|
160
|
+
|
161
|
+
### Server Setup
|
162
|
+
|
163
|
+
```js
|
164
|
+
import { server } from 'frontend-hamroun/server';
|
165
|
+
|
166
|
+
const app = await server.createServer({
|
167
|
+
port: 3000,
|
168
|
+
apiDir: './api',
|
169
|
+
pagesDir: './pages',
|
170
|
+
staticDir: './public',
|
171
|
+
db: {
|
172
|
+
url: process.env.DB_URL,
|
173
|
+
type: 'mongodb' // or 'mysql', 'postgres'
|
174
|
+
},
|
175
|
+
auth: {
|
176
|
+
secret: process.env.JWT_SECRET,
|
177
|
+
expiresIn: '7d'
|
178
|
+
}
|
179
|
+
});
|
180
|
+
|
181
|
+
await app.start();
|
182
|
+
```
|
183
|
+
|
184
|
+
### API Routes
|
185
|
+
|
186
|
+
Create API endpoints in your `apiDir` folder:
|
187
|
+
|
188
|
+
```js
|
189
|
+
// api/users.js
|
190
|
+
export async function get(req, res) {
|
191
|
+
const users = await req.db.collection('users').find().toArray();
|
192
|
+
res.json(users);
|
193
|
+
}
|
194
|
+
|
195
|
+
export async function post(req, res) {
|
196
|
+
const user = req.body;
|
197
|
+
const result = await req.db.collection('users').insertOne(user);
|
198
|
+
res.status(201).json(result);
|
199
|
+
}
|
200
|
+
```
|
201
|
+
|
171
202
|
## Server-Side Rendering
|
172
203
|
|
173
204
|
Frontend Hamroun supports server-side rendering with hydration:
|
174
205
|
|
175
|
-
```
|
206
|
+
```jsx
|
176
207
|
// Server-side
|
177
|
-
import { renderToString } from 'frontend-hamroun';
|
208
|
+
import { renderToString } from 'frontend-hamroun/ssr';
|
178
209
|
|
179
210
|
const html = await renderToString(<App />);
|
180
211
|
res.send(`
|
@@ -199,7 +230,7 @@ hydrate(<App />, document.getElementById('root'));
|
|
199
230
|
### Batch Updates
|
200
231
|
Group multiple state updates together to prevent unnecessary re-renders.
|
201
232
|
|
202
|
-
```
|
233
|
+
```jsx
|
203
234
|
import { batchUpdates } from 'frontend-hamroun';
|
204
235
|
|
205
236
|
batchUpdates(() => {
|
@@ -211,10 +242,29 @@ batchUpdates(() => {
|
|
211
242
|
|
212
243
|
## Project Templates
|
213
244
|
|
214
|
-
The framework comes with
|
245
|
+
The framework comes with several project templates:
|
246
|
+
|
247
|
+
1. **Basic App**: Simple client-side application
|
248
|
+
2. **SSR Template**: Server-side rendering with hydration
|
249
|
+
3. **Fullstack App**: Complete solution with API routes, authentication, and database integration
|
250
|
+
|
251
|
+
## CLI Tools
|
252
|
+
|
253
|
+
Frontend Hamroun comes with a powerful CLI for project management:
|
215
254
|
|
216
|
-
|
217
|
-
|
255
|
+
```bash
|
256
|
+
# Create a new project
|
257
|
+
npx frontend-hamroun create my-app
|
258
|
+
|
259
|
+
# Add a new component
|
260
|
+
npx frontend-hamroun add:component Button
|
261
|
+
|
262
|
+
# Add a new page
|
263
|
+
npx frontend-hamroun add:page home
|
264
|
+
|
265
|
+
# Add a new API route
|
266
|
+
npx frontend-hamroun add:api users
|
267
|
+
```
|
218
268
|
|
219
269
|
## Browser Compatibility
|
220
270
|
|