diff --git a/3.14.js b/3.14.js new file mode 100644 index 0000000..93edad4 --- /dev/null +++ b/3.14.js @@ -0,0 +1,42 @@ + +/* Class */ +// - Force initialization of all variables. Throw error if not enough params passed in + +/* State (denoted by "$" in front of the name) */ +// - Sync with attributes +// - Proxies to enforce type +// w/ initializers like [] {} 0 "" + +// How would one detect class object changes? +// Does object detection go all layers down? + + // Swift: Yes, if you change the inner it will rerender the outer. + // struct ContentView: View { + // @State private var outerState = OuterStruct() + + // var body: some View { + // Text(outerState.innerState.property) + // .onTapGesture { + // outerState.innerState.property = "New Value" + // } + // } + // } + + // struct OuterStruct { + // var innerState = InnerStruct() + // } + + // struct InnerStruct { + // var property = "Initial Value" + // } + +// Reactivity: +// Parse lines which use the variables? +// Rerender whole thing? + +// Lit does only parts which depend, React does whole thing then compares + +// Binding +// Objects are passed by reference, str and int by value + + diff --git a/Test/parse.test.js b/Test/parse.test.js index 224ab0e..f4b1f6f 100644 --- a/Test/parse.test.js +++ b/Test/parse.test.js @@ -1,5 +1,22 @@ window.testSuites.push( class testParse { + +testParseClassFieldsWithNoDefault() { + class Space extends HTMLElement { + form + contents = [] + + constructor() { + super() + } + } + + const fields = window.Registry.parseClassFields(Space); + if(!(JSON.stringify(fields) === JSON.stringify(["form", "contents"]))) { + return `Fields don't match` + } +} + testParseClassFieldsWithEqualityCheck() { class Space extends HTMLElement { form = Forms.observe(window.location.pathname, this) diff --git a/index.js b/index.js index 08e054f..627e753 100644 --- a/index.js +++ b/index.js @@ -51,8 +51,11 @@ window.Registry = class Registry { } static registerElement = (el, tagname) => { + console.log(this.parseClassFields(el)) let stateVariables = this.parseClassFields(el).filter(field => field.startsWith('$')); let stateVariablesWithout$ = stateVariables.map(str => str.substring(1)); + + console.log(stateVariables) // Observe attributes Object.defineProperty(el, 'observedAttributes', {