Skip to content

Commit 0008af8

Browse files
committed
feat: add evaluate :parent attribute
1 parent b216062 commit 0008af8

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/entity.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default class Entity {
1717

1818
if (MiniJS.debug) this.element.dataset.entityId = this.id
1919

20-
if (this.element.hasAttribute(':parent')) this.setAsParent()
20+
this.attributes.evaluateParent()
2121
}
2222

2323
setAsParent() {

lib/entity/attributes.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import { Events } from './events'
22
import { escapeHTML } from '../helpers/sanitize'
33

44
export class Attributes {
5-
static CUSTOM_ATTRIBUTES = [':class', ':text', ':value', ':checked', ':each']
5+
static CUSTOM_ATTRIBUTES = [
6+
':class',
7+
':text',
8+
':value',
9+
':checked',
10+
':each',
11+
':parent',
12+
]
613
static FORBIDDEN_ATTRIBUTES = [':innerHTML', ':innerText']
714

815
static isValidAttribute(attribute, element) {
@@ -52,7 +59,8 @@ export class Attributes {
5259

5360
async evaluateAttribute(attr) {
5461
if (!Attributes.isValidAttribute(attr, this.base.element)) return
55-
if (attr === ':class') await this.evaluateClass()
62+
if (attr === ':parent') this.evaluateParent()
63+
else if (attr === ':class') await this.evaluateClass()
5664
else if (attr === ':text') await this.evaluateText()
5765
else if ([':value', ':checked'].includes(attr)) await this.evaluateValue()
5866
else if (attr === ':each') await this.evaluateEach()
@@ -63,6 +71,12 @@ export class Attributes {
6371
}
6472
}
6573

74+
evaluateParent() {
75+
if (!this.base.element.hasAttribute(':parent')) return
76+
if (this.base.isParent()) return
77+
this.base.setAsParent()
78+
}
79+
6680
async evaluateClass() {
6781
const expr = this.base.element.getAttribute(':class')
6882
if (!expr) return

0 commit comments

Comments
 (0)