mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Allow property values to be functions that resolve to the actual value
This commit is contained in:
parent
4752706da3
commit
2e52266d50
@ -32,6 +32,10 @@ function getPropsStr(props, template) {
|
||||
if (props) {
|
||||
template.indent(function () {
|
||||
forEachEntry(props, function (name, value) {
|
||||
if (typeof value === 'function') {
|
||||
value = value();
|
||||
}
|
||||
|
||||
if (template.isExpression(value)) {
|
||||
var expressionStr;
|
||||
template.indent(function () {
|
||||
@ -63,15 +67,26 @@ function TagHandlerNode(tag) {
|
||||
this.tag = tag;
|
||||
this.dynamicAttributes = null;
|
||||
this.inputExpression = null;
|
||||
this.additionalVars = [];
|
||||
}
|
||||
TagHandlerNode.nodeType = 'element';
|
||||
|
||||
TagHandlerNode.convertNode = function (node, tag) {
|
||||
if (node._TagHandlerNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
extend(node, TagHandlerNode.prototype);
|
||||
TagHandlerNode.call(node, tag);
|
||||
};
|
||||
|
||||
TagHandlerNode.prototype = {
|
||||
|
||||
_TagHandlerNode: true,
|
||||
|
||||
addNestedVariable: function(name) {
|
||||
this.additionalVars.push(name);
|
||||
},
|
||||
addDynamicAttribute: function (name, value) {
|
||||
if (!this.dynamicAttributes) {
|
||||
this.dynamicAttributes = {};
|
||||
@ -129,6 +144,10 @@ TagHandlerNode.prototype = {
|
||||
variableNames.push(varName);
|
||||
}, this);
|
||||
|
||||
if (this.additionalVars.length) {
|
||||
variableNames = variableNames.concat(this.additionalVars);
|
||||
}
|
||||
|
||||
template.functionCall(tagHelperVar, function () {
|
||||
template.code('context,\n').indent(function () {
|
||||
template.line(handlerVar + ',').indent();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user