From e55c33cf8c370c9ec3c6ace84409743d738addc1 Mon Sep 17 00:00:00 2001 From: Luke Melia Date: Sun, 17 Sep 2023 19:50:09 -0400 Subject: [PATCH] Refactor away from reliance on getting the current Ember run loop - this API is considered private and is removed in 4.0 --- .../components/mobiledoc-editor/component.js | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/addon/components/mobiledoc-editor/component.js b/addon/components/mobiledoc-editor/component.js index 6fdda86..0f12aa4 100644 --- a/addon/components/mobiledoc-editor/component.js +++ b/addon/components/mobiledoc-editor/component.js @@ -3,14 +3,7 @@ /* eslint-disable ember/require-tagless-components */ /* eslint-disable ember/no-classic-classes */ /* eslint-disable ember/no-classic-components */ -import { - _getCurrentRunLoop, - getCurrentRunLoop, - schedule, - begin, - end, - join, -} from '@ember/runloop'; +import { schedule, begin, end, join, next } from '@ember/runloop'; import { copy } from 'ember-copy'; import { A } from '@ember/array'; import { camelize, capitalize } from '@ember/string'; @@ -300,20 +293,21 @@ export default Component.extend({ } editor = new Editor(editorOptions); editor.willRender(() => { - // The editor's render/rerender will happen after this `editor.willRender`, - // so we explicitly start a runloop here if there is none, so that the - // add/remove card hooks happen inside a runloop. + // The editor's rendering call will happen after this `editor.willRender`, + // so we explicitly start a runloop here, so that the add/remove card hooks + // happen inside a runloop. // When pasting text that gets turned into a card, for example, - // the add card hook would run outside the runloop if we didn't begin a new + // the add card hook could run outside the runloop if we didn't begin a new // one now. - // Check for current run loop in two ways to avoid deprecations in different Ember versions - let currRunLoop = _getCurrentRunLoop - ? _getCurrentRunLoop() - : getCurrentRunLoop(); - if (!currRunLoop) { - this._startedRunLoop = true; - begin(); - } + this._startedRunLoop = true; + begin(); + // If this run loop is not ended by the next runloop, explicitly end it. + next(() => { + if (this._startedRunLoop) { + this._startedRunLoop = false; + end(); + } + }); }); editor.didRender(() => { // If we had explicitly started a run loop in `editor.willRender`,