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: "Solid 强烈建议使用浅层不可变模式来更新状态。通过分离读写，我们可以更好地控制系统的响应性，而不会遭遇经过组件层传递后丢失变更跟踪代理。与 Signal 相比，使用 Store 适用范围更广。"
    }), "\n", jsxs(_components.p, {
      children: ["然而，有时，突变更容易推理。这就是为什么 Solid 提供了一个受 Immer 启发的 ", jsx(_components.code, {
        children: "produce"
      }), " store 修饰符的原因，它可以让你在 ", jsx(_components.code, {
        children: "setStore"
      }), " 调用中改变 Store 对象的可写代理版本。"]
    }), "\n", jsxs(_components.p, {
      children: ["这是一个很好的工具，可以在不放弃控制的情况下允许小范围的突变。让我们在 Todos 示例中使用 ", jsx(_components.code, {
        children: "produce"
      }), "，将事件处理程序代码替换为："]
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-jsx",
        children: [jsx(_components.span, {
          className: "hljs-keyword",
          children: "const"
        }), " ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "addTodo"
        }), " = (", jsx(_components.span, {
          className: "hljs-params",
          children: "text"
        }), ") => {\n  ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "setStore"
        }), "(\n    ", jsx(_components.span, {
          className: "hljs-string",
          children: "'todos'"
        }), ",\n    ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "produce"
        }), "(", jsxs(_components.span, {
          className: "hljs-function",
          children: ["(", jsx(_components.span, {
            className: "hljs-params",
            children: "todos"
          }), ") =>"]
        }), " {\n      todos.", jsx(_components.span, {
          className: "hljs-title function_",
          children: "push"
        }), "({ ", jsx(_components.span, {
          className: "hljs-attr",
          children: "id"
        }), ": ++todoId, text, ", jsx(_components.span, {
          className: "hljs-attr",
          children: "completed"
        }), ": ", jsx(_components.span, {
          className: "hljs-literal",
          children: "false"
        }), " });\n    }),\n  );\n};\n", jsx(_components.span, {
          className: "hljs-keyword",
          children: "const"
        }), " ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "toggleTodo"
        }), " = (", jsx(_components.span, {
          className: "hljs-params",
          children: "id"
        }), ") => {\n  ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "setStore"
        }), "(\n    ", jsx(_components.span, {
          className: "hljs-string",
          children: "'todos'"
        }), ",\n    ", jsxs(_components.span, {
          className: "hljs-function",
          children: [jsx(_components.span, {
            className: "hljs-params",
            children: "todo"
          }), " =>"]
        }), " todo.", jsx(_components.span, {
          className: "hljs-property",
          children: "id"
        }), " === id,\n    ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "produce"
        }), "(", jsxs(_components.span, {
          className: "hljs-function",
          children: ["(", jsx(_components.span, {
            className: "hljs-params",
            children: "todo"
          }), ") =>"]
        }), " (todo.", jsx(_components.span, {
          className: "hljs-property",
          children: "completed"
        }), " = !todo.", jsx(_components.span, {
          className: "hljs-property",
          children: "completed"
        }), ")),\n  );\n};\n"]
      })
    }), "\n", jsxs(_components.p, {
      children: ["虽然带有 Store 配合 ", jsx(_components.code, {
        children: "produce"
      }), " 可以处理绝大多数情况，但 Solid 也可以用 ", jsx(_components.code, {
        children: "createMutable"
      }), " 创建一个可变的 Store 对象。虽然不是内部 API 所推荐的方法，但有时用来与第三方系统进行互操作或兼容很有用。"]
    })]
  });
}
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-c64b37f9.js.map
