small tweaks to start on ternaries
This commit is contained in:
@@ -21,6 +21,10 @@ document.body.append(
|
||||
)
|
||||
```
|
||||
|
||||
## Needs Support:
|
||||
Ternaries within render()
|
||||
Other statements within render()
|
||||
|
||||
## Boilerplate:
|
||||
- ```*html```: Type in an HTML file and select the suggestion to create HTML boilerplate.
|
||||
- ```*element```: Type in a JS file and select the suggestion to create JS Custom Element boilerplate.
|
||||
|
||||
@@ -149,6 +149,13 @@ window.testSuites.push( class testParse {
|
||||
window.Registry.parseConstructor(Space)
|
||||
}
|
||||
|
||||
// CopyTo() {
|
||||
// let str = "render=()=>{VStack(()=>{"
|
||||
// let ret = str.copyTo("{")
|
||||
|
||||
// if(ret !== "render=()=>") return "Copy 1 failed!"
|
||||
// }
|
||||
|
||||
ParseRender() {
|
||||
class Sidebar extends Shadow {
|
||||
$$windowState = windowState
|
||||
@@ -177,7 +184,7 @@ window.testSuites.push( class testParse {
|
||||
}
|
||||
}
|
||||
|
||||
let result = Registry.parseRender(Sidebar)
|
||||
let result = new Registry.parseRender(Sidebar).parse()
|
||||
console.log(result)
|
||||
|
||||
let expectedOutput = "[[VStack.ForEach, form.children], [VStack.x, windowState.sidebarOut]]"
|
||||
@@ -187,12 +194,4 @@ window.testSuites.push( class testParse {
|
||||
}
|
||||
}
|
||||
|
||||
CopyTo() {
|
||||
let str = "render=()=>{VStack(()=>{"
|
||||
let ret = str.copyTo("{")
|
||||
console.log(ret)
|
||||
|
||||
if(ret !== "render=()=>") return "Copy 1 failed!"
|
||||
}
|
||||
|
||||
})
|
||||
@@ -2,9 +2,9 @@ console.log("Tests initializing.")
|
||||
window.testSuites = [];
|
||||
|
||||
await import ("./parse.test.js")
|
||||
// await import ("./init.test.js")
|
||||
// await import ("./render.test.js")
|
||||
// await import ("./observedobject.test.js")
|
||||
await import ("./init.test.js")
|
||||
await import ("./render.test.js")
|
||||
await import ("./observedobject.test.js")
|
||||
|
||||
window.randomName = function randomName(prefix) {
|
||||
const sanitizedPrefix = prefix.toLowerCase().replace(/[^a-z0-9]/g, '');
|
||||
|
||||
127
index.js
127
index.js
@@ -233,11 +233,15 @@ class ObservedObject {
|
||||
for (let property of properties) {
|
||||
if(property === "children") {
|
||||
Registry.rerender(observer)
|
||||
} else {
|
||||
if(Array.isArray(property)) {
|
||||
observer[property[0]][property[1]] = newValue;
|
||||
} else {
|
||||
observer[property] = newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
get: function() {
|
||||
if(Registry.lastState) {
|
||||
@@ -499,13 +503,6 @@ window.Registry = class Registry {
|
||||
|
||||
/* DEFAULT WRAPPERS */
|
||||
|
||||
window.ForEach = function (arr, cb) {
|
||||
Registry.initReactivity(window.rendering.last(), "children", arr)
|
||||
arr.forEach((el, i) => {
|
||||
cb(el, i)
|
||||
})
|
||||
}
|
||||
|
||||
window.a = function a({ href, name=href } = {}) {
|
||||
let link = document.createElement("a")
|
||||
link.setAttribute('href', href);
|
||||
@@ -545,7 +542,14 @@ window.span = function (innerText) {
|
||||
return span
|
||||
}
|
||||
|
||||
/* STACKS */
|
||||
/* CUSTOM */
|
||||
|
||||
window.ForEach = function (arr, cb) {
|
||||
Registry.initReactivity(window.rendering.last(), "children", arr)
|
||||
arr.forEach((el, i) => {
|
||||
cb(el, i)
|
||||
})
|
||||
}
|
||||
|
||||
window.VStack = function (cb = () => {}) {
|
||||
let nowRendering = window.rendering.last()
|
||||
@@ -859,64 +863,85 @@ Registry.getRender = function(classObject) {
|
||||
}
|
||||
}
|
||||
|
||||
Registry.parseRender = class ParseRender {
|
||||
str;
|
||||
i = 0;
|
||||
functionStack;
|
||||
result;
|
||||
|
||||
Registry.parseRender = function(classObject) {
|
||||
let str = Registry.getRender(classObject.toString()).replace(/\s/g, "");
|
||||
console.log(str)
|
||||
let functionStack = []
|
||||
let i = str.indexOf("{");
|
||||
/*
|
||||
[
|
||||
[Function scope, value used]
|
||||
["VStack.ForEach", "form.children"],
|
||||
["VStack.ForEach.SidebarFile", "form.color"]
|
||||
["VStack.x", windowState.sidebarOut]
|
||||
]
|
||||
*/
|
||||
|
||||
constructor(classObject) {
|
||||
this.str = Registry.getRender(classObject.toString()).replace(/\s/g, "");
|
||||
this.functionStack = ""
|
||||
this.result = []
|
||||
}
|
||||
|
||||
parse() {
|
||||
this.parseFunction()
|
||||
return this.result
|
||||
}
|
||||
|
||||
parseFunction() {
|
||||
console.log(this.str)
|
||||
this.copyTo("{")
|
||||
let firstEl = this.copyTo("(")
|
||||
console.log(firstEl)
|
||||
|
||||
let firstEl = str.copyTo("(", i)
|
||||
if(!firstEl) {
|
||||
console.log("Empty render function")
|
||||
return
|
||||
} else {
|
||||
i += firstEl.length + 1
|
||||
}
|
||||
|
||||
if(firstEl.includes("Stack")) {
|
||||
parseArrowFunction(str, i)
|
||||
this.parseFunction()
|
||||
} else if(firstEl.includes("ForEach")) {
|
||||
let array = this.copyTo(",")
|
||||
if(array.includes("this")) {
|
||||
console.log(this.result)
|
||||
this.result.push([this.functionStack + "ForEach", array.replace("this.", "")])
|
||||
}
|
||||
this.parseFunction()
|
||||
} else if(firstEl === "switch") {
|
||||
|
||||
return usage;
|
||||
}
|
||||
|
||||
function parseArrowFunction(str, i) {
|
||||
i += str.copyTo("{", i).length + 1
|
||||
console.log(str[i])
|
||||
let firstEl = str.copyTo("(", i)
|
||||
console.log(firstEl)
|
||||
}
|
||||
|
||||
function firstParam(str, i) {
|
||||
console.log(str[i])
|
||||
switch(str[i]) {
|
||||
case "(":
|
||||
console.log("function")
|
||||
break;
|
||||
case "\"":
|
||||
console.log("string")
|
||||
break;
|
||||
default:
|
||||
if (!isNaN(input)) {
|
||||
console.log("Number");
|
||||
} else {
|
||||
console.log("Variable");
|
||||
} else if(firstEl === ("if")) {
|
||||
console.log("if")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String.prototype.copyTo = function(char, i=0) {
|
||||
let copied = ""
|
||||
while(this[i]) {
|
||||
if(this[i] === char) {
|
||||
break;
|
||||
}
|
||||
copied += this[i]
|
||||
copyTo = function(char) {
|
||||
this.i = this.str.indexOf(char)
|
||||
let copied = this.str.substring(0, this.str.indexOf(char));
|
||||
this.str = this.str.slice(this.i + 1); // Update the string to exclude the copied part and the character
|
||||
|
||||
i++
|
||||
}
|
||||
return copied
|
||||
}
|
||||
|
||||
// firstParam(str, i, stack, total) {
|
||||
// console.log(str[i])
|
||||
// switch(str[i]) {
|
||||
// case "(":
|
||||
// console.log("function")
|
||||
// break;
|
||||
// case "\"":
|
||||
// console.log("string")
|
||||
// break;
|
||||
// default:
|
||||
// if (!isNaN(input)) {
|
||||
// console.log("Number");
|
||||
// } else {
|
||||
// console.log("Variable");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
window.register = Registry.register
|
||||
|
||||
Reference in New Issue
Block a user