Try to use CodeMirror in my Elm app.
I bind a textarea from update
function like that:
( ..., runCodemirror textAreaId)
Where runCodemirror
is a port:
port runCodemirror : String -> Cmd msg
Problem is that event ports.runCodemirror
fires before a textarea appears in DOM.
I try to solve that with setTimeout
:
app.ports.runCodemirror.subscribe(
function (textAreaId) {
setTimeout(
function() {
CodeMirror.fromTextArea(document.getElementById(textAreaId));
},
100
);
}
);
but it's ugly. 100ms is too slow, I see a blinking.
Other options I have: to bind CodeMirror with invisible textarea or MutationObserver API.
Is there a better way?