Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,59 +39,19 @@ function wrapDynamics(path, dynamics) {
const config = getConfig(path);

const effectWrapperId = registerImportMethod(path, config.effectWrapper);
const prevValue = t.identifier("_$p");

if (dynamics.length === 1) {
const prevValue = t.identifier("_$p");

return dynamics.map(({ elem, key, value }) => {
return t.expressionStatement(
t.callExpression(effectWrapperId, [
t.arrowFunctionExpression(
[prevValue],
setAttr(path, dynamics[0].elem, dynamics[0].key, dynamics[0].value, {
setAttr(path, elem, key, value, {
dynamic: true,
prevId: prevValue
})
)
])
);
}
const decls = [],
statements = [],
identifiers = [],
prevId = t.identifier("_p$");
dynamics.forEach(({ elem, key, value }) => {
const identifier = path.scope.generateUidIdentifier("v$");
identifiers.push(identifier);
decls.push(t.variableDeclarator(identifier, value));
const prev = t.memberExpression(prevId, identifier);
statements.push(
t.expressionStatement(
t.logicalExpression(
"&&",
t.binaryExpression("!==", identifier, t.memberExpression(prevId, identifier)),
t.assignmentExpression("=", t.memberExpression(prevId, identifier), setAttr(
path,
elem,
key,
identifier,
{ dynamic: true, prevId: prev }
))
)
)
);
});

return t.expressionStatement(
t.callExpression(effectWrapperId, [
t.arrowFunctionExpression(
[prevId],
t.blockStatement([
t.variableDeclaration("const", decls),
...statements,
t.returnStatement(prevId)
])
),
t.objectExpression(identifiers.map(id => t.objectProperty(id, t.identifier("undefined"))))
])
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,30 @@ const template = (() => {

_$setProp(_el$3, "readonly", value);

_$effect(
_p$ => {
const _v$ = welcoming(),
_v$2 = {
"background-color": color(),
"margin-right": "40px"
},
_v$3 = {
dynamic: dynamic(),
selected
};

_v$ !== _p$._v$ && (_p$._v$ = _$setProp(_el$2, "title", _v$, _p$._v$));
_v$2 !== _p$._v$2 && (_p$._v$2 = _$setProp(_el$2, "style", _v$2, _p$._v$2));
_v$3 !== _p$._v$3 && (_p$._v$3 = _$setProp(_el$2, "classList", _v$3, _p$._v$3));
return _p$;
},
{
_v$: undefined,
_v$2: undefined,
_v$3: undefined
}
_$effect(_$p => _$setProp(_el$2, "title", welcoming(), _$p));

_$effect(_$p =>
_$setProp(
_el$2,
"style",
{
"background-color": color(),
"margin-right": "40px"
},
_$p
)
);

_$effect(_$p =>
_$setProp(
_el$2,
"classList",
{
dynamic: dynamic(),
selected
},
_$p
)
);

return _el$;
Expand Down Expand Up @@ -144,27 +146,23 @@ const template6 = (() => {
const template7 = (() => {
const _el$13 = _$createElement("div");

_$effect(
_p$ => {
const _v$4 = {
"background-color": color(),
"margin-right": "40px",
...props.style
},
_v$5 = props.top,
_v$6 = props.active;
_v$4 !== _p$._v$4 && (_p$._v$4 = _$setProp(_el$13, "style", _v$4, _p$._v$4));
_v$5 !== _p$._v$5 && (_p$._v$5 = _$setProp(_el$13, "style:padding-top", _v$5, _p$._v$5));
_v$6 !== _p$._v$6 && (_p$._v$6 = _$setProp(_el$13, "class:my-class", _v$6, _p$._v$6));
return _p$;
},
{
_v$4: undefined,
_v$5: undefined,
_v$6: undefined
}
_$effect(_$p =>
_$setProp(
_el$13,
"style",
{
"background-color": color(),
"margin-right": "40px",
...props.style
},
_$p
)
);

_$effect(_$p => _$setProp(_el$13, "style:padding-top", props.top, _$p));

_$effect(_$p => _$setProp(_el$13, "class:my-class", props.active, _$p));

return _el$13;
})();

Expand Down