vaderjs 1.9.9 → 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 +11 -1
  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
@@ -552,13 +552,23 @@ if (mode == 'development' || mode == 'serve') {
552
552
  if (mode == "development") {
553
553
  return new Response(data + `
554
554
  <script>
555
- let ws = new WebSocket('ws://localhost:${server.port}')
555
+ let ws = new WebSocket(\`\${location.protocol === 'https:' ? 'wss' : 'ws'}://\${location.host}\`)
556
556
  ws.onmessage = (e) => {
557
557
  if(e.data === 'reload'){
558
558
  console.log('Reloading to display changes from server')
559
559
  window.location.reload()
560
560
  }
561
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
+
562
572
  </script>
563
573
  `, {
564
574
  headers: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vaderjs",
3
- "version": "1.9.9",
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"