vaderjs 1.3.3-alpha-41 → 1.3.3-alpha-43

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/package.json CHANGED
@@ -2,10 +2,19 @@
2
2
  "name": "vaderjs",
3
3
  "description": "A Reactive library aimed to helping you build reactive applications inspired by react.js",
4
4
  "module": "vader.js",
5
- "version": "1.3.3-alpha-41",
5
+ "version": "1.3.3-alpha-43",
6
6
  "bin": {
7
7
  "vader": "./vader.js"
8
8
  },
9
+ "keywords": [
10
+ "react",
11
+ "reactive",
12
+ "nextjs",
13
+ "pages router",
14
+ "spa",
15
+ "vanillajs",
16
+ "vanilla js"
17
+ ],
9
18
  "type": "module",
10
19
  "license": "MIT",
11
20
  "homepage": "https://vader-js.pages.dev/#/",
package/runtime/router.js CHANGED
@@ -236,16 +236,11 @@ class VaderRouter{
236
236
  },
237
237
  render: async (/**@type {Component} */ Component, req, res) => {
238
238
  try {
239
- // Check if the component is valid
240
- if (!Component || !Component.default || !Component.constructor) {
241
- let message = !Component || !Component.default ? 'default' : 'constructor';
242
- switch (message) {
243
- case 'default':
244
- throw new Error(`Component must have a default export ex: return {default: Component}`);
245
- case 'constructor':
246
- throw new Error(`Component is invalid, please check the constructor`);
247
- }
239
+ if(!Component.default || !Component.default.constructor){
240
+ let message = !Component.default ? `Router expected a default exported component ie: export default class Component` : !Component.default.constructor ? 'Component is not a class' : null;
241
+ throw new Error(message);
248
242
  }
243
+
249
244
 
250
245
  // Create an instance of the component
251
246
  Component = Component.default ? new Component.default() : Component.constructor ? new Component() : Component;
@@ -266,6 +261,7 @@ class VaderRouter{
266
261
 
267
262
  // Check if the component has a router and is not a child component
268
263
  if (Component.router.use && !Component.isChild) {
264
+
269
265
  // Allow pausing the route and run code before rendering
270
266
  await new Promise(async (resolve) => {
271
267
  await Component.router.use(req, res)
@@ -276,6 +272,8 @@ class VaderRouter{
276
272
  clearInterval(timer);
277
273
  }
278
274
  }, 1000);
275
+ }else{
276
+ resolve();
279
277
  }
280
278
  });
281
279
  } else if (Component.router.use && Component.isChild) {
@@ -302,19 +300,22 @@ class VaderRouter{
302
300
  send: (data) => {
303
301
  document.querySelector('#root').innerHTML = data;
304
302
  },
305
- json: (selector, data) => {
306
-
307
- if(typeof selector === 'string'){
308
- // @ts-ignore
309
- let obj = document.createElement('object');
310
- // data url
311
- obj.data = URL.createObjectURL(new Blob([JSON.stringify(data)], {type: 'application/json'}));
312
- // @ts-ignore
313
- document.querySelector(selector).appendChild(obj);
314
- }else{
315
- throw new Error('Selector must be a string');
316
- }
317
- }
303
+ json: (data) => {
304
+ const rootElement = document.querySelector('#root');
305
+
306
+ // Clear existing content in #root
307
+ rootElement.innerHTML = '';
308
+
309
+ // Create a <pre> element
310
+ const preElement = document.createElement('pre');
311
+
312
+ // Set the text content of the <pre> element with formatted JSON
313
+ preElement.textContent = JSON.stringify(data, null, 2);
314
+
315
+ // Append the <pre> element to the #root element
316
+ rootElement.appendChild(preElement);
317
+ }
318
+
318
319
  };
319
320
  middlewares.forEach((middleware) => {
320
321
  middleware(req, res);