vaderjs 1.3.3-alpha-23 → 1.3.3-alpha-24
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/runtime/router.js +3 -0
- package/runtime/vader.js +18 -7
- package/vader.js +8 -4
package/package.json
CHANGED
package/runtime/router.js
CHANGED
|
@@ -225,6 +225,9 @@ class VaderRouter{
|
|
|
225
225
|
if(!document.querySelector('#root')){
|
|
226
226
|
throw new Error('Root element not found, please add an element with id root');
|
|
227
227
|
}
|
|
228
|
+
Component.state = {}
|
|
229
|
+
Component.reset();
|
|
230
|
+
Component.components = {}
|
|
228
231
|
Component.request = req;
|
|
229
232
|
Component.response = res;
|
|
230
233
|
document.querySelector('#root').innerHTML = Component.render()
|
package/runtime/vader.js
CHANGED
|
@@ -257,10 +257,21 @@ export class Component {
|
|
|
257
257
|
comp.response = this.response;
|
|
258
258
|
comp.key = props.key || null;
|
|
259
259
|
|
|
260
|
+
if(!this.components[props.key]){
|
|
261
|
+
states[props.key] = {}
|
|
262
|
+
}
|
|
260
263
|
this.components[props.key] = comp
|
|
261
264
|
this.children.push(comp)
|
|
262
265
|
return this.components[props.key]
|
|
263
266
|
}
|
|
267
|
+
reset(){
|
|
268
|
+
Object.keys(this.components).forEach((key) => {
|
|
269
|
+
states[key] = {}
|
|
270
|
+
})
|
|
271
|
+
states[this.key] = {}
|
|
272
|
+
this.components = {}
|
|
273
|
+
this.children = []
|
|
274
|
+
}
|
|
264
275
|
memoize(/**@type {Component}**/component){
|
|
265
276
|
if(!component.key){
|
|
266
277
|
throw new Error('Component must have a static key')
|
|
@@ -273,7 +284,7 @@ export class Component {
|
|
|
273
284
|
}
|
|
274
285
|
|
|
275
286
|
let comp = this.components[component.key];
|
|
276
|
-
comp.props = component.props;
|
|
287
|
+
comp.props = component.props;
|
|
277
288
|
let h = comp.render()
|
|
278
289
|
|
|
279
290
|
if(h && h.split('>,').length > 1){
|
|
@@ -542,9 +553,9 @@ export class Component {
|
|
|
542
553
|
* @param {T} initialState - The initial state value.
|
|
543
554
|
* @returns {[() => T, (newValue: T, hook: Function) => void]} - A tuple with getter and setter functions.
|
|
544
555
|
*/
|
|
545
|
-
useState(key, initialState) {
|
|
546
|
-
if (!this.
|
|
547
|
-
this.
|
|
556
|
+
useState(key, initialState) {
|
|
557
|
+
if (!states[this.key][key]) {
|
|
558
|
+
states[this.key][key] = initialState;
|
|
548
559
|
}
|
|
549
560
|
|
|
550
561
|
/**
|
|
@@ -552,7 +563,7 @@ export class Component {
|
|
|
552
563
|
*
|
|
553
564
|
* @returns {T} The current state value.
|
|
554
565
|
*/
|
|
555
|
-
let updatedValue = () => this.
|
|
566
|
+
let updatedValue = () => states[this.key][key];
|
|
556
567
|
|
|
557
568
|
const getValue = updatedValue();
|
|
558
569
|
|
|
@@ -563,13 +574,13 @@ export class Component {
|
|
|
563
574
|
* @param {Function} hook - The hook to hydrate after setting the value.
|
|
564
575
|
*/
|
|
565
576
|
const set = (newValue, hook) => {
|
|
566
|
-
this.
|
|
577
|
+
states[this.key][key] = newValue;
|
|
567
578
|
this.hydrate(hook);
|
|
568
579
|
};
|
|
569
580
|
|
|
570
581
|
|
|
571
582
|
|
|
572
|
-
return [
|
|
583
|
+
return [getValue, set];
|
|
573
584
|
}
|
|
574
585
|
|
|
575
586
|
|
package/vader.js
CHANGED
|
@@ -226,11 +226,13 @@ function Compiler(func) {
|
|
|
226
226
|
|
|
227
227
|
let paramString = params ? params.split(' ').map(param => param + ',').join('') : "";
|
|
228
228
|
|
|
229
|
+
paramString = paramString.replaceAll(',,', ',')
|
|
230
|
+
let jsxAttribute = `${attributeName}=function(${paramString}){${newvalue}},`
|
|
229
231
|
let newatribute = `${attributeName}="\${this.bind(\`${newvalue}\`, ${isJSXComponent ? true : false}, '${ref}', "${paramString}", ${params || null})}",`
|
|
230
232
|
|
|
231
233
|
attribute[attributeName] = {
|
|
232
234
|
old: old,
|
|
233
|
-
new: newatribute,
|
|
235
|
+
new: isJSXComponent ? jsxAttribute : newatribute,
|
|
234
236
|
attribute: attributeName,
|
|
235
237
|
};
|
|
236
238
|
attributesList.push({
|
|
@@ -262,9 +264,11 @@ function Compiler(func) {
|
|
|
262
264
|
// since js is all in one line split it
|
|
263
265
|
newvalue = newvalue.split('\n').map(line => line.trim() ? line.trim() + ';' : line).join('\n');
|
|
264
266
|
let paramString = params ? params.split(' ').map(param => param + ',').join('') : "";
|
|
267
|
+
paramString = paramString.replaceAll(',,', ',')
|
|
268
|
+
let jsxAttribute = `${attributeName}=function(${paramString}){${newvalue}},`
|
|
265
269
|
let newattribute = `${attributeName}="\${this.bind(\`${newvalue}\`, ${isJSXComponent ? true : false}, '${ref}', "${paramString}", ${params || null})}",`
|
|
266
270
|
newattribute = newattribute.replace(/\s+/g, " ")
|
|
267
|
-
string = string.replace(old, newattribute);
|
|
271
|
+
string = string.replace(old, isJSXComponent ? jsxAttribute : newattribute);
|
|
268
272
|
}
|
|
269
273
|
}
|
|
270
274
|
}
|
|
@@ -566,10 +570,10 @@ function Compiler(func) {
|
|
|
566
570
|
.replaceAll('=`', ':`')
|
|
567
571
|
.replaceAll(`={\``, ':`')
|
|
568
572
|
.replaceAll('`}', '`')
|
|
573
|
+
.replaceAll(",,", ',')
|
|
569
574
|
|
|
570
575
|
.replaceAll(/=([A-z])/g, ":$1")
|
|
571
|
-
props = props.replace(/:('[^']*'|"[^"]*")/g, ':$1,');
|
|
572
|
-
props = props.replace(/:('[^']*'|"[^"]*")/g, ':$1,');
|
|
576
|
+
props = props.replace(/:('[^']*'|"[^"]*")/g, ':$1,');
|
|
573
577
|
// ANY VALUE NUMBER BOOLEAN OR STRING
|
|
574
578
|
props = props.replace(/=(\d+)/g, ':$1,');
|
|
575
579
|
props = props.replaceAll(',,', ',')
|