vaderjs 1.9.8 → 2.0.0

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.
Files changed (3) hide show
  1. package/index.ts +11 -4
  2. package/main.js +23 -7
  3. package/package.json +1 -1
package/index.ts CHANGED
@@ -3,6 +3,8 @@ let isClassComponent = function (element) {
3
3
  return element.toString().startsWith("class");
4
4
  };
5
5
 
6
+
7
+
6
8
 
7
9
 
8
10
  const memoizes = new Map();
@@ -96,8 +98,11 @@ export const A = (props: {
96
98
  if (props.openInNewTab) {
97
99
  window.open(props.href, "_blank");
98
100
  return void 0;
99
- }
100
- window.location.href = props.href;
101
+ }
102
+ window.history.pushState({}, "", props.href);
103
+ window.dispatchEvent(new Event("popstate"));
104
+ window.dispatchEvent(new Event("load"));
105
+ window.location.reload();
101
106
  return void 0;
102
107
  }
103
108
  return e("a", { ...props, onClick: handleClick }, props.children);
@@ -192,7 +197,9 @@ interface SwitchProps {
192
197
  export function Switch({ children = [] }: SwitchProps) {
193
198
  for (let child of children) {
194
199
  if (child.props.when) {
195
- return child
200
+ return { type: "div", props: {
201
+ idKey: crypto.randomUUID()
202
+ }, children: [child] };
196
203
  }
197
204
  }
198
205
  return { type: "div", props: {}, children: [] };
@@ -675,7 +682,7 @@ export class Component {
675
682
  }
676
683
  toElement() {
677
684
  let children = this.render(this.props);
678
- let el = this.parseToElement(children);
685
+ let el = this.parseToElement(children);
679
686
  el.setAttribute("idKey", this.key);
680
687
  return el;
681
688
  }
package/main.js CHANGED
@@ -218,13 +218,12 @@ async function generateApp() {
218
218
  fs.mkdirSync(path.join(process.cwd() + '/dist', path.dirname(r)), { recursive: true })
219
219
  let params = routes.match(route).params || {}
220
220
  let base = routes.match(route)
221
- let paramIndexes = []
222
- console.log(base)
221
+ let paramIndexes = []
223
222
  for (let param in params) {
224
223
  let routes = base.pathname.split('/')
225
224
  let index = routes.indexOf('[' + param + ']')
226
225
  paramIndexes.push(index)
227
- }
226
+ }
228
227
 
229
228
  // dont return
230
229
 
@@ -233,7 +232,15 @@ async function generateApp() {
233
232
  `
234
233
  let route = window.location.pathname.split('/').filter(Boolean)
235
234
  let params = {
236
- ${Object.keys(params).map(p => `${p}: route[${paramIndexes[Object.keys(params).indexOf(p)]}]`).join(',\n')}
235
+ // get index tehn do route[index]
236
+ ${Object.keys(params).map((param, i) => {
237
+ if (paramIndexes[i] !== -1) {
238
+ var r_copy = r;
239
+ r_copy = r_copy.split('/').filter(Boolean)
240
+ var index = paramIndexes[i] - 1
241
+ return `${param}: route[${index}]`
242
+ }
243
+ }).join(',\n')}
237
244
  }
238
245
 
239
246
  \n${code}
@@ -324,8 +331,7 @@ async function generateApp() {
324
331
 
325
332
  function handleFiles() {
326
333
  return new Promise(async (resolve, reject) => {
327
- try {
328
- console.log(Glob)
334
+ try {
329
335
  let glob = new Glob('public/**/*')
330
336
  for await (var i of glob.scan()) {
331
337
  let file = i
@@ -546,13 +552,23 @@ if (mode == 'development' || mode == 'serve') {
546
552
  if (mode == "development") {
547
553
  return new Response(data + `
548
554
  <script>
549
- let ws = new WebSocket('ws://localhost:${server.port}')
555
+ let ws = new WebSocket(\`\${location.protocol === 'https:' ? 'wss' : 'ws'}://\${location.host}\`)
550
556
  ws.onmessage = (e) => {
551
557
  if(e.data === 'reload'){
552
558
  console.log('Reloading to display changes from server')
553
559
  window.location.reload()
554
560
  }
555
561
  }
562
+ ws.onopen = () => {
563
+ console.log('Connected to hmr server')
564
+ }
565
+
566
+ ws.onclose = () => {
567
+ // try to reconnect
568
+ console.log('Reconnecting to hmr server')
569
+ ws = new WebSocket(\`\${location.protocol === 'https:' ? 'wss' : 'ws'}://\${location.host}\`)
570
+ }
571
+
556
572
  </script>
557
573
  `, {
558
574
  headers: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vaderjs",
3
- "version": "1.9.8",
3
+ "version": "2.0.0",
4
4
  "description": "A simple and powerful JavaScript library for building modern web applications.",
5
5
  "bin": {
6
6
  "vaderjs": "./main.js"