Bartosz Dziewoński has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/356061 )
Change subject: WindowManager: Deprecate using the return value of
openWindow/closeWindow as a promise
......................................................................
WindowManager: Deprecate using the return value of openWindow/closeWindow as a
promise
The return value is now a WindowInstance object. Rather than using the
"nested promises" to wait for window to open/close, you should instace
use its properties (opening, opened, closing, closed) to wait for the
given step of window lifecycle.
Updated OO.ui.alert/confirm/prompt not to use the now-deprecated method.
Bug: T95923
Change-Id: Id1087428b2ac80bb1223793fbd66024be80bcf1d
---
M src/WindowManager.js
M src/windows.js
2 files changed, 29 insertions(+), 25 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/61/356061/1
diff --git a/src/WindowManager.js b/src/WindowManager.js
index 1cc73ef..acc8e2d 100644
--- a/src/WindowManager.js
+++ b/src/WindowManager.js
@@ -358,7 +358,13 @@
// Turn lifecycle into a Thenable for backwards-compatibility with
// the deprecated nested-promise behaviour (T163510).
- lifecycle.then = compatOpening.then;
+ lifecycle.then = function () {
+ OO.ui.warnDeprecation(
+ 'Using the return value of openWindow as a promise is
deprecated. ' +
+ 'Use .openWindow( ... ).opening.then( ... ) instead.'
+ );
+ return compatOpening.then.apply( this, arguments );
+ };
// Argument handling
if ( typeof win === 'string' ) {
@@ -459,7 +465,13 @@
// Turn lifecycle into a Thenable for backwards-compatibility with
// the deprecated nested-promise behaviour (T163510).
- lifecycle.then = compatClosing.then;
+ lifecycle.then = function () {
+ OO.ui.warnDeprecation(
+ 'Using the return value of closeWindow as a promise is
deprecated. ' +
+ 'Use .closeWindow( ... ).closing.then( ... ) instead.'
+ );
+ return compatClosing.then.apply( this, arguments );
+ };
// Error handling
if ( !win ) {
diff --git a/src/windows.js b/src/windows.js
index cdc60e6..7def14d 100644
--- a/src/windows.js
+++ b/src/windows.js
@@ -40,12 +40,8 @@
return OO.ui.getWindowManager().openWindow( 'message', $.extend( {
message: text,
actions: [ OO.ui.MessageDialog.static.actions[ 0 ] ]
- }, options ) ).then( function ( opened ) {
- return opened.then( function ( closing ) {
- return closing.then( function () {
- return $.Deferred().resolve();
- } );
- } );
+ }, options ) ).closed.then( function ( data ) {
+ return undefined;
} );
};
@@ -75,12 +71,8 @@
OO.ui.confirm = function ( text, options ) {
return OO.ui.getWindowManager().openWindow( 'message', $.extend( {
message: text
- }, options ) ).then( function ( opened ) {
- return opened.then( function ( closing ) {
- return closing.then( function ( data ) {
- return $.Deferred().resolve( !!( data &&
data.action === 'accept' ) );
- } );
- } );
+ }, options ) ).closed.then( function ( data ) {
+ return !!( data && data.action === 'accept' );
} );
};
@@ -109,27 +101,27 @@
* resolve to `null`.
*/
OO.ui.prompt = function ( text, options ) {
- var manager = OO.ui.getWindowManager(),
+ var instance,
+ manager = OO.ui.getWindowManager(),
textInput = new OO.ui.TextInputWidget( ( options &&
options.textInput ) || {} ),
textField = new OO.ui.FieldLayout( textInput, {
align: 'top',
label: text
} );
- // TODO: This is a little hacky, and could be done by extending
MessageDialog instead.
-
- return manager.openWindow( 'message', $.extend( {
+ instance = manager.openWindow( 'message', $.extend( {
message: textField.$element
- }, options ) ).then( function ( opened ) {
- // After ready
+ }, options ) );
+
+ // TODO: This is a little hacky, and could be done by extending
MessageDialog instead.
+ instance.opened.then( function () {
textInput.on( 'enter', function () {
manager.getCurrentWindow().close( { action: 'accept' }
);
} );
textInput.focus();
- return opened.then( function ( closing ) {
- return closing.then( function ( data ) {
- return $.Deferred().resolve( data &&
data.action === 'accept' ? textInput.getValue() : null );
- } );
- } );
+ } );
+
+ return instance.closed.then( function ( data ) {
+ return data && data.action === 'accept' ? textInput.getValue()
: null;
} );
};
--
To view, visit https://gerrit.wikimedia.org/r/356061
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id1087428b2ac80bb1223793fbd66024be80bcf1d
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits