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",
    pre: "pre",
    code: "code",
    span: "span"
  }, props.components);
  return jsxs(Fragment, {
    children: [jsx(_components.p, {
      children: "Context 适合用来做数据存储。Context 处理注入，将所有权与响应图联系起来，自动管理销毁，并且鉴于 Solid 的细粒度渲染，而且没有渲染开销。"
    }), "\n", jsx(_components.p, {
      children: "但是，你也可以直接将响应式系统用于简单的场景。尽管几乎没有指出的必要，但一个简单的可写 Store 确实就是一个 Signal："
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-js",
        children: [jsx(_components.span, {
          className: "hljs-keyword",
          children: "import"
        }), " { createSignal } ", jsx(_components.span, {
          className: "hljs-keyword",
          children: "from"
        }), " ", jsx(_components.span, {
          className: "hljs-string",
          children: "'solid-js'"
        }), ";\n\n", jsx(_components.span, {
          className: "hljs-keyword",
          children: "export"
        }), " ", jsx(_components.span, {
          className: "hljs-keyword",
          children: "default"
        }), " ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "createSignal"
        }), "(", jsx(_components.span, {
          className: "hljs-number",
          children: "0"
        }), ");\n\n", jsx(_components.span, {
          className: "hljs-comment",
          children: "// 别的地方的代码"
        }), "\n", jsx(_components.span, {
          className: "hljs-keyword",
          children: "import"
        }), " counter ", jsx(_components.span, {
          className: "hljs-keyword",
          children: "from"
        }), " ", jsx(_components.span, {
          className: "hljs-string",
          children: "'./counter'"
        }), ";\n", jsx(_components.span, {
          className: "hljs-keyword",
          children: "const"
        }), " [count, setCount] = counter;\n"]
      })
    }), "\n", jsx(_components.p, {
      children: "Solid 的响应性是一个普遍的概念。它跟是内部组件还是外部组件都没有关系。全局状态和局部状态没有不同的概念。都是一样的。"
    }), "\n", jsxs(_components.p, {
      children: ["唯一的限制是所有计算（Effect/Momo）都需要在响应顶层即 —— ", jsx(_components.code, {
        children: "createRoot"
      }), " 下创建。Solid 的 ", jsx(_components.code, {
        children: "render"
      }), " 会自动执行此操作。"]
    }), "\n", jsxs(_components.p, {
      children: ["在本教程中，", jsx(_components.code, {
        children: "counter.tsx"
      }), " 就是这样一个全局 Store。我们可以将 ", jsx(_components.code, {
        children: "main.tsx"
      }), " 中的组件修改为："]
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-jsx",
        children: [jsx(_components.span, {
          className: "hljs-keyword",
          children: "const"
        }), " { count, doubleCount, increment } = counter;\n\n", jsx(_components.span, {
          className: "hljs-keyword",
          children: "return"
        }), " (\n  ", jsxs(_components.span, {
          className: "xml",
          children: [jsxs(_components.span, {
            className: "hljs-tag",
            children: ["<", jsx(_components.span, {
              className: "hljs-name",
              children: "button"
            }), " ", jsx(_components.span, {
              className: "hljs-attr",
              children: "type"
            }), "=", jsx(_components.span, {
              className: "hljs-string",
              children: "\"button\""
            }), " ", jsx(_components.span, {
              className: "hljs-attr",
              children: "onClick"
            }), "=", jsx(_components.span, {
              className: "hljs-string",
              children: "{increment}"
            }), ">"]
          }), "\n    {count()} {doubleCount()}\n  ", jsxs(_components.span, {
            className: "hljs-tag",
            children: ["</", jsx(_components.span, {
              className: "hljs-name",
              children: "button"
            }), ">"]
          })]
        }), "\n);\n"]
      })
    }), "\n", jsxs(_components.p, {
      children: ["所以当你使用包含计算的复杂全局 Store 时，一定要调用 ", jsx(_components.code, {
        children: "createRoot"
      }), "。 或者更好的选择是出于为了方便使用 Context。"]
    })]
  });
}
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-cb888bcc.js.map
