export default class CodeMirror extends Modifier<Signature> {
@service declare editor: EditorService;
@service declare router: RouterService;
modify(element: Element, [value]: PositionalArgs) {
this.setup(element, [value]);
}
isSetup = false;
setup = async (element: Element, [value]: PositionalArgs) => {
if (this.isSetup) {
return;
}
// CODEMIRROR here is a function I abstracted for setting up / configuring codemirror.
// the important part is that the `element` is passed to it, and I can cleanup when the
// modifier is destroyed (see registerDestructor below)
let { view } = CODEMIRROR(element, value);
registerDestructor(this, () => view.destroy());
};
}
A code editor doing things with DOM “should” be no different than highcharts operating on DOM, so I hope this technique helps!
I was surprised to see the ember-highcharts addon usescheduleOnce to integrate with Highcharts. I’m curious if there is an alternate way.
Yeah, this bit me recently. It’s not really correct. I think it works that way because it has evolved over time since before Ember had modifiers, but NullVoxPopuli is correct that in current Ember idioms a modifier is the best way to do this and not need any weird runloop interactions.
The symptom I hit by the way is that the body scroll position was getting messed up when a chart would get rendered. It was happening because the page actually renders “short” with an empty chart briefly due to the scheduleOnce shenanigans.