();\n\n/**\n * Prevents re-render of a template function until a single value or an array of\n * values changes.\n *\n * Example:\n *\n * ```js\n * html`\n * \n * ${guard([user.id, company.id], () => html`...`)}\n *
\n * ```\n *\n * In this case, the template only renders if either `user.id` or `company.id`\n * changes.\n *\n * guard() is useful with immutable data patterns, by preventing expensive work\n * until data updates.\n *\n * Example:\n *\n * ```js\n * html`\n * \n * ${guard([immutableItems], () => immutableItems.map(i => html`${i}`))}\n *
\n * ```\n *\n * In this case, items are mapped over only when the array reference changes.\n *\n * @param value the value to check before re-rendering\n * @param f the template function\n */\nexport const guard =\n directive((value: unknown, f: () => unknown) => (part: Part): void => {\n const previousValue = previousValues.get(part);\n if (Array.isArray(value)) {\n // Dirty-check arrays by item\n if (Array.isArray(previousValue) &&\n previousValue.length === value.length &&\n value.every((v, i) => v === previousValue[i])) {\n return;\n }\n } else if (\n previousValue === value &&\n (value !== undefined || previousValues.has(part))) {\n // Dirty-check non-arrays by identity\n return;\n }\n\n part.setValue(f());\n // Copy the value if it's an array so that if it's mutated we don't forget\n // what the previous values were.\n previousValues.set(\n part, Array.isArray(value) ? Array.from(value) : value);\n });\n"]