vaderjs 1.3.2 → 1.3.3-5b5a772ebe58

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,243 @@
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
+
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={(count, setCount)=>{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
+ export default function (req, res){
130
+ return <>
131
+ <Layout {...{title:'home', description:'home page', keywords:'vader.js', logo:''}}>
132
+ <h1> Hello World</h1>
133
+ </Layout>
134
+ </>
135
+ }
136
+
137
+ ```
138
+ Vader will take the metadata and place it inside of the compiled html file.
139
+
140
+ ### Styling
141
+
142
+ Vaderjs has two types of in javascript styling - css modules and inline jsx styling
143
+ ```jsx
144
+
145
+ // inline
146
+ <button style={{color:'red'}}>Button</button>
147
+
148
+ // css module
149
+
150
+ //public/app.module.css
151
+ `
152
+ .container{
153
+ color:red;
154
+ font-size:20px
155
+ }
156
+ `
157
+
158
+ // import file
159
+ import style from 'public/app.module.css' // this gets replaced with the compiled css output
160
+
161
+ <button style={{...style.container}}>Button </button>
162
+
163
+ ```
164
+ ### State Management
165
+ Vaderjs uses partial hydration & full reflection
166
+
167
+ 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
168
+
169
+ ```jsx
170
+ import {Component, useState, useRef} = from 'vaderjs/client'
171
+
172
+ export default class MyApp extends Component{
173
+ contructor(){
174
+ super()
175
+ this.key = 'static key for state changes'
176
+ }
177
+
178
+ render(){
179
+ let [count, setCount] = useState(0)
180
+ let ref = useRef('')
181
+
182
+ return <>
183
+ <p ref={ref.bind}>Count is ${count}</p>
184
+ ${/**
185
+ pass anything used from the toplevel render to the lowerlevel function params to be able to invoke!
186
+ **/}
187
+ <button onclick={(setCount, count, ref)=>{
188
+ setCount(count + 1, ref.bind)
189
+ }}>Increment</button>
190
+ </>
191
+
192
+ }
193
+ }
194
+ ```
195
+
196
+
197
+ ### Function Binding
198
+
199
+ Vaderjs allows you to bind functions directly to html elements just like react
200
+ there are two ways - top level invokes like below
201
+
202
+ ```javascript
203
+ // vader uses params[0] as the event target object and other parameters resolve after
204
+
205
+ function click(event, otherparams){
206
+ console.log(event.target, otherparams)
207
+ }
208
+
209
+ const hello = function(event, otherparams){
210
+
211
+ }
212
+
213
+ return <>
214
+ <button onclick={()=>click()}>Click Me</button>
215
+ </>
216
+ ```
217
+
218
+ and lower level invokes - these operate the same just allow you to pass items from top level to lower level: ex - I have a variable named car and i want the button to log it i can pass it as a parameter to allow it to be added to the buttons function scope
219
+
220
+ ```jsx
221
+ let car = {
222
+ model: 'tesla',
223
+ price: 'toomiuch'
224
+ }
225
+ return <>
226
+ <button onclick={(car)=>{
227
+ console.log(car.model)
228
+ }}>Log</button>
229
+ ```
230
+
231
+
232
+
233
+
234
+
235
+
236
+ ## License
237
+
238
+ VaderJS is released under the MIT License. See the [LICENSE](https://github.com/Postr-Inc/Vader.js/blob/main/LICENSE) file for details.
239
+
240
+ ## Join the Community
241
+
242
+ Connect with the VaderJS community on [GitHub](https://github.com/Postr-Inc/Vader.js). Contribute, share feedback, and improve VaderJS for SPA development.
243
+