Ver código fonte

Added `first` getter to the PendingActions plugin.

Oskar Wróbel 7 anos atrás
pai
commit
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;
 			}
 		} );
 	}
@@ -118,6 +118,15 @@ export default class PendingActions extends Plugin {
 	}
 
 	/**
+	 * Returns first action from the list.
+	 *
+	 * returns {Object} Pending action object.
+	 */
+	get first() {
+		return this._actions.get( 0 );
+	}
+
+	/**
 	 * Iterable interface.
 	 *
 	 * @returns {Iterable.<*>}

+ 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' );