mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-23 15:16:50 +00:00
Switch to native Promises and fetch
For fetch and AbortController we provide native polyfills (see resources/src/skip-web2017-polyfills.js) so safe to use this here. This will be empty for modern browsers. Change-Id: Ic0f55eb0a0276be3587a4b866834bddff1124ad2
This commit is contained in:
parent
8f03303dc4
commit
428c32d027
|
@ -13,9 +13,9 @@
|
|||
"include": [ "src/**/*.js" ],
|
||||
|
||||
"//": "Set the coverage percentage by category thresholds.",
|
||||
"statements": 83,
|
||||
"statements": 80,
|
||||
"branches": 70,
|
||||
"functions": 82,
|
||||
"functions": 80,
|
||||
"lines": 90,
|
||||
|
||||
"//": "Fail if the coverage is below threshold.",
|
||||
|
|
|
@ -222,6 +222,7 @@
|
|||
"popups-refpreview-collapsible-placeholder"
|
||||
],
|
||||
"dependencies": [
|
||||
"web2017-polyfills",
|
||||
"ext.popups.icons",
|
||||
"ext.popups.images",
|
||||
"mediawiki.experiments",
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
"bundlesize": [
|
||||
{
|
||||
"path": "resources/dist/index.js",
|
||||
"maxSize": "13.5kB"
|
||||
"maxSize": "14.0kB"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
BIN
resources/dist/index.js
vendored
BIN
resources/dist/index.js
vendored
Binary file not shown.
BIN
resources/dist/index.js.map.json
vendored
BIN
resources/dist/index.js.map.json
vendored
Binary file not shown.
|
@ -162,11 +162,11 @@ export function fetch( gateway, title, el, token, type ) {
|
|||
throw exception;
|
||||
} );
|
||||
|
||||
return $.when(
|
||||
return Promise.all( [
|
||||
chain,
|
||||
wait( getDwellDelay( type ) )
|
||||
)
|
||||
.then( ( result ) => {
|
||||
] )
|
||||
.then( ( [ result ] ) => {
|
||||
dispatch( {
|
||||
type: types.FETCH_COMPLETE,
|
||||
el,
|
||||
|
|
|
@ -6,6 +6,26 @@ import constants from '../constants';
|
|||
import createMediaWikiApiGateway from './mediawiki';
|
||||
import createRESTBaseGateway from './rest';
|
||||
import * as formatters from './restFormatters';
|
||||
import { abortablePromise } from './index.js';
|
||||
|
||||
/**
|
||||
* @param {Object} options
|
||||
* @return {Promise}
|
||||
*/
|
||||
function ajax( options ) {
|
||||
const controller = new AbortController();
|
||||
const signal = controller.signal;
|
||||
|
||||
return abortablePromise(
|
||||
fetch( options.url, {
|
||||
headers: options.headers,
|
||||
signal
|
||||
} ).then( ( resp ) => resp.json() ),
|
||||
() => {
|
||||
controller.abort();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a page preview gateway with sensible values for the dependencies.
|
||||
|
@ -25,10 +45,10 @@ export default function createPagePreviewGateway( config ) {
|
|||
return createMediaWikiApiGateway( new mw.Api(), gatewayConfig );
|
||||
case 'restbasePlain':
|
||||
return createRESTBaseGateway(
|
||||
$.ajax, restConfig, formatters.parsePlainTextResponse );
|
||||
ajax, restConfig, formatters.parsePlainTextResponse );
|
||||
case 'restbaseHTML':
|
||||
return createRESTBaseGateway(
|
||||
$.ajax, restConfig, formatters.parseHTMLResponse );
|
||||
ajax, restConfig, formatters.parseHTMLResponse );
|
||||
default:
|
||||
throw new Error( 'Unknown gateway' );
|
||||
}
|
||||
|
|
|
@ -112,8 +112,8 @@ module.exports = ( env, argv ) => ( {
|
|||
// Minified uncompressed size limits for chunks / assets and entrypoints. Keep these numbers
|
||||
// up-to-date and rounded to the nearest 10th of a kibibyte so that code sizing costs are
|
||||
// well understood. Related to bundlesize minified, gzipped compressed file size tests.
|
||||
maxAssetSize: 42.5 * 1024,
|
||||
maxEntrypointSize: 42.5 * 1024,
|
||||
maxAssetSize: 42.9 * 1024,
|
||||
maxEntrypointSize: 42.9 * 1024,
|
||||
|
||||
// The default filter excludes map files but we rename ours.
|
||||
assetFilter: ( filename ) => !filename.endsWith( srcMapExt )
|
||||
|
|
Loading…
Reference in a new issue