vaderjs 1.3.2 → 1.3.3-122198a8b18b-hotfix

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 ADDED
@@ -0,0 +1,247 @@
1
+
2
+ <p align="center">
3
+ <a href="https://vader-js.pages.dev">
4
+ <picture>
5
+ <source media="(prefers-color-scheme: dark)" srcset="/icon.jpeg">
6
+ <img src="./logo.png" height="128">
7
+ </picture>
8
+ <h1 align="center">Vader.js</h1>
9
+ </a>
10
+ </p>
11
+
12
+ # VaderJS: A Powerful Reactive Framework for SPAs inspired by react.js!
13
+
14
+ [![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)
15
+
16
+
17
+ > Do not use any alpha versions as these where changed multiple times any version under latest is considered lts and are deemed to be stable
18
+ ## Get Started
19
+
20
+ 2. Install vaderjs
21
+
22
+ ```bash
23
+ npm i vaderjs@latest
24
+ ```
25
+
26
+ 4. Create Proper Folders
27
+
28
+ Create a pages folder - which allows you to have nextjs page like routing via buns file based router
29
+
30
+ Tip: Each folder can be deep nested up to 4 levels!
31
+
32
+ ```bash
33
+ /pages/index.jsx = /
34
+ /pages/home/[page].jsx = /home/:page
35
+ /pages/path/index.jsx = /path/
36
+ /pages/test/[...]/index.jsx = /path/test/*
37
+ /pages/route/[param1]/[param2].jsx = /path/route/:param1/:param2
38
+ ```
39
+ Keyword folders - all files are passed from these folders to the `dist` folder
40
+
41
+ ```bash
42
+
43
+ pages - used for jsx route files
44
+ src - used for your jsx components / javascript files
45
+ public - used for anything
46
+
47
+ ```
48
+
49
+
50
+
51
+ 5. And your done - Run `npx vaderjs` and the compiled output is visible inside of the `/dist/` folder!
52
+
53
+
54
+ ## Key Features & Examples
55
+
56
+ ### File based routing
57
+ vader's compiler automatically handles routing so you wont need to! - it uses a similar page routing to nextjs
58
+
59
+ ```bash
60
+ /pages/index.jsx = /
61
+ /pages/home/[page].jsx = /home/:page
62
+ /pages/path/index.jsx = /path/
63
+ /pages/path/[...].jsx = /path/*
64
+
65
+ ```
66
+ For pages that have [params] you can derive it using this.request
67
+
68
+
69
+ # Usage
70
+
71
+
72
+ ```jsx
73
+ // pages/home.jsx
74
+ import {Component, useState, useRef} = from 'vaderjs/client'
75
+ import Mycomponent from './src/mycomponent.jsx'
76
+
77
+
78
+ export default function(req, res){
79
+ let counterRef = useRef(null)
80
+ let [count, setCount] = useState(0)
81
+
82
+ return <>
83
+ <h1>${count}</h1>
84
+ <button onClick={(event)=>{setCount(count + 1)}}>
85
+ </>
86
+ }
87
+
88
+
89
+
90
+ ```
91
+
92
+ # ServerSide Site Generation (SSG)
93
+
94
+ Vader compiles all code to a static index.html page so your visitors will never have to wait for the page to load, it then rehydrates the page reapplying functionality!
95
+
96
+ you can always opt out of ssg using:
97
+
98
+ ```js
99
+ export const $prerender = false;
100
+ ```
101
+ We can define some metadata to be used at compile
102
+
103
+ ```jsx
104
+ // src/layout.tsx
105
+ export function Layout({title, keywords, description, children}){
106
+ return <>
107
+ <Html lang="en-us">
108
+ <Head>
109
+ <title>${title}</title>
110
+ <meta charset="utf-8" />
111
+ <meta name="description" content={description} />
112
+ <meta name="robots" content="index, follow" />
113
+ <meta name="author" content="Malik Whitten" />
114
+ <meta name="keywords" content={keywords} />
115
+ <meta name="url" content="https://malikwhitten.com" />
116
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
117
+ <link rel="icon" href={logo} />
118
+ <script src="/src/theme.js" eager> </script>
119
+ <link rel="stylesheet" href="/public/css/styles.css" />
120
+ </Head>
121
+
122
+ ${children}
123
+ </Html>
124
+ </>
125
+ }
126
+
127
+ // pages/index.jsx
128
+
129
+ //$= is a ternary operator used for spread like nesting
130
+
131
+ export default function (req, res){
132
+ return <>
133
+ <Layout $={{title:'home', description:'home page', keywords:'vader.js', logo:''}}>
134
+ <h1> Hello World</h1>
135
+ </Layout>
136
+ </>
137
+ }
138
+
139
+ ```
140
+ Vader will take the metadata and place it inside of the compiled html file.
141
+
142
+ ### Styling
143
+
144
+ Vaderjs has two types of in javascript styling - css modules and inline jsx styling
145
+ ```jsx
146
+
147
+ // inline
148
+ <button style={{color:'red'}}>Button</button>
149
+
150
+ // css module
151
+
152
+ //public/app.module.css
153
+ `
154
+ .container{
155
+ color:red;
156
+ font-size:20px
157
+ }
158
+ `
159
+
160
+ // import file
161
+ import style from 'public/app.module.css' // this gets replaced with the compiled css output
162
+
163
+ <button style={{...style.container}}>Button </button>
164
+
165
+ ```
166
+ ### State Management
167
+ Vaderjs uses partial hydration & full reflection
168
+
169
+ You can pass a reference to the dom target like an id for the element u want to change - or you can just swap the value and the entire component will rerender
170
+
171
+ ```jsx
172
+ import {Component, useState, useRef} = from 'vaderjs/client'
173
+
174
+ export default class MyApp extends Component{
175
+ contructor(){
176
+ super()
177
+ this.key = 'static key for state changes'
178
+ // or
179
+ this.nokey // disable element generation
180
+ }
181
+
182
+ render(){
183
+ let [count, setCount] = useState(0)
184
+ let ref = useRef('')
185
+
186
+ return <>
187
+ <p ref={ref.bind}>Count is ${count}</p>
188
+ ${/**
189
+ pass anything used from the toplevel render to the lowerlevel function params to be able to invoke!
190
+ **/}
191
+ <button onclick={(setCount, count, ref)=>{
192
+ setCount(count + 1, ref.bind)
193
+ }}>Increment</button>
194
+ </>
195
+
196
+ }
197
+ }
198
+ ```
199
+
200
+
201
+ ### Function Binding
202
+
203
+ Vaderjs allows you to bind functions directly to html elements just like react
204
+ there are two ways - top level invokes like below
205
+
206
+ ```javascript
207
+ // vader uses params[0] as the event target object and other parameters resolve after
208
+
209
+ function click(event, otherparams){
210
+ console.log(event.target, otherparams)
211
+ }
212
+
213
+ const hello = function(event, otherparams){
214
+
215
+ }
216
+
217
+ return <>
218
+ <button onclick={()=>click()}>Click Me</button>
219
+ </>
220
+ ```
221
+
222
+ Low level invokes are considered top level and can access - any value above the scope !!
223
+
224
+ ```jsx
225
+ let car = {
226
+ model: 'tesla',
227
+ price: 'toomiuch'
228
+ }
229
+ return <>
230
+ <button onclick={(event)=>{
231
+ console.log(car.model)
232
+ }}>Log</button>
233
+ ```
234
+
235
+
236
+
237
+
238
+
239
+
240
+ ## License
241
+
242
+ VaderJS is released under the MIT License. See the [LICENSE](https://github.com/Postr-Inc/Vader.js/blob/main/LICENSE) file for details.
243
+
244
+ ## Join the Community
245
+
246
+ Connect with the VaderJS community on [GitHub](https://github.com/Postr-Inc/Vader.js). Contribute, share feedback, and improve VaderJS for SPA development.
247
+