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

Commit

Permalink
Removed throttle when firing update event.
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarwrobel committed Jun 28, 2018
1 parent 3ab8d2c commit 051d76b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 42 deletions.
17 changes: 2 additions & 15 deletions src/editor/editorui.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';

import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
import mix from '@ckeditor/ckeditor5-utils/src/mix';
import throttle from '@ckeditor/ckeditor5-utils/src/lib/lodash/throttle';

/**
* A class providing the minimal interface that is required to successfully bootstrap any editor UI.
Expand Down Expand Up @@ -61,31 +60,22 @@ export default class EditorUI {
*/
this.focusTracker = new FocusTracker();

/**
* Fires throttled {@link module:core/editor/editorui~EditorUI#event:update} event.
*
* @protected
* @type {Function}
*/
this._throttledUpdate = throttle( () => this.fire( 'update' ), 5 );

// Informs UI components that should be refreshed after layout change.
this.listenTo( editor.editing.view.document, 'layoutChanged', () => this.update() );
}

/**
* Fires the (throttled) {@link module:core/editor/editorui~EditorUI#event:update} event.
* Fires the {@link module:core/editor/editorui~EditorUI#event:update} event.
*/
update() {
this._throttledUpdate();
this.fire( 'update' );
}

/**
* Destroys the UI.
*/
destroy() {
this.stopListening();
this._throttledUpdate.cancel();
this.view.destroy();
}

Expand All @@ -95,9 +85,6 @@ export default class EditorUI {
* **Note:**: The event is fired after each {@link module:engine/view/document~Document#event:layoutChanged}.
* It can also be fired manually via the {@link module:core/editor/editorui~EditorUI#update} method.
*
* **Note:**: Successive `update` events will throttled (5ms) to improve the performance of the UI
* and the overall responsiveness of the editor.
*
* @event update
*/
}
Expand Down
29 changes: 2 additions & 27 deletions tests/editor/editorui.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe( 'EditorUI', () => {
expect( ui.focusTracker ).to.be.instanceOf( FocusTracker );
} );

it( 'should fire throttled update event after viewDocument#layoutChanged', () => {
it( 'should fire update event after viewDocument#layoutChanged', () => {
const spy = sinon.spy();

ui.on( 'update', spy );
Expand All @@ -58,16 +58,12 @@ describe( 'EditorUI', () => {

editor.editing.view.document.fire( 'layoutChanged' );

sinon.assert.calledOnce( spy );

ui._throttledUpdate.flush();

sinon.assert.calledTwice( spy );
} );
} );

describe( 'update()', () => {
it( 'should fire throttled update event', () => {
it( 'should fire update event', () => {
const spy = sinon.spy();

ui.on( 'update', spy );
Expand All @@ -78,10 +74,6 @@ describe( 'EditorUI', () => {

ui.update();

sinon.assert.calledOnce( spy );

ui._throttledUpdate.flush();

sinon.assert.calledTwice( spy );
} );
} );
Expand All @@ -102,22 +94,5 @@ describe( 'EditorUI', () => {

sinon.assert.called( spy );
} );

it( 'should cancel throttled update event', () => {
const spy = sinon.spy();

ui.on( 'update', spy );

ui.update();

sinon.assert.calledOnce( spy );

ui.destroy();

ui.update();
ui._throttledUpdate.flush();

sinon.assert.calledOnce( spy );
} );
} );
} );

0 comments on commit 051d76b

Please sign in to comment.