Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
smtdfc committed Dec 16, 2023
1 parent 395b713 commit 47065ee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
34 changes: 17 additions & 17 deletions src/Component/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export class TurtleComponent extends HTMLElement {
this.data = {}
this.refs = {}
this.states = {}
this.rerenderDepenedents = null
this.shouldRerender = true
this.isRendered = false
this.updateDependents = null
this.shouldUpdate = true
this.isUpdate = false
this.component_data = {}
this.usingShadowDOM = false
this.wrapping = null
Expand All @@ -32,21 +32,21 @@ export class TurtleComponent extends HTMLElement {

setState(name,value){
this.states[name] = value
if(this.shouldRerender){
if(this.rerenderDepenedents == null || this.rerenderDepenedents.includes(name)) this.requestRender()
if(this.shouldUpdate){
if(this.updateDependents == null || this.updateDependents.includes(name)) this.requestRender()
}
}

onCreate() {}
onRemove() {}
onFirstRender() {}
onRerender() {}
onRendered() {}
onUpdate() {}
onRender() {}
beforeRender() {}
onEffect(){}
start() {}

async requestRender() {
if (!this.isRendered) {
if (!this.isUpdate) {
let result = processDOM(this.template.content.childNodes)
this.refs = result.refs
this.mem = result.mem
Expand All @@ -58,22 +58,22 @@ export class TurtleComponent extends HTMLElement {
})

requestAnimationFrame(()=>{
this.beforeRender()
update(this.mem,this)
this.isRendered = true
this.onFirstRender()
this.onRender()
this.isUpdate = true
this.onRendered()
this.onEffect()
})

let r = this.usingShadowDOM ? this.shadowRoot : this
r.textContent = ""
r.appendChild(this.template.content)
}else{
requestAnimationFrame(() => {
this.beforeRender()

update(this.mem, this)
this.isRendered = true
this.onRerender()
this.onRender()
this.isUpdate = true
this.onUpdated()
this.onEffect()
})
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Component/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ export function processDOM(nodes) {
node.removeAttribute("t-ref")
return
}

if (attr.localName == "t-attrs") {
let attrs = window.TURTLE.TURTLE_ATTRS[attr.value]
Object.keys(attrs).forEach(name => {
node[name] = attrs[name]
})
node.removeAttribute("t-attrs")
return

}

if (attr.localName == "t-event") {
events.push({
node: node,
Expand All @@ -49,6 +50,8 @@ export function processDOM(nodes) {
temp: attr.value
})
}


})

let child = processDOM(node.childNodes)
Expand Down

0 comments on commit 47065ee

Please sign in to comment.