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's reactivity is synchronous which means, by the next line after any change, the DOM will have updated. And for the most part this is perfectly fine, as Solid's granular rendering is just a propagation of the update in the reactive system. Unrelated changes \"rendering\" twice don't actually mean wasted work."
    }), "\n", jsxs(_components.p, {
      children: ["What if the changes are related? Solid's ", jsx(_components.code, {
        children: "batch"
      }), " helper allows to queue up multiple changes and then apply them all at the same time before notifying their observers."]
    }), "\n", jsxs(_components.p, {
      children: ["In this example, we are assigning both names on a button click and this triggers our rendered update twice. You can see the logs in the console when you click the button. So let's wrap the ", jsx(_components.code, {
        children: "set"
      }), " calls in a batch."]
    }), "\n", jsx(_components.pre, {
      children: jsxs(_components.code, {
        className: "hljs language-js",
        children: [" ", jsx(_components.span, {
          className: "hljs-keyword",
          children: "const"
        }), " ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "updateNames"
        }), " = (", jsx(_components.span, {
          className: "hljs-params"
        }), ") => {\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: "\"Button Clicked\""
        }), ");\n    ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "batch"
        }), "(", jsx(_components.span, {
          className: "hljs-function",
          children: "() =>"
        }), " {\n      ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "setFirstName"
        }), "(", jsx(_components.span, {
          className: "hljs-title function_",
          children: "firstName"
        }), "() + ", jsx(_components.span, {
          className: "hljs-string",
          children: "\"n\""
        }), ");\n      ", jsx(_components.span, {
          className: "hljs-title function_",
          children: "setLastName"
        }), "(", jsx(_components.span, {
          className: "hljs-title function_",
          children: "lastName"
        }), "() + ", jsx(_components.span, {
          className: "hljs-string",
          children: "\"!\""
        }), ");\n    })\n  }\n"]
      })
    }), "\n", jsx(_components.p, {
      children: "And that's it. Now we only notify once for the whole changeset."
    })]
  });
}
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-704c4e48.js.map
