Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 6577d04

Browse files
author
Piotr Jasiun
authored
Merge pull request #1682 from ckeditor/t/ckeditor5/1530
Feature: Introduce read-only `View#isRenderingInProgress` flag to check if the document is in the rendering phase. Closes ckeditor/ckeditor5#1530.
2 parents 8ee66bf + d718c60 commit 6577d04

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

src/view/view.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ export default class View {
8888
*/
8989
this.domRoots = new Map();
9090

91+
/**
92+
* Used to prevent calling {@link #forceRender} and {@link #change} during rendering view to the DOM.
93+
*
94+
* @readonly
95+
* @member {Boolean} #isRenderingInProgress
96+
*/
97+
this.set( 'isRenderingInProgress', false );
98+
9199
/**
92100
* Instance of the {@link module:engine/view/renderer~Renderer renderer}.
93101
*
@@ -124,14 +132,6 @@ export default class View {
124132
*/
125133
this._ongoingChange = false;
126134

127-
/**
128-
* Used to prevent calling {@link #forceRender} and {@link #change} during rendering view to the DOM.
129-
*
130-
* @private
131-
* @type {Boolean}
132-
*/
133-
this._renderingInProgress = false;
134-
135135
/**
136136
* Used to prevent calling {@link #forceRender} and {@link #change} during rendering view to the DOM.
137137
*
@@ -434,7 +434,7 @@ export default class View {
434434
* @returns {*} Value returned by the callback.
435435
*/
436436
change( callback ) {
437-
if ( this._renderingInProgress || this._postFixersInProgress ) {
437+
if ( this.isRenderingInProgress || this._postFixersInProgress ) {
438438
/**
439439
* Thrown when there is an attempt to make changes to the view tree when it is in incorrect state. This may
440440
* cause some unexpected behaviour and inconsistency between the DOM and the view.
@@ -668,11 +668,11 @@ export default class View {
668668
* @private
669669
*/
670670
_render() {
671-
this._renderingInProgress = true;
671+
this.isRenderingInProgress = true;
672672
this.disableObservers();
673673
this._renderer.render();
674674
this.enableObservers();
675-
this._renderingInProgress = false;
675+
this.isRenderingInProgress = false;
676676
}
677677

678678
/**

tests/view/view/view.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,22 @@ describe( 'view', () => {
487487
} );
488488
} );
489489

490+
describe( 'isRenderingInProgress', () => {
491+
it( 'should be true while rendering is in progress', () => {
492+
expect( view.isRenderingInProgress ).to.equal( false );
493+
494+
const spy = sinon.spy();
495+
496+
view.on( 'change:isRenderingInProgress', spy );
497+
498+
view.fire( 'render' );
499+
500+
sinon.assert.calledTwice( spy );
501+
sinon.assert.calledWith( spy.firstCall, sinon.match.any, 'isRenderingInProgress', true );
502+
sinon.assert.calledWith( spy.secondCall, sinon.match.any, 'isRenderingInProgress', false );
503+
} );
504+
} );
505+
490506
describe( 'forceRender()', () => {
491507
it( 'disable observers, renders and enable observers', () => {
492508
const observerMock = view.addObserver( ObserverMock );

0 commit comments

Comments
 (0)