vaderjs 1.0.4 → 1.0.6
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 +1 -1
- package/readme.md +4 -2
- package/vader.js +14 -18
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -80,7 +80,7 @@ import { vhtml, component, rf } from './script.js'
|
|
|
80
80
|
|
|
81
81
|
const app = component('app', {
|
|
82
82
|
render: (states) => {
|
|
83
|
-
let [count, setCount] = useState(
|
|
83
|
+
let [count, setCount] = useState( 0);
|
|
84
84
|
useEffect(() => {
|
|
85
85
|
console.log(states)
|
|
86
86
|
console.log('App component mounted');
|
|
@@ -106,7 +106,9 @@ const app = component('app', {
|
|
|
106
106
|
},
|
|
107
107
|
})
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
(async ()=>{
|
|
110
|
+
document.body.innerHTML = await app.render()
|
|
111
|
+
})
|
|
110
112
|
```
|
|
111
113
|
|
|
112
114
|
## Get Started
|
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 = (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
const useState = ( initialValue) => {
|
|
100
|
+
let state = states[name];
|
|
101
|
+
if (!state) {
|
|
102
|
+
state = initialValue;
|
|
103
|
+
states[name] = state;
|
|
103
104
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
|
@@ -311,14 +309,14 @@ export function component(name, options) {
|
|
|
311
309
|
window.useAuth = useAuth;
|
|
312
310
|
window.useSyncStore = useSyncStore;
|
|
313
311
|
|
|
314
|
-
const updateComponent = () => {
|
|
312
|
+
const updateComponent = async () => {
|
|
315
313
|
const componentContainer = document.querySelector(
|
|
316
314
|
`[data-component="${name}"]`
|
|
317
315
|
);
|
|
318
316
|
if (componentContainer) {
|
|
319
317
|
runEffects;
|
|
320
318
|
|
|
321
|
-
componentContainer.innerHTML = options.render(
|
|
319
|
+
componentContainer.innerHTML = await options.render(
|
|
322
320
|
states,
|
|
323
321
|
(storedProps = null)
|
|
324
322
|
);
|
|
@@ -338,13 +336,11 @@ export function component(name, options) {
|
|
|
338
336
|
const componentContainer = document.querySelector(
|
|
339
337
|
`[data-component="${name}"]`
|
|
340
338
|
);
|
|
339
|
+
|
|
341
340
|
if (componentContainer) {
|
|
342
341
|
runEffects();
|
|
343
342
|
|
|
344
|
-
componentContainer.innerHTML =
|
|
345
|
-
states,
|
|
346
|
-
(storedProps = null)
|
|
347
|
-
);
|
|
343
|
+
componentContainer.innerHTML = await options.render( states, props);
|
|
348
344
|
} else {
|
|
349
345
|
return vhtml`
|
|
350
346
|
<div data-component="${name}">
|