olova 2.0.3 → 2.0.4
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 +237 -33
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,54 +1,258 @@
|
|
|
1
|
-
# Olova
|
|
1
|
+
# 🚀 Olova Framework Documentation
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
development with a clean, intuitive syntax. It provides a reactivity system and
|
|
5
|
-
hooks to manage state and side effects, allowing developers to build modern web
|
|
6
|
-
applications with ease.
|
|
3
|
+
> A lightweight JavaScript framework for building web applications with JSX
|
|
7
4
|
|
|
8
|
-
##
|
|
5
|
+
## What is Olova?
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
state changes.
|
|
14
|
-
- **JSX-style Syntax**: Write UI components using a simple, declarative
|
|
15
|
-
JSX-style syntax.
|
|
16
|
-
- **Reactivity**: Automatically re-render components when state changes.
|
|
7
|
+
Olova is a simple yet powerful JavaScript framework that lets you build web
|
|
8
|
+
applications using JSX. It directly manipulates the DOM without a Virtual DOM,
|
|
9
|
+
making it lightweight and straightforward to use.
|
|
17
10
|
|
|
18
|
-
##
|
|
11
|
+
## ⚡ Quick Start
|
|
19
12
|
|
|
20
|
-
|
|
13
|
+
### Installation
|
|
14
|
+
|
|
15
|
+
Get started with a single command:
|
|
21
16
|
|
|
22
17
|
```bash
|
|
23
|
-
npm
|
|
18
|
+
npm create vilo@latest
|
|
24
19
|
```
|
|
25
20
|
|
|
26
|
-
|
|
21
|
+
This command will set up a new Olova project, similar to how Vite works. You can
|
|
22
|
+
use it to create an Olova template or install Olova in an existing project.
|
|
23
|
+
|
|
24
|
+
Alternatively, you can install Olova directly:
|
|
27
25
|
|
|
28
26
|
```bash
|
|
29
|
-
|
|
27
|
+
npm install olova
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Your First Olova App
|
|
31
|
+
|
|
32
|
+
```jsx
|
|
33
|
+
import Olova from "olova";
|
|
34
|
+
|
|
35
|
+
const App = () => {
|
|
36
|
+
return (
|
|
37
|
+
<>
|
|
38
|
+
<h1>Welcome to Olova! 🎉</h1>
|
|
39
|
+
<p>Building web apps made simple.</p>
|
|
40
|
+
</>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 🎯 Core Concepts
|
|
46
|
+
|
|
47
|
+
### Built-in Hooks
|
|
48
|
+
|
|
49
|
+
Olova provides several essential hooks for building dynamic applications:
|
|
50
|
+
|
|
51
|
+
```jsx
|
|
52
|
+
import {
|
|
53
|
+
$signal, // Manage component state
|
|
54
|
+
$effect, // Handle side effects
|
|
55
|
+
$memo, // Memoize values
|
|
56
|
+
$ref, // Reference DOM elements
|
|
57
|
+
$context, // Share data between components
|
|
58
|
+
$callback, // Memoize functions
|
|
59
|
+
} from "olova";
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Default Exports
|
|
63
|
+
|
|
64
|
+
Olova comes with two built-in utilities:
|
|
65
|
+
|
|
66
|
+
```jsx
|
|
67
|
+
import Olova, { h, Fragment } from "olova";
|
|
68
|
+
|
|
69
|
+
// h: Element generator (automatically used for JSX transformation)
|
|
70
|
+
// Fragment: Wrapper for multiple elements, can be used as <></> or <Fragment></Fragment>
|
|
30
71
|
```
|
|
31
72
|
|
|
32
|
-
##
|
|
73
|
+
## 💫 Using Hooks
|
|
33
74
|
|
|
34
|
-
|
|
75
|
+
### State Management
|
|
35
76
|
|
|
36
|
-
```
|
|
37
|
-
import Olova, {
|
|
77
|
+
```jsx
|
|
78
|
+
import Olova, { $signal } from "olova";
|
|
38
79
|
|
|
39
|
-
|
|
80
|
+
const Counter = () => {
|
|
40
81
|
const [count, setCount] = State(0);
|
|
41
82
|
|
|
83
|
+
return <button onClick={() => setCount(count + 1)}>Count: {count}</button>;
|
|
84
|
+
};
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Side Effects
|
|
88
|
+
|
|
89
|
+
```jsx
|
|
90
|
+
import Olova, { $effect, $signal } from "olova";
|
|
91
|
+
|
|
92
|
+
const DataFetcher = () => {
|
|
93
|
+
const [data, setData] = State(null);
|
|
94
|
+
|
|
42
95
|
Effect(() => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
96
|
+
fetch("/api/data")
|
|
97
|
+
.then((res) => res.json())
|
|
98
|
+
.then(setData);
|
|
99
|
+
}, []); // Empty array means run once on mount
|
|
46
100
|
|
|
47
|
-
return
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
101
|
+
return <div>{data ? "Data loaded!" : "Loading..."}</div>;
|
|
102
|
+
};
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Using References
|
|
106
|
+
|
|
107
|
+
```jsx
|
|
108
|
+
import Olova, { $ref } from "olova";
|
|
109
|
+
|
|
110
|
+
const FocusInput = () => {
|
|
111
|
+
const inputRef = $ref(null);
|
|
112
|
+
|
|
113
|
+
return <input ref={inputRef} onFocus={() => console.log("Input focused!")} />;
|
|
114
|
+
};
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Memoization
|
|
118
|
+
|
|
119
|
+
```jsx
|
|
120
|
+
import Olova, { $memo, $signal } from "olova";
|
|
121
|
+
|
|
122
|
+
const ExpensiveComponent = ({ data }) => {
|
|
123
|
+
const processedData = Memo(() => {
|
|
124
|
+
// Expensive computation here
|
|
125
|
+
return data.map((item) => item * 2);
|
|
126
|
+
}, [data]);
|
|
127
|
+
|
|
128
|
+
return <div>{processedData.join(", ")}</div>;
|
|
129
|
+
};
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## 🎨 Styling in Olova
|
|
133
|
+
|
|
134
|
+
Olova supports all standard CSS approaches:
|
|
135
|
+
|
|
136
|
+
### CSS Imports
|
|
137
|
+
|
|
138
|
+
```jsx
|
|
139
|
+
import "./styles.css";
|
|
140
|
+
|
|
141
|
+
const StyledComponent = () => (
|
|
142
|
+
<div className="my-component">Styled content</div>
|
|
143
|
+
);
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### CSS Modules
|
|
147
|
+
|
|
148
|
+
```jsx
|
|
149
|
+
import styles from "./Component.module.css";
|
|
150
|
+
|
|
151
|
+
const ModuleStyledComponent = () => (
|
|
152
|
+
<div className={styles.container}>Module styled content</div>
|
|
153
|
+
);
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Inline Styles
|
|
157
|
+
|
|
158
|
+
```jsx
|
|
159
|
+
const InlineStyledComponent = () => (
|
|
160
|
+
<div style={{ padding: "20px", color: "blue" }}>Inline styled content</div>
|
|
161
|
+
);
|
|
54
162
|
```
|
|
163
|
+
|
|
164
|
+
## 🔮 How Olova Works
|
|
165
|
+
|
|
166
|
+
1. **Direct DOM Manipulation**
|
|
167
|
+
|
|
168
|
+
1. Olova directly updates the DOM without a Virtual DOM
|
|
169
|
+
1. Efficient updates when state changes
|
|
170
|
+
1. Lightweight and fast performance
|
|
171
|
+
|
|
172
|
+
1. **JSX Transformation**
|
|
173
|
+
|
|
174
|
+
1. Uses the `h` function to transform JSX into DOM elements
|
|
175
|
+
1. Handles event binding automatically
|
|
176
|
+
1. Manages component lifecycle efficiently
|
|
177
|
+
|
|
178
|
+
## 📚 Best Practices
|
|
179
|
+
|
|
180
|
+
### Component Structure
|
|
181
|
+
|
|
182
|
+
```jsx
|
|
183
|
+
// Good: Single responsibility component
|
|
184
|
+
const UserProfile = ({ user }) => (
|
|
185
|
+
<div className="profile">
|
|
186
|
+
<img src={user.avatar || "/placeholder.svg"} alt={user.name} />
|
|
187
|
+
<h2>{user.name}</h2>
|
|
188
|
+
</div>
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
// Better: Using Fragment for multiple elements
|
|
192
|
+
const UserCard = ({ user }) => (
|
|
193
|
+
<>
|
|
194
|
+
<UserProfile user={user} />
|
|
195
|
+
<UserStats stats={user.stats} />
|
|
196
|
+
</>
|
|
197
|
+
);
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Hook Usage
|
|
201
|
+
|
|
202
|
+
```jsx
|
|
203
|
+
// Effective use of multiple hooks
|
|
204
|
+
const UserDashboard = () => {
|
|
205
|
+
const [user, setUser] = State(null);
|
|
206
|
+
const userCache = $ref({});
|
|
207
|
+
|
|
208
|
+
Effect(() => {
|
|
209
|
+
// Side effect cleanup example
|
|
210
|
+
return () => {
|
|
211
|
+
userCache.current = {};
|
|
212
|
+
};
|
|
213
|
+
}, []);
|
|
214
|
+
|
|
215
|
+
return <div>Dashboard Content</div>;
|
|
216
|
+
};
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## 🚀 Coming Soon
|
|
220
|
+
|
|
221
|
+
- More built-in hooks
|
|
222
|
+
- Enhanced development tools
|
|
223
|
+
- Additional utility functions
|
|
224
|
+
- Performance optimizations
|
|
225
|
+
|
|
226
|
+
## 🤝 Contributing
|
|
227
|
+
|
|
228
|
+
We welcome contributions! Whether it's:
|
|
229
|
+
|
|
230
|
+
- Bug reports
|
|
231
|
+
- Feature requests
|
|
232
|
+
- Documentation improvements
|
|
233
|
+
- Pull requests
|
|
234
|
+
|
|
235
|
+
## 📖 Examples
|
|
236
|
+
|
|
237
|
+
Find more examples in our [GitHub repository](https://github.com/olovajs/olova).
|
|
238
|
+
|
|
239
|
+
## 🛠 Using Vilo
|
|
240
|
+
|
|
241
|
+
Vilo is a project creation tool for Olova, similar to Vite. You can use it to
|
|
242
|
+
quickly set up new Olova projects or add Olova to existing projects.
|
|
243
|
+
|
|
244
|
+
To create a new Olova project:
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
npm create vilo@latest my-olova-app
|
|
248
|
+
cd my-olova-app
|
|
249
|
+
npm install
|
|
250
|
+
npm run dev
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
This will set up a new Olova project with a basic template, ready for you to
|
|
254
|
+
start developing.
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
Made with simplicity in mind 🌟
|