mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Koenig - Fixed .cleanup
when called during editor initialisation
refs https://github.com/TryGhost/Ghost/issues/9724 - we call `koenig.cleanup` when setting a post in the editor controller but the call will happen before `componentCards` has been populated so none of our "delete if empty" routines were being run - calls to `.cleanup` now schedule the cleanup after the next editor render which should mean cards are populated before we try to remove them
This commit is contained in:
parent
4463f975e3
commit
6943e1d27a
1 changed files with 21 additions and 4 deletions
|
@ -394,6 +394,10 @@ export default Component.extend({
|
||||||
this._startedRunLoop = false;
|
this._startedRunLoop = false;
|
||||||
run.end();
|
run.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this._cleanupScheduled) {
|
||||||
|
run.schedule('afterRender', this, this._cleanup);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
editor.postDidChange(() => {
|
editor.postDidChange(() => {
|
||||||
|
@ -624,16 +628,28 @@ export default Component.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
/* public interface ----------------------------------------------------- */
|
/* public interface ----------------------------------------------------- */
|
||||||
// TODO: find a better way to expose this?
|
// TODO: find a better way to expose the public interface?
|
||||||
|
|
||||||
|
// HACK: this scheduled cleanup is a bit hacky. We call .cleanup when
|
||||||
|
// initializing Koenig in our editor controller but we have to wait for
|
||||||
|
// rendering to finish so that componentCards is populated, even then
|
||||||
|
// it's unlikely the card.component registration has finished.
|
||||||
|
//
|
||||||
|
// TODO: see if there's a way we can perform cleanup directly on the
|
||||||
|
// mobiledoc, maybe with a "cleanupOnInit" option so that we modify the
|
||||||
|
// mobiledoc before we start rendering
|
||||||
cleanup() {
|
cleanup() {
|
||||||
|
this._cleanupScheduled = true;
|
||||||
|
},
|
||||||
|
|
||||||
|
_cleanup() {
|
||||||
this.componentCards.forEach((card) => {
|
this.componentCards.forEach((card) => {
|
||||||
if (!card.koenigOptions.deleteIfEmpty) {
|
let shouldDelete = card.koenigOptions.deleteIfEmpty;
|
||||||
|
|
||||||
|
if (!shouldDelete) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let shouldDelete = card.koenigOptions.deleteIfEmpty;
|
|
||||||
|
|
||||||
if (typeof shouldDelete === 'string') {
|
if (typeof shouldDelete === 'string') {
|
||||||
let payloadKey = shouldDelete;
|
let payloadKey = shouldDelete;
|
||||||
shouldDelete = card => isBlank(get(card, payloadKey));
|
shouldDelete = card => isBlank(get(card, payloadKey));
|
||||||
|
@ -643,6 +659,7 @@ export default Component.extend({
|
||||||
this.deleteCard(card, NO_CURSOR_MOVEMENT);
|
this.deleteCard(card, NO_CURSOR_MOVEMENT);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this._cleanupScheduled = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
/* mobiledoc event handlers --------------------------------------------- */
|
/* mobiledoc event handlers --------------------------------------------- */
|
||||||
|
|
Loading…
Add table
Reference in a new issue