8
0
Просмотр исходного кода

Added `first` getter to the PendingActions plugin.

Oskar Wróbel 7 лет назад
Родитель
Сommit
4dfda09bcf

+ 10 - 1
packages/ckeditor5-core/src/pendingactions.js

@@ -75,7 +75,7 @@ export default class PendingActions extends Plugin {
 		/* istanbul ignore next */
 		this._domEmitter.listenTo( window, 'beforeunload', ( evtInfo, domEvt ) => {
 			if ( this.isPending ) {
-				domEvt.returnValue = this._actions.get( 0 ).message;
+				domEvt.returnValue = this.first.message;
 			}
 		} );
 	}
@@ -117,6 +117,15 @@ export default class PendingActions extends Plugin {
 		this.isPending = !!this._actions.length;
 	}
 
+	/**
+	 * Returns first action from the list.
+	 *
+	 * returns {Object} Pending action object.
+	 */
+	get first() {
+		return this._actions.get( 0 );
+	}
+
 	/**
 	 * Iterable interface.
 	 *

+ 10 - 0
packages/ckeditor5-core/tests/pendingactions.js

@@ -114,6 +114,16 @@ describe( 'PendingActions', () => {
 		} );
 	} );
 
+	describe( 'first', () => {
+		it( 'should return first pending action from the list', () => {
+			const action = pendingActions.add( 'Action 1' );
+
+			pendingActions.add( 'Action 2' );
+
+			expect( pendingActions.first ).to.equal( action );
+		} );
+	} );
+
 	describe( 'iterator', () => {
 		it( 'should return all panding actions', () => {
 			pendingActions.add( 'Action 1' );