Simple observed object reactivity

This commit is contained in:
metacryst
2024-03-26 21:32:50 -04:00
parent f697003efc
commit 7231a5bdac
5 changed files with 404 additions and 171 deletions

View File

@@ -26,24 +26,6 @@ window.testSuites.push( class testObservedObject {
}
}
// WorksWithShadow() {
// window.Form = class Form extends ObservedObject {
// id
// path
// $canvasPosition
// }
// class File extends Shadow {
// $$form = Form.decode({id: "123", path: "/", canvasPosition: "25|25"})
// }
// window.register(File, "file-1")
// let file = window.File()
// console.log(file, p())
// return "Not yet"
// }
// ChangingObjChangesInstance() {
// class Form extends ObservedObject {
// id

39
Test/params.test.js Normal file
View File

@@ -0,0 +1,39 @@
window.testSuites.push( class testParams {
Args() {
}
Constructor() {
}
Default() {
}
// 2/3
DefaultArgs() {
}
ConstructorArgs() {
}
ConstructorDefault() {
}
// 3/3
ConstructorDefaultArgs() {
}
ConstructorDefault() {
}
})

View File

@@ -5,7 +5,6 @@ window.testSuites.push( class testRender {
$form
render = () => {
console.log("render", window.rendering)
p(this.form.data)
}
@@ -31,7 +30,6 @@ window.testSuites.push( class testRender {
$name
render = () => {
console.log("render", window.rendering)
p(this.name)
}
@@ -55,7 +53,6 @@ window.testSuites.push( class testRender {
$name = "asd"
render = () => {
console.log("render", window.rendering)
p(this.name)
p("asd")
}
@@ -69,14 +66,100 @@ window.testSuites.push( class testRender {
const file = File()
file.name = "hey123"
let childs = Array.from(file.children)
childs.forEach((el) => {
console.log(el.innerText)
})
if(file.children[1].innerText === "hey123") {
return "Paragraph innertext falsely changed"
}
}
DefaultObservedObject() {
window.Form = class Form extends ObservedObject {
id
path
$canvasPosition
}
class File extends Shadow {
$$form = Form.decode({id: "123", path: "/", canvasPosition: "25|25"})
render = () => {
p(this.form.path)
}
}
window.register(File, "file-1")
let file = window.File()
if(file.firstChild?.innerText !== "/") {
return "Path is not inside of paragraph tag"
}
}
ObservedObject() {
let Form = class Form extends ObservedObject {
id
$path
$children
$canvasPosition
}
let object = Form.decode({id: "123", path: "/", children: [], canvasPosition: "25|25"});
register(class File extends Shadow {
$$form
render = () => {
p(this.form.path)
}
}, randomName("file"))
let file = File(object)
if(file.firstChild?.innerText !== "/") {
return "Path is not inside of paragraph tag"
}
object.path = "/asd"
if(file.form.path !== "/asd") {
return "Path did not change when changing original object"
}
if(file.firstChild?.innerText !== "/asd") {
return "Observed Object did not cause a reactive change"
}
}
// ObservedObjectWithArray() {
// let Form = class Form extends ObservedObject {
// id
// $path
// $children
// $canvasPosition
// }
// let object = Form.decode({id: "123", path: "/", children: [], canvasPosition: "25|25"});
// register(class File extends Shadow {
// $$form
// render = () => {
// p(this.form.path)
// }
// }, randomName("file"))
// let file = File(object)
// if(file.firstChild?.innerText !== "/") {
// return "Path is not inside of paragraph tag"
// }
// file.form.children.push("hello")
// object.path = "/asd"
// if(file.form.path !== "/asd") {
// return "Path did not change when changing original object"
// }
// if(file.firstChild?.innerText !== "/asd") {
// return "Observed Object did not cause a reactive change"
// }
// }
})

View File

@@ -124,7 +124,31 @@ window.testSuites.push( class testShadow {
}
}
CannotAddUndefinedProperties() {
// this needs to be fixed
// CannotAddUndefinedProperties() {
// register(class File extends Shadow {
// render = () => {
// p("boi")
// }
// constructor() {
// super()
// this.hey = "unallowed"
// }
// }, randomName("file"))
// try {
// const file = File()
// return "Did not throw error!"
// } catch(e) {
// if(!e.message.includes("Extensible")) {
// throw e
// }
// }
// }
CannotAddUndefinedPropertiesAfterConstructor() {
register(class File extends Shadow {
render = () => {
@@ -133,21 +157,21 @@ window.testSuites.push( class testShadow {
constructor() {
super()
this.hey = "unallowed"
}
}, randomName("file"))
try {
const file = File()
file.hey = "unallowed"
return "Did not throw error!"
} catch(e) {
if(!e.message.includes("Extensible")) {
if(!e.message.includes("extensible")) {
throw e
}
}
}
SetNonStateFields() {
NonStateFieldsGetSet() {
register(class File extends Shadow {
nonStateField
@@ -157,9 +181,29 @@ window.testSuites.push( class testShadow {
}, randomName("file"))
const file = File("asd")
if(!file.nonStateField === "asd") {
if(!(file.nonStateField === "asd")) {
return "Did not set field!"
}
}
AllFieldsMustBeSet() {
register(class File extends Shadow {
$field1
$field2
constructor() {
super()
}
}, randomName("file"))
try {
const file = File("asd")
console.log(file.field1, file.field2)
return "No error thrown"
} catch(e) {
if(!e.message.includes("field2\" must be initialized")) {
throw e
}
}
}
})