vaderjs 1.0.3 → 1.0.5

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/jsconfig.json CHANGED
@@ -2,8 +2,13 @@
2
2
  "compilerOptions": {
3
3
  "allowJs": true,
4
4
  "checkJs": true,
5
-
5
+ "jsx": "react",
6
+ "module": "esnext",
7
+ "moduleResolution": "node",
8
+ "noEmit": true,
9
+ "strict": true, // Enforce strict type checking
10
+ "forceConsistentCasingInFileNames": true, // Ensures consistent file name casing
11
+ "noImplicitAny": true,
6
12
  },
7
- "include": ["/"],
8
-
9
- }
13
+ "include": ["/"]
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vaderjs",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "A Reactive Framework for Single-Page Applications (SPA)",
5
5
  "main": "vader.js",
6
6
  "scripts": {
package/vader.js CHANGED
@@ -96,19 +96,17 @@ export function component(name, options) {
96
96
  * @returns {Array} [state, setState]
97
97
  * @description Allows you to bind state to component
98
98
  */
99
- const useState = (key, initialValue) => {
100
- if (!(key in states)) {
101
- states[key] = initialValue;
102
- window.props[key] = initialValue;
99
+ const useState = ( initialValue) => {
100
+ let state = states[name];
101
+ if (!state) {
102
+ state = initialValue;
103
+ states[name] = state;
103
104
  }
104
-
105
- /**
106
- * @Array state
107
- * @param {*} states
108
- * @description Allows you to get state of component
109
- */
110
-
111
- return [states[key], (newValue) => setState(key, newValue)];
105
+ const setState = (value) => {
106
+ states[name] = value;
107
+ updateComponent();
108
+ }
109
+ return [state, setState];
112
110
  };
113
111
  /**
114
112
  * @function useEffect
@@ -310,14 +308,15 @@ export function component(name, options) {
310
308
  window.useEffect = useEffect;
311
309
  window.useAuth = useAuth;
312
310
  window.useSyncStore = useSyncStore;
313
- const updateComponent = () => {
311
+
312
+ const updateComponent = async () => {
314
313
  const componentContainer = document.querySelector(
315
314
  `[data-component="${name}"]`
316
315
  );
317
316
  if (componentContainer) {
318
317
  runEffects;
319
318
 
320
- componentContainer.innerHTML = options.render(
319
+ componentContainer.innerHTML = await options.render(
321
320
  states,
322
321
  (storedProps = null)
323
322
  );
@@ -332,22 +331,20 @@ export function component(name, options) {
332
331
  * @returns
333
332
  */
334
333
 
335
- const render = (props) => {
334
+ const render = async (props) => {
336
335
  storedProps = props;
337
336
  const componentContainer = document.querySelector(
338
337
  `[data-component="${name}"]`
339
338
  );
339
+
340
340
  if (componentContainer) {
341
341
  runEffects();
342
342
 
343
- componentContainer.innerHTML = options.render(
344
- states,
345
- (storedProps = null)
346
- );
343
+ componentContainer.innerHTML = await options.render( states, props);
347
344
  } else {
348
345
  return vhtml`
349
346
  <div data-component="${name}">
350
- ${options.render(
347
+ ${await options.render(
351
348
  states,
352
349
  props
353
350
  )}
@@ -371,3 +368,22 @@ export function component(name, options) {
371
368
  export const rf = (name, fn) => {
372
369
  window[name] = fn;
373
370
  };
371
+ /**
372
+ * @function include
373
+ * @description Allows you to include html file
374
+ * @returns - modified string with html content
375
+ * @param {string} path
376
+ */
377
+
378
+ export const include = (path) => {
379
+ return fetch(`./${path}`)
380
+ .then((res) => {
381
+ if(res.status === 404){
382
+ throw new Error(`No file found at ${path}`)
383
+ }
384
+ return res.text()
385
+ })
386
+ .then((data) => {
387
+ return new Function(`return \`${data}\`;`)()
388
+ })
389
+ };
package/vaderRouter.js CHANGED
@@ -81,7 +81,15 @@ class VaderRouter {
81
81
  status: 404,
82
82
  message: "Page not found",
83
83
  };
84
- this.handleError("404", errBody);
84
+ const res = {
85
+ return: function (data) {
86
+ this.hooked = false;
87
+ },
88
+ render: function (selector, data) {
89
+ document.querySelector(selector).innerHTML = data;
90
+ }
91
+ }
92
+ this.handleError("404", errBody, res);
85
93
  }
86
94
  });
87
95
  }
@@ -111,9 +119,9 @@ class VaderRouter {
111
119
  * @description used by start() to handle errors.
112
120
  */
113
121
 
114
- handleError(type, data) {
122
+ handleError(type, data, res) {
115
123
  if (this.errorHandlers[type]) {
116
- this.errorHandlers[type](data);
124
+ this.errorHandlers[type](data, res);
117
125
  } else {
118
126
  console.error(`No error handler found for type: ${type}`);
119
127
  }
@@ -1,20 +0,0 @@
1
- <header>
2
- <div>
3
- <h1>Header</h1>
4
- <test
5
- ${props.styles}
6
- >${props.color}</test>
7
-
8
- ${
9
- function(){
10
-
11
- if(props.color === 'red'){
12
- return `<h1>Red</h1>`
13
- }else{
14
- return `<h1>Not Red</h1>`
15
- }
16
-
17
- }()
18
- }
19
- </div>
20
- </header>
package/config.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "port": 3001,
3
- "type": "http",
4
- "origin": "http://localhost:3000",
5
- "path": "/api"
6
-
7
- }