small tweaks to start on ternaries

This commit is contained in:
metacryst
2024-04-11 17:48:26 -05:00
parent 95e90568db
commit 4c351197aa
4 changed files with 98 additions and 70 deletions

View File

@@ -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.

View File

@@ -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!"
}
})

View File

@@ -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, '');

141
index.js
View File

@@ -234,7 +234,11 @@ class ObservedObject {
if(property === "children") {
Registry.rerender(observer)
} else {
observer[property] = newValue;
if(Array.isArray(property)) {
observer[property[0]][property[1]] = newValue;
} else {
observer[property] = newValue;
}
}
}
}
@@ -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]
]
*/
let firstEl = str.copyTo("(", i)
if(!firstEl) {
console.log("Empty render function")
return
} else {
i += firstEl.length + 1
constructor(classObject) {
this.str = Registry.getRender(classObject.toString()).replace(/\s/g, "");
this.functionStack = ""
this.result = []
}
if(firstEl.includes("Stack")) {
parseArrowFunction(str, i)
parse() {
this.parseFunction()
return this.result
}
return usage;
}
parseFunction() {
console.log(this.str)
this.copyTo("{")
let firstEl = this.copyTo("(")
console.log(firstEl)
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");
}
}
}
String.prototype.copyTo = function(char, i=0) {
let copied = ""
while(this[i]) {
if(this[i] === char) {
break;
if(!firstEl) {
console.log("Empty render function")
return
}
if(firstEl.includes("Stack")) {
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") {
} else if(firstEl === ("if")) {
console.log("if")
}
copied += this[i]
i++
}
return copied
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
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