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

Commit

Permalink
Introduce readonly View#isRenderingInProgress flag to check if view i…
Browse files Browse the repository at this point in the history
…s in the rendering phase.
  • Loading branch information
oskarwrobel committed Feb 18, 2019
1 parent 8ee66bf commit d718c60
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ export default class View {
*/
this.domRoots = new Map();

/**
* Used to prevent calling {@link #forceRender} and {@link #change} during rendering view to the DOM.
*
* @readonly
* @member {Boolean} #isRenderingInProgress
*/
this.set( 'isRenderingInProgress', false );

/**
* Instance of the {@link module:engine/view/renderer~Renderer renderer}.
*
Expand Down Expand Up @@ -124,14 +132,6 @@ export default class View {
*/
this._ongoingChange = false;

/**
* Used to prevent calling {@link #forceRender} and {@link #change} during rendering view to the DOM.
*
* @private
* @type {Boolean}
*/
this._renderingInProgress = false;

/**
* Used to prevent calling {@link #forceRender} and {@link #change} during rendering view to the DOM.
*
Expand Down Expand Up @@ -434,7 +434,7 @@ export default class View {
* @returns {*} Value returned by the callback.
*/
change( callback ) {
if ( this._renderingInProgress || this._postFixersInProgress ) {
if ( this.isRenderingInProgress || this._postFixersInProgress ) {
/**
* Thrown when there is an attempt to make changes to the view tree when it is in incorrect state. This may
* cause some unexpected behaviour and inconsistency between the DOM and the view.
Expand Down Expand Up @@ -668,11 +668,11 @@ export default class View {
* @private
*/
_render() {
this._renderingInProgress = true;
this.isRenderingInProgress = true;
this.disableObservers();
this._renderer.render();
this.enableObservers();
this._renderingInProgress = false;
this.isRenderingInProgress = false;
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/view/view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,22 @@ describe( 'view', () => {
} );
} );

describe( 'isRenderingInProgress', () => {
it( 'should be true while rendering is in progress', () => {
expect( view.isRenderingInProgress ).to.equal( false );

const spy = sinon.spy();

view.on( 'change:isRenderingInProgress', spy );

view.fire( 'render' );

sinon.assert.calledTwice( spy );
sinon.assert.calledWith( spy.firstCall, sinon.match.any, 'isRenderingInProgress', true );
sinon.assert.calledWith( spy.secondCall, sinon.match.any, 'isRenderingInProgress', false );
} );
} );

describe( 'forceRender()', () => {
it( 'disable observers, renders and enable observers', () => {
const observerMock = view.addObserver( ObserverMock );
Expand Down

0 comments on commit d718c60

Please sign in to comment.