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: [jsx(_components.p, {
      children: "Signal 是可追踪的值，但它们只是等式的一半。另一半是观察者，也就是计算。最基本的计算称为 Effect，它产生副作用 —— 我们系统的输出。"
    }), "\n", jsxs(_components.p, {
      children: ["可以通过从 ", jsx(_components.code, {
        children: "solid-js"
      }), " 导入 ", jsx(_components.code, {
        children: "createEffect"
      }), " 来创建 Effect。", jsx(_components.code, {
        children: "createEffect"
      }), " 接收一个函数，并监视其执行情况。", jsx(_components.code, {
        children: "createEffect"
      }), " 会自动订阅在执行期间读取的所有 Signal，并在这些 Signal 值之一发生变化时重新运行该函数。"]
    }), "\n", jsxs(_components.p, {
      children: ["因此，让我们创建一个 Effect，该 Effect 会在 ", jsx(_components.code, {
        children: "count"
      }), " 更改时重新运行。"]
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-jsx",
        children: [jsx(_components.span, {
          className: "hljs-title function_",
          children: "createEffect"
        }), "(", jsx(_components.span, {
          className: "hljs-function",
          children: "() =>"
        }), " {\n  ", jsx(_components.span, {
          className: "hljs-variable language_",
          children: "console"
        }), ".", jsx(_components.span, {
          className: "hljs-title function_",
          children: "log"
        }), "(", jsx(_components.span, {
          className: "hljs-string",
          children: "\"The count is now\""
        }), ", ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "count"
        }), "());\n});\n"]
      })
    }), "\n", jsxs(_components.p, {
      children: ["要更新 ", jsx(_components.code, {
        children: "count"
      }), " Signal，我们需要在按钮上绑定一个点击事件监听器。"]
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-jsx",
        children: ["<button onClick={", 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-title class_",
          children: "Click"
        }), " ", jsx(_components.span, {
          className: "hljs-title class_",
          children: "Me"
        }), "</button>\n"]
      })
    }), "\n", jsxs(_components.p, {
      children: ["现在单击按钮就会输出日志了。这是一个相对简单的示例，但要了解 Solid 的工作原理，你应该想象 JSX 中的每个表达式都可能是一个单独包装的 Effect，它会在其依赖信号发生变化时重新执行。这就是 Solid 中所有渲染的工作方式。从 Solid 的角度来看，", jsx(_components.code, {
        children: "所有渲染都只是响应系统的副作用"
      }), "。"]
    }), "\n", jsxs(_components.p, {
      children: ["开发者使用 ", jsx(_components.code, {
        children: "createEffect"
      }), " 创建的 Effect 会在渲染完成后运行，主要用于调度渲染后与 DOM 交互的更新。"]
    })]
  });
}
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-6895a02b.js.map
