Skip to content

Commit 049f153

Browse files
Computed attributes
1 parent b89c90a commit 049f153

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ root = true
22

33
[*]
44
indent_style = space
5-
indent_size = 4
5+
indent_size = 2
66
end_of_line = lf
77
charset = utf-8
88
quote_type = single

src/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,18 @@ function parseLocals(options, {attrs}, html) {
112112
// Handle attributes to be merged with default
113113
// only for Array or Objects
114114
const mergeAttributeWithDefault = [];
115+
const computedAttributes = [];
115116
Object.keys(attributes).forEach(attribute => {
116117
if (attribute.startsWith('merge:')) {
117118
const newAttributeName = attribute.replace('merge:', '');
118119
attributes[newAttributeName] = attributes[attribute];
119120
delete attributes[attribute];
120121
mergeAttributeWithDefault.push(newAttributeName);
122+
} else if (attribute.startsWith('computed:')) {
123+
const newAttributeName = attribute.replace('computed:', '');
124+
attributes[newAttributeName] = attributes[attribute];
125+
delete attributes[attribute];
126+
computedAttributes.push(newAttributeName);
121127
}
122128
});
123129

@@ -152,6 +158,8 @@ function parseLocals(options, {attrs}, html) {
152158
Object.keys(locals).forEach(local => {
153159
if (mergeAttributeWithDefault.includes(local)) {
154160
attributes[local] = merge({...locals[local]}, {...attributes[local]});
161+
} else if (computedAttributes.includes(local)) {
162+
attributes[local] = locals[local];
155163
} else if (typeof attributes[local] === 'undefined') {
156164
attributes[local] = locals[local];
157165
}

0 commit comments

Comments
 (0)