Skip to content

Commit

Permalink
add remove node functionality, make some view methods private
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudValette committed Jan 9, 2023
1 parent 90b21cd commit 781b0af
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ generatePublic.generateHtmlRoot('frontend', 'this is a frontend')
generatePublic.generateRobots()
const s = new Scenario()
const {index, app} = generateSrc(s)
s.be()


s.writeChanges()
25 changes: 22 additions & 3 deletions virtual/Scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ class Scenario{
nextState={content:[]}

push(component){
let prev= [...this.content]
const prev= [...this.content]
this.content=[...this.content,component]
this.update({...this.previousState, content:prev},{content:this.content})
}

writeChanges(){
}

computeDiff(){
}

createRootComponent(name,options){
const root= new view.rootComponent(name,options)
this.push(root)
Expand All @@ -29,10 +35,23 @@ class Scenario{
return component
}

removeNode(nodeId){
this.findNode(nodeId)
.removeSelf()
const newContent=[]
for(let i=0;i<this.content.length;i++){
if(this.content[i].getNodeId()!==nodeId){
newContent.push(this.content[i])
}
}
this.update({...this.previousState, content:[...this.content]},{content:newContent})
this.content=newContent
}

findNode(nodeId){
for(let i = 0; i<this.content.length; i++){
if(content.getNodeId() === nodeId){
return content[i]
if(this.content[i].getNodeId() === nodeId){
return this.content[i]
}
}
}
Expand Down
20 changes: 18 additions & 2 deletions virtual/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class component{
this.location='component'
}

addParentDependency(component){
#addParentDependency(component){
this.parentDependencies={...this.parentDependencies,
[component.getNodeId()]:{
path:`${component.getLocation()}/${component.getNodeId()}`,
Expand All @@ -22,14 +22,30 @@ class component{
}
}

#removeLocalDependency(nodeId){
const newLocalDependencies={}
for(const [key,value] of Object.entries(this.localDependencies)){
if(value.name!==nodeId){
newLocalDependencies[key]=value
}
}
this.localDependencies=newLocalDependencies
}

removeSelf(){
for(const [key,value] of Object.entries(this.parentDependencies)){
value.ref.#removeLocalDependency(this.nodeId)
}
}

addLocalDependency(component){
this.localDependencies={...this.localDependencies,
[component.getNodeId()]:{
path:`${component.getLocation()}/${component.getNodeId()}`,
name:component.getNodeId(),
ref:component
}}
component.addParentDependency(this)
component.#addParentDependency(this)
}

getChildrenByNodeId(nodeId){
Expand Down

0 comments on commit 781b0af

Please sign in to comment.