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:
|
## Boilerplate:
|
||||||
- ```*html```: Type in an HTML file and select the suggestion to create HTML 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.
|
- ```*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)
|
window.Registry.parseConstructor(Space)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CopyTo() {
|
||||||
|
// let str = "render=()=>{VStack(()=>{"
|
||||||
|
// let ret = str.copyTo("{")
|
||||||
|
|
||||||
|
// if(ret !== "render=()=>") return "Copy 1 failed!"
|
||||||
|
// }
|
||||||
|
|
||||||
ParseRender() {
|
ParseRender() {
|
||||||
class Sidebar extends Shadow {
|
class Sidebar extends Shadow {
|
||||||
$$windowState = windowState
|
$$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)
|
console.log(result)
|
||||||
|
|
||||||
let expectedOutput = "[[VStack.ForEach, form.children], [VStack.x, windowState.sidebarOut]]"
|
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 = [];
|
window.testSuites = [];
|
||||||
|
|
||||||
await import ("./parse.test.js")
|
await import ("./parse.test.js")
|
||||||
// await import ("./init.test.js")
|
await import ("./init.test.js")
|
||||||
// await import ("./render.test.js")
|
await import ("./render.test.js")
|
||||||
// await import ("./observedobject.test.js")
|
await import ("./observedobject.test.js")
|
||||||
|
|
||||||
window.randomName = function randomName(prefix) {
|
window.randomName = function randomName(prefix) {
|
||||||
const sanitizedPrefix = prefix.toLowerCase().replace(/[^a-z0-9]/g, '');
|
const sanitizedPrefix = prefix.toLowerCase().replace(/[^a-z0-9]/g, '');
|
||||||
|
|||||||
141
index.js
141
index.js
@@ -234,7 +234,11 @@ class ObservedObject {
|
|||||||
if(property === "children") {
|
if(property === "children") {
|
||||||
Registry.rerender(observer)
|
Registry.rerender(observer)
|
||||||
} else {
|
} 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 */
|
/* 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 } = {}) {
|
window.a = function a({ href, name=href } = {}) {
|
||||||
let link = document.createElement("a")
|
let link = document.createElement("a")
|
||||||
link.setAttribute('href', href);
|
link.setAttribute('href', href);
|
||||||
@@ -545,7 +542,14 @@ window.span = function (innerText) {
|
|||||||
return span
|
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 = () => {}) {
|
window.VStack = function (cb = () => {}) {
|
||||||
let nowRendering = window.rendering.last()
|
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)
|
[Function scope, value used]
|
||||||
let functionStack = []
|
["VStack.ForEach", "form.children"],
|
||||||
let i = str.indexOf("{");
|
["VStack.ForEach.SidebarFile", "form.color"]
|
||||||
|
["VStack.x", windowState.sidebarOut]
|
||||||
|
]
|
||||||
|
*/
|
||||||
|
|
||||||
let firstEl = str.copyTo("(", i)
|
constructor(classObject) {
|
||||||
if(!firstEl) {
|
this.str = Registry.getRender(classObject.toString()).replace(/\s/g, "");
|
||||||
console.log("Empty render function")
|
this.functionStack = ""
|
||||||
return
|
this.result = []
|
||||||
} else {
|
|
||||||
i += firstEl.length + 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(firstEl.includes("Stack")) {
|
parse() {
|
||||||
parseArrowFunction(str, i)
|
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) {
|
if(!firstEl) {
|
||||||
i += str.copyTo("{", i).length + 1
|
console.log("Empty render function")
|
||||||
console.log(str[i])
|
return
|
||||||
let firstEl = str.copyTo("(", i)
|
}
|
||||||
console.log(firstEl)
|
|
||||||
}
|
if(firstEl.includes("Stack")) {
|
||||||
|
this.parseFunction()
|
||||||
function firstParam(str, i) {
|
} else if(firstEl.includes("ForEach")) {
|
||||||
console.log(str[i])
|
let array = this.copyTo(",")
|
||||||
switch(str[i]) {
|
if(array.includes("this")) {
|
||||||
case "(":
|
console.log(this.result)
|
||||||
console.log("function")
|
this.result.push([this.functionStack + "ForEach", array.replace("this.", "")])
|
||||||
break;
|
}
|
||||||
case "\"":
|
this.parseFunction()
|
||||||
console.log("string")
|
} else if(firstEl === "switch") {
|
||||||
break;
|
|
||||||
default:
|
} else if(firstEl === ("if")) {
|
||||||
if (!isNaN(input)) {
|
console.log("if")
|
||||||
console.log("Number");
|
|
||||||
} else {
|
|
||||||
console.log("Variable");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String.prototype.copyTo = function(char, i=0) {
|
|
||||||
let copied = ""
|
|
||||||
while(this[i]) {
|
|
||||||
if(this[i] === char) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
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
|
window.register = Registry.register
|
||||||
|
|||||||
Reference in New Issue
Block a user