Skip to content

Commit

Permalink
Merge pull request #84 from ckeditor/t/82
Browse files Browse the repository at this point in the history
Other: Improved performance by processing data only when effectively needed. Closes #82. Closes #83.
  • Loading branch information
ma2ciek committed Apr 2, 2019
2 parents 63c0073 + a66a0d5 commit 0e4638e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
22 changes: 20 additions & 2 deletions src/ckeditor/ckeditor.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ describe( 'CKEditorComponent', () => {
} );
} );

it( 'change - should not calculate editor data when the control value ancestor is not specified', () => {
fixture.detectChanges();

const changeSpy = jasmine.createSpy();
component.change.subscribe( changeSpy );

return wait().then( () => {
spyOn( component.editorInstance!, 'getData' ).and.callThrough();

component.editorInstance!.execute( 'input', { text: 'foo' } );
component.editorInstance!.execute( 'input', { text: 'foo' } );
component.editorInstance!.execute( 'input', { text: 'foo' } );

expect( component.editorInstance!.getData ).toHaveBeenCalledTimes( 0 );
expect( changeSpy ).toHaveBeenCalledTimes( 3 );
} );
} );

it( 'focus', () => {
fixture.detectChanges();
const spy = jasmine.createSpy();
Expand Down Expand Up @@ -235,7 +253,7 @@ describe( 'CKEditorComponent', () => {
} );
} );

it( 'onChange callback should be called when editor model changes', () => {
it( 'onChange callback should be called when editor model changes with editor data', () => {
fixture.detectChanges();

return wait().then( () => {
Expand All @@ -244,7 +262,7 @@ describe( 'CKEditorComponent', () => {

component.editorInstance!.execute( 'input', { text: 'foo' } );

expect( spy ).toHaveBeenCalled();
expect( spy ).toHaveBeenCalledWith( '<p>foo</p>' );
} );
} );
} );
Expand Down
4 changes: 2 additions & 2 deletions src/ckeditor/ckeditor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,10 @@ export class CKEditorComponent implements AfterViewInit, OnDestroy, ControlValue
const viewDocument = editor.editing.view.document;

modelDocument.on( 'change:data', ( evt: CKEditor5.EventInfo<'change:data'> ) => {
const data = editor.getData();

this.ngZone.run( () => {
if ( this.cvaOnChange ) {
const data = editor.getData();

this.cvaOnChange( data );
}

Expand Down

0 comments on commit 0e4638e

Please sign in to comment.