open-vault/ui/tests/helpers/codemirror.js
Jordan Reimer 52fe56ec87
Eslint prefer-const (#17864)
* adds prefer-const to eslint config and runs fixer

* reverts unintended change
2022-11-09 15:15:31 -08:00

16 lines
447 B
JavaScript

const invariant = (truthy, error) => {
if (!truthy) throw new Error(error);
};
export default function (context, selector) {
const cmService = context.owner.lookup('service:code-mirror');
const element = document.querySelector(selector);
invariant(element, `Selector ${selector} matched no elements`);
const cm = cmService.instanceFor(element.id);
invariant(cm, `No registered CodeMirror instance for ${selector}`);
return cm;
}