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.
@@ -1,3 +1,5 @@
1
1
  {
2
- "liveServer.settings.port": 5501
2
+ "liveServer.settings.port": 5501,
3
+ "js/ts.implicitProjectConfig.checkJs": true,
4
+ "js/ts.implicitProjectConfig.experimentalDecorators": true
3
5
  }
Binary file
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
- "allowJs": true,
4
- "checkJs": true,
5
- "jsx": "react",
6
- "module": "esnext",
7
- "moduleResolution": "node",
8
- "noEmit": true,
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
- "include": ["/"]
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.4",
3
+ "version": "1.1.6",
4
4
  "description": "A Reactive Framework for Single-Page Applications (SPA)",
5
- "main": "vader.js",
5
+ "main": "index.js",
6
6
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
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
  [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Postr-Inc/Vader.js/blob/main/LICENSE) [![npm version](https://img.shields.io/npm/v/vaderjs.svg?style=flat)](https://www.npmjs.com/package/vaderjs)
4
14
 
5
- VaderJS is a powerful reactive framework for building Single-Page Applications (SPAs), inspired by React.js.
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
- const router = new vaderRouter('/');
13
- router.use('/');
14
- router.on('/test/:hello', (req) => {
15
- console.log(req.params);
16
- });
17
- router.start();
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
- const [state, setState] = useState("count", initialState);
24
- function increment(){
25
- setState(state + 1)
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
- signal.subscribe( (detail)=>{
56
- console.log(detail)
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
- signal.call()
135
+ count.call()
61
136
 
62
- signal.cleanup() // cleans up the signal
137
+ count.cleanup() // cleans up the signal
63
138
 
64
- signal.get() // returns the signal detail
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
- rf('login', login);
73
- return html`<button onclick="login()">Login</button>`;
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
- ### Global State Management
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
- // id is a unique component key in which allows vader to update the component state!
99
- const myComponent = (id) = component(id, {
100
- render: (states, props) => {
101
- return vhtml(`
102
- <div>${props.message}</div>
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 { vhtml, component, rf, include } from 'vader.js'
166
- const Home = component('Home', {
167
- render: async () =>{
168
- let html = await include('views/app.html')
169
- return vhtml(html)
170
- },
171
- componentDidMount: () =>{
172
- console.log('home mounted')
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
- 4. Create dynamic SPAs with enhanced user experiences.
217
+
218
+ ```
219
+
189
220
 
190
221
  ## License
191
222
 
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2016",
4
+ "module": "commonjs",
5
+ "allowJs": true,
6
+ "checkJs": true
7
+
8
+ },
9
+ "include": [
10
+ "**/*.js"
11
+ ],
12
+ "exclude": [
13
+ "node_modules",
14
+ "dist",
15
+ "website"
16
+ ],
17
+ "compileOnSave": true,
18
+ }