Skip to content

Commit b48f0b2

Browse files
committed
fix: make :each children work with observe dom
1 parent c662ba1 commit b48f0b2

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

lib/entity.js

+3-14
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ export default class Entity {
197197
return 'Entity' + Date.now() + Math.floor(Math.random() * 10000)
198198
}
199199

200-
async init(shouldAdd = false) {
200+
async init() {
201201
this.getVariables()
202202
this.applyEventBindings()
203203
await this.evaluateAll()
204204

205-
if (shouldAdd || !this.isInsideEachElement()) MiniJS.elements.push(this)
205+
MiniJS.elements.push(this)
206206
}
207207

208208
initChildren() {
@@ -214,24 +214,13 @@ export default class Entity {
214214

215215
try {
216216
const entity = new Entity(element)
217-
entity.init(true)
217+
entity.init()
218218
} catch (error) {
219219
console.error('Failed to initialize child entity:', error)
220220
}
221221
}
222222
}
223223

224-
isInsideEachElement() {
225-
let value = this.element.parentElement
226-
227-
while (value) {
228-
if (value.hasAttribute && value.hasAttribute(':each')) return true
229-
value = value.parentElement
230-
}
231-
232-
return false
233-
}
234-
235224
async evaluateEventAction(attrName) {
236225
const attrVal = this.element.getAttribute(attrName)
237226
await this._interpret(attrVal)

lib/main.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ const MiniJS = (() => {
201201
if (elem.nodeType !== 1) continue
202202

203203
const entity = new Entity(elem)
204-
205-
if (!entity.isInsideEachElement()) _elements.push(entity)
204+
_elements.push(entity)
206205
}
207206
}
208207

0 commit comments

Comments
 (0)