import { jsx, jsxs, Fragment } from 'solid-jsx/jsx-runtime';

/*@jsxRuntime automatic @jsxImportSource solid-jsx*/
const toc = [];
function _createMdxContent(props) {
  const _components = Object.assign({
    p: "p",
    code: "code",
    pre: "pre",
    span: "span"
  }, props.components);
  return jsxs(Fragment, {
    children: [jsxs(_components.p, {
      children: ["一些框架的清理方法直接是框架的副作用或生命周期方法的返回值。由于 Solid 渲染树中的所有内容都存在于（可能是惰性的）Effect 中并且可以嵌套，因此我们将 ", jsx(_components.code, {
        children: "onCleanup"
      }), " 设为一级方法。您可以在任何范围内调用它，它会在该范围被触发以重新求值以及最终销毁时运行。"]
    }), "\n", jsxs(_components.p, {
      children: ["你可以在组件或 Effect 中使用 ", jsx(_components.code, {
        children: "onCleanup"
      }), "。在自定义指令中使用 ", jsx(_components.code, {
        children: "onCleanup"
      }), "。 在响应式系统同步执行的任何地方都可以使用 ", jsx(_components.code, {
        children: "onCleanup"
      }), "。"]
    }), "\n", jsxs(_components.p, {
      children: ["介绍章节中的 Signal 示例在执行之后从未清理过。让我们通过用这个替换 ", jsx(_components.code, {
        children: "setInterval"
      }), " 调用来解决这个问题："]
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-js",
        children: [jsx(_components.span, {
          className: "hljs-keyword",
          children: "const"
        }), " timer = ", jsx(_components.span, {
          className: "hljs-built_in",
          children: "setInterval"
        }), "(", jsx(_components.span, {
          className: "hljs-function",
          children: "() =>"
        }), " ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "setCount"
        }), "(", jsx(_components.span, {
          className: "hljs-title function_",
          children: "count"
        }), "() + ", jsx(_components.span, {
          className: "hljs-number",
          children: "1"
        }), "), ", jsx(_components.span, {
          className: "hljs-number",
          children: "1000"
        }), ");\n", jsx(_components.span, {
          className: "hljs-title function_",
          children: "onCleanup"
        }), "(", jsx(_components.span, {
          className: "hljs-function",
          children: "() =>"
        }), " ", jsx(_components.span, {
          className: "hljs-built_in",
          children: "clearInterval"
        }), "(timer));\n"]
      })
    })]
  });
}
function MDXContent(props = {}) {
  const {wrapper: MDXLayout} = props.components || ({});
  return MDXLayout ? jsx(MDXLayout, Object.assign({}, props, {
    children: jsx(_createMdxContent, props)
  })) : _createMdxContent(props);
}

export { MDXContent as default, toc };
//# sourceMappingURL=lesson-e2816065.js.map
