/
githubmirror
/
wp-calypso
Обзор
Документация
Войти
/
githubmirror
/
wp-calypso
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/wpcom.js/src/lib/batch.js
48 строк
863 B
Calypso Bot
chore(deps): update linters (major) (#80830)
27 сен 2023, 16:26
Не верифицирован
27 сен 2023, 16:26
e1f240e
Код
Авторство
О чём код?
class Batch { /** * Create a `Batch` instance * @param {WPCOM} wpcom - wpcom instance * @returns {null} null */ constructor( wpcom ) { if ( ! ( this instanceof Batch ) ) { return new Batch( wpcom ); } this.wpcom = wpcom; this.urls = []; } /** * Add url to batch requests * @param {string} url - endpoint url * @returns {Batch} batch instance */ add( url ) { this.urls.push( url ); return this; } /** * Run the batch request * @param {Object} [query] - optional query parameter * @param {Function} fn - callback * @returns {Promise} Promise */ run( query = {}, fn ) { if ( 'function' === typeof query ) { fn = query; query = {}; } // add urls to query object query.urls = this.urls; return this.wpcom.req.get( '/batch', query, fn ); } } /** * Expose `Batch` module */ export default Batch;