vaderjs 1.1.4 → 1.1.6
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/.vscode/settings.json +3 -1
- package/images/router.png +0 -0
- package/images/state.png +0 -0
- package/index.js +12 -0
- package/jsconfig.json +14 -11
- package/logo.png +0 -0
- package/package.json +7 -4
- package/readme.md +144 -113
- package/tsconfig.json +18 -0
- package/vader.js +534 -431
- package/vaderRouter.js +93 -97
package/.vscode/settings.json
CHANGED
|
Binary file
|
package/images/state.png
ADDED
|
Binary file
|
package/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @file index.js
|
|
4
|
+
* @description This is the entry point for the library. This file exports all the necessary classes and functions.
|
|
5
|
+
* @version 1.1.5
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { Vader } from "./vader.js";
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
import { VaderRouter } from "./vader-router.js";
|
|
11
|
+
|
|
12
|
+
export { Vader, VaderRouter };
|
package/jsconfig.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"strict": true, // Enforce strict type checking
|
|
10
|
-
"forceConsistentCasingInFileNames": true, // Ensures consistent file name casing
|
|
11
|
-
"noImplicitAny": true,
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"checkJs": true,
|
|
5
|
+
"target": "es6",
|
|
6
|
+
"module": "commonjs",
|
|
7
|
+
"alwaysStrict": true
|
|
8
|
+
|
|
12
9
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
10
|
+
"exclude": [
|
|
11
|
+
"node_modules",
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"include": [
|
|
15
|
+
"**/*.js"
|
|
16
|
+
]
|
|
17
|
+
}
|
package/logo.png
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vaderjs",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "A Reactive Framework for Single-Page Applications (SPA)",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "
|
|
7
|
+
"test": "tsc --noEmit "
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -22,5 +22,8 @@
|
|
|
22
22
|
"bugs": {
|
|
23
23
|
"url": "https://github.com/Postr-Inc/Vader.js/issues"
|
|
24
24
|
},
|
|
25
|
-
"homepage": "https://github.com/Postr-Inc/Vader.js#readme"
|
|
25
|
+
"homepage": "https://github.com/Postr-Inc/Vader.js#readme",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"typescript": "^5.2.2"
|
|
28
|
+
}
|
|
26
29
|
}
|
package/readme.md
CHANGED
|
@@ -1,42 +1,116 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://vader-js.pages.dev">
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="/icon.jpeg">
|
|
5
|
+
<img src="logo.png" height="128">
|
|
6
|
+
</picture>
|
|
7
|
+
<h1 align="center">Vader.js</h1>
|
|
8
|
+
</a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
1
11
|
# VaderJS: A Reactive Framework for SPAs
|
|
2
12
|
|
|
3
13
|
[](https://github.com/Postr-Inc/Vader.js/blob/main/LICENSE) [](https://www.npmjs.com/package/vaderjs)
|
|
4
14
|
|
|
5
|
-
VaderJS is
|
|
15
|
+
VaderJS is powerful component based reactive library for spa inspired by react.js
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## Get Started
|
|
19
|
+
|
|
20
|
+
1. Install VaderJS:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
npm install vaderjs
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
or
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/vaderjs@latest/index.js" ></script>
|
|
30
|
+
<script type="module" src="https://unpkg.com/vaderjs@latest/index.js">
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
2. Import components and utilities into your project.
|
|
34
|
+
|
|
35
|
+
- Heres an example import map
|
|
36
|
+
|
|
37
|
+
```html
|
|
38
|
+
<script type="importmap">
|
|
39
|
+
{
|
|
40
|
+
"imports":{
|
|
41
|
+
"vaderjs":"./dist/vader/index.js",
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
</script>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- Then you can import like this
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
import { Vader, VaderRouter } from 'vaderjs'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
3. Use VaderJS features for routing, state management, auth, and more.
|
|
54
|
+
|
|
55
|
+
4. Create dynamic SPAs with enhanced user experiences.
|
|
6
56
|
|
|
7
57
|
## Key Features
|
|
8
58
|
|
|
9
59
|
### Declarative Routing
|
|
10
60
|
|
|
11
61
|
```javascript
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
62
|
+
import { VaderRouter } from "vader-router";
|
|
63
|
+
import { MyComponent } from './components/my-component.js'
|
|
64
|
+
const app = new VaderRouter('/') // intial route
|
|
65
|
+
|
|
66
|
+
app.use('/') // use the route
|
|
67
|
+
|
|
68
|
+
app.get('/', async (req, res) => {
|
|
69
|
+
res.render('#app', await MyComponent.render())
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
app.on('/', async (req, res) => {
|
|
73
|
+
res.render('#app', await MyComponent.render())
|
|
74
|
+
})
|
|
75
|
+
app.get('/:hello', (req, res) => {
|
|
76
|
+
res.render('#app', `<h1>Hello ${req.params.hello}</h1>`)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
app.start()
|
|
18
80
|
```
|
|
81
|
+
|
|
19
82
|
|
|
20
83
|
### State Management
|
|
21
84
|
|
|
22
85
|
```javascript
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
86
|
+
import { Vader } from "vaderjs"
|
|
87
|
+
|
|
88
|
+
class MyApp extends Vader.Component{
|
|
89
|
+
contructor(){
|
|
90
|
+
super()
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
render(){
|
|
95
|
+
const [state, setState] = this.useState('state', 0, ()=>{
|
|
96
|
+
// this is a callback that is ran on state change!
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
let myfunc = this.$Function(function fn(){
|
|
100
|
+
setState(state + 1)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
this.useEffect(()=>{
|
|
104
|
+
// this is a callback that is ran on component mount
|
|
105
|
+
}, [])
|
|
106
|
+
|
|
107
|
+
return this.html(`
|
|
108
|
+
<p>count ${state} </p>
|
|
109
|
+
<button onclick="${myfunc}">Change State by 1</button>
|
|
110
|
+
`)
|
|
111
|
+
|
|
112
|
+
}
|
|
26
113
|
}
|
|
27
|
-
rf('increment', increment)
|
|
28
|
-
useEffect((state)=>{
|
|
29
|
-
console.log('New State for count' + state)
|
|
30
|
-
}[state])
|
|
31
|
-
<button onclick="increment()">Increment</button>
|
|
32
|
-
|
|
33
|
-
// useRef in v1.1.2 - allows you to reference a dom element and efficiently update it, update takes the given html and checks for differences and only update the element if necessary
|
|
34
|
-
componentDidMount: () => {
|
|
35
|
-
let title = useRef('title').current
|
|
36
|
-
title.innerHTML = 'Home'
|
|
37
|
-
useRef('title').update(`<span class="text-2xl font-bold">Home</span>`)
|
|
38
|
-
},
|
|
39
|
-
|
|
40
114
|
```
|
|
41
115
|
|
|
42
116
|
### Signals
|
|
@@ -47,36 +121,48 @@ Signals are a way to communicate between components. Signals are similar to even
|
|
|
47
121
|
|
|
48
122
|
```javascript
|
|
49
123
|
|
|
50
|
-
let count = signal('count', 0)
|
|
51
|
-
function increment(){
|
|
52
|
-
count.set(count.get() + 1)
|
|
53
|
-
}
|
|
124
|
+
let count = this.signal('count', 0)
|
|
54
125
|
|
|
55
|
-
|
|
56
|
-
|
|
126
|
+
let increment = this.$Function(function increment(){
|
|
127
|
+
count.set(count.get() + 1)
|
|
57
128
|
})
|
|
58
129
|
|
|
130
|
+
count.subscribe( (detail)=>{
|
|
131
|
+
console.log(detail)
|
|
132
|
+
}, true) // true means it will run on once
|
|
133
|
+
|
|
59
134
|
// call the signal
|
|
60
|
-
|
|
135
|
+
count.call()
|
|
61
136
|
|
|
62
|
-
|
|
137
|
+
count.cleanup() // cleans up the signal
|
|
63
138
|
|
|
64
|
-
|
|
139
|
+
count.get() // returns the signal detail
|
|
65
140
|
|
|
66
141
|
|
|
142
|
+
|
|
67
143
|
```
|
|
144
|
+
- Signals also allow you to share state between scopes
|
|
145
|
+
|
|
146
|
+
```javascript
|
|
147
|
+
window.addEventListener('signalDispatch', (e)=>{
|
|
148
|
+
console.log(e.detail)
|
|
149
|
+
})
|
|
150
|
+
````
|
|
68
151
|
|
|
69
152
|
### Function Binding
|
|
70
153
|
|
|
71
154
|
```javascript
|
|
72
|
-
|
|
73
|
-
|
|
155
|
+
const fn = this.$Function(function fn() {
|
|
156
|
+
console.log("Hello World");
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
return html`<button onclick="${fn}">Click Me</button>`
|
|
74
160
|
```
|
|
75
161
|
|
|
76
162
|
### Authentication & Authorization
|
|
77
163
|
|
|
78
164
|
```javascript
|
|
79
|
-
const auth = useAuth({
|
|
165
|
+
const auth = this.useAuth({
|
|
80
166
|
rulesets: rules,
|
|
81
167
|
user: currentUser
|
|
82
168
|
});
|
|
@@ -85,65 +171,20 @@ if (auth.can('edit')) {
|
|
|
85
171
|
}
|
|
86
172
|
```
|
|
87
173
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
```javascript
|
|
91
|
-
const store = createStore(initialState);
|
|
92
|
-
const { state, setState, subscribe } = store;
|
|
93
|
-
```
|
|
94
|
-
|
|
174
|
+
|
|
95
175
|
### Simplified Component Creation
|
|
96
176
|
|
|
97
177
|
```javascript
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
178
|
+
import { Vader } from 'vaderjs';
|
|
179
|
+
|
|
180
|
+
export class App extends Vader.Component{
|
|
181
|
+
constructor(){
|
|
182
|
+
super('App')
|
|
183
|
+
}
|
|
184
|
+
render(){
|
|
185
|
+
return html`<div>Hello World</div>`
|
|
186
|
+
}
|
|
104
187
|
}
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
// then call
|
|
108
|
-
|
|
109
|
-
myComponent(key).render({props})
|
|
110
|
-
|
|
111
|
-
//example
|
|
112
|
-
|
|
113
|
-
import VaderRouter from "./router.js";
|
|
114
|
-
import { vhtml, component, rf } from './script.js'
|
|
115
|
-
|
|
116
|
-
const app = component('app', {
|
|
117
|
-
render: (states) => {
|
|
118
|
-
let [count, setCount] = useState('count', 0);
|
|
119
|
-
useEffect(() => {
|
|
120
|
-
console.log(states)
|
|
121
|
-
console.log('App component mounted');
|
|
122
|
-
}, [count]);
|
|
123
|
-
|
|
124
|
-
function incrementHandler() {
|
|
125
|
-
setCount(count + 1);
|
|
126
|
-
}
|
|
127
|
-
rf('incrementHandler', incrementHandler);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return vhtml(`
|
|
131
|
-
|
|
132
|
-
<div>
|
|
133
|
-
<button className="btn" onclick="incrementHandler()"
|
|
134
|
-
|
|
135
|
-
>Count: ${count}</button>
|
|
136
|
-
${
|
|
137
|
-
count > 10 ? '<h1 style="color:lightBlue">Greater Than 10</h1>' : 'Less than 10'
|
|
138
|
-
}
|
|
139
|
-
</div>
|
|
140
|
-
`)
|
|
141
|
-
},
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
(async ()=>{
|
|
145
|
-
document.body.innerHTML = await app.render()
|
|
146
|
-
})
|
|
147
188
|
```
|
|
148
189
|
|
|
149
190
|
## Include views
|
|
@@ -162,30 +203,20 @@ ${
|
|
|
162
203
|
|
|
163
204
|
```js
|
|
164
205
|
// home.js
|
|
165
|
-
import {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
## Get Started
|
|
178
|
-
|
|
179
|
-
1. Install VaderJS:
|
|
180
|
-
```sh
|
|
181
|
-
npm install vaderjs
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
2. Import components and utilities into your project.
|
|
185
|
-
|
|
186
|
-
3. Use VaderJS features for routing, state management, auth, and more.
|
|
206
|
+
import { Vader, include } from "vaderjs";
|
|
207
|
+
|
|
208
|
+
class Home extends Vader.Component {
|
|
209
|
+
constructor() {
|
|
210
|
+
super();
|
|
211
|
+
}
|
|
212
|
+
render() {
|
|
213
|
+
return this.html(include("views/app.html"));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
187
216
|
|
|
188
|
-
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
|
|
189
220
|
|
|
190
221
|
## License
|
|
191
222
|
|
package/tsconfig.json
ADDED