mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
feat: eliminate userEffect helper if we can statically tell there's no cleanup
This commit is contained in:
parent
b07fc6be5e
commit
67895bedef
@ -1,11 +1,7 @@
|
||||
import { userEffect as _userEffect, register as _register, bind as _bind, queueHydrate as _queueHydrate, createRenderFn as _createRenderFn } from "@marko/runtime-fluurt/src/dom";
|
||||
|
||||
const _temp = function (_scope) {
|
||||
document.body.className = "no-deps";
|
||||
};
|
||||
import { register as _register, queueHydrate as _queueHydrate, createRenderFn as _createRenderFn } from "@marko/runtime-fluurt/src/dom";
|
||||
|
||||
function _hydrate(_scope) {
|
||||
_userEffect(_scope, 0, _bind(_scope, _temp));
|
||||
document.body.className = "no-deps";
|
||||
}
|
||||
|
||||
_register("packages/translator/src/__tests__/fixtures/basic-effect-no-deps/template.marko_0", _hydrate);
|
||||
|
||||
@ -1,9 +1,4 @@
|
||||
import { queue as _queue, userEffect as _userEffect, on as _on, register as _register, bind as _bind, queueHydrate as _queueHydrate, write as _write, createRenderFn as _createRenderFn } from "@marko/runtime-fluurt/src/dom";
|
||||
|
||||
const _temp = function (_scope) {
|
||||
const clickCount = _scope[1];
|
||||
document.getElementById("button").textContent = clickCount;
|
||||
};
|
||||
import { queue as _queue, on as _on, register as _register, bind as _bind, queueHydrate as _queueHydrate, write as _write, createRenderFn as _createRenderFn } from "@marko/runtime-fluurt/src/dom";
|
||||
|
||||
const _onclick = function (_scope) {
|
||||
const clickCount = _scope[1];
|
||||
@ -12,7 +7,7 @@ const _onclick = function (_scope) {
|
||||
};
|
||||
|
||||
function _hydrate_clickCount(_scope, clickCount = _scope[1]) {
|
||||
_userEffect(_scope, 2, _bind(_scope, _temp));
|
||||
document.getElementById("button").textContent = clickCount;
|
||||
|
||||
_on(_scope[0], "click", _bind(_scope, _onclick));
|
||||
}
|
||||
|
||||
@ -1,12 +1,7 @@
|
||||
import { userEffect as _userEffect, register as _register, bind as _bind, queueHydrate as _queueHydrate, write as _write, createRenderFn as _createRenderFn } from "@marko/runtime-fluurt/src/dom";
|
||||
|
||||
const _temp = function (_scope) {
|
||||
const x = _scope[0];
|
||||
document.getElementById("ref").textContent = x;
|
||||
};
|
||||
import { register as _register, queueHydrate as _queueHydrate, write as _write, createRenderFn as _createRenderFn } from "@marko/runtime-fluurt/src/dom";
|
||||
|
||||
function _hydrate_x(_scope, x = _scope[0]) {
|
||||
_userEffect(_scope, 1, _bind(_scope, _temp));
|
||||
document.getElementById("ref").textContent = x;
|
||||
}
|
||||
|
||||
_register("packages/translator/src/__tests__/fixtures/effect-tag/template.marko_0_x", _hydrate_x);
|
||||
|
||||
@ -41,18 +41,32 @@ export default {
|
||||
const sectionId = getSectionId(tag);
|
||||
if (isOutputDOM()) {
|
||||
const cleanupIndex = tag.node.extra!.reserve!.id;
|
||||
const { value } = defaultAttr;
|
||||
let inlineStatements = null;
|
||||
if (
|
||||
t.isFunctionExpression(value) ||
|
||||
(t.isArrowFunctionExpression(value) && t.isBlockStatement(value.body))
|
||||
) {
|
||||
inlineStatements = (value.body as t.BlockStatement).body;
|
||||
t.traverse(value.body, (node) => {
|
||||
if (t.isReturnStatement(node)) {
|
||||
inlineStatements = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
addStatement(
|
||||
"hydrate",
|
||||
sectionId,
|
||||
defaultAttr.extra?.valueReferences,
|
||||
t.expressionStatement(
|
||||
callRuntime(
|
||||
"userEffect",
|
||||
scopeIdentifier,
|
||||
t.numericLiteral(cleanupIndex),
|
||||
defaultAttr.value
|
||||
inlineStatements ||
|
||||
t.expressionStatement(
|
||||
callRuntime(
|
||||
"userEffect",
|
||||
scopeIdentifier,
|
||||
t.numericLiteral(cleanupIndex),
|
||||
defaultAttr.value
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
addHTMLHydrateCall(sectionId, defaultAttr.extra?.valueReferences);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user