mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
1 line
5.3 KiB
Plaintext
1 line
5.3 KiB
Plaintext
{"version":3,"file":"pending.min.js","sources":["../src/pending.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * A helper used to inform Behat that an operation is in progress and that Behat must wait for it to complete.\n *\n * @module core/pending\n * @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 3.6\n */\n\n/**\n * A helper used to register any long-running operations that are in-progress and that Behat must wait for it to complete.\n *\n * This is useful in cases where the user interface may be updated and take some time to change - for example where\n * applying a transition.\n *\n * This data is used by Behat, but may also be consumed by other location too.\n *\n * By informing Behat that an action is about to happen, and then that it is complete, allows\n * Behat to wait for that completion and avoid random failures in automated testing.\n *\n * Note: It is recommended that a descriptive key be used to aid in debugging where possible, but this is optional.\n */\nexport default class {\n\n /**\n * Create a new Pending Promise statically.\n *\n * @param {String} pendingKey An identifier to help in debugging\n * @return {Promise} A Native Promise\n * @deprecated since Moodle 4.2\n */\n static request(pendingKey) {\n window.console.error(\n `The core/pending::request method has been deprecated. ` +\n `Please use one of the alternative calls to core/pending, for example \"new Pending('${pendingKey}')\". ` +\n `Called with ${pendingKey}`\n );\n return new this(pendingKey);\n }\n\n /**\n * Request a new pendingPromise for later resolution.\n *\n * When the action you are performing is complete, simply call resolve on the returned Promise.\n *\n * @param {String} [pendingKey='pendingPromise'] An identifier to help in debugging\n * @return {Promise} A Native Promise\n * @example\n * import Pending from 'core/pending';\n * import {get_string as getString} from 'core/str';\n *\n * const stringPromise = new Pending('mod_myexample/setup');\n * const myString = getString('ok')\n * .then(okay => {\n * window.console.log(okay);\n * })\n * .then(okay => stringPromise.resolve(okay));\n */\n constructor(pendingKey = 'pendingPromise') {\n let resolver;\n let rejector;\n const pendingPromise = this.constructor.Promise((resolve, reject) => {\n resolver = resolve;\n rejector = reject;\n }, pendingKey);\n pendingPromise.resolve = resolver;\n pendingPromise.reject = rejector;\n\n return pendingPromise;\n }\n\n /**\n * Create a new Pending Promise with the same interface as a native Promise.\n *\n * @param {Callable} fn A callable which takes the resolve and reject arguments as in a Native Promise constructor.\n * @param {String} [pendingKey='pendingPromise'] An identifier to help in debugging\n * @returns {Promise}\n * @since Moodle 4.2\n * @example\n * // Use the Pending class in the same way that you would a Native Promise.\n * import Pending from 'core/pending';\n * import {get_string as getString} from 'core/str';\n *\n * export const init => {\n * Pending.Promise((resolve, reject) => {\n * getString('ok')\n * .then(okay => {\n * window.console.log(okay);\n * return okay;\n * })\n * .then(resolve)\n * .catch(reject);\n * }, 'mod_myexample/setup:init');\n * };\n */\n static Promise(fn, pendingKey = 'pendingPromise') {\n const resolver = new Promise((resolve, reject) => {\n M.util.js_pending(pendingKey);\n\n fn(resolve, reject);\n });\n\n resolver.then(() => {\n M.util.js_complete(pendingKey);\n return;\n }).catch();\n\n return resolver;\n }\n}\n"],"names":["pendingKey","window","console","error","this","constructor","resolver","rejector","pendingPromise","Promise","resolve","reject","fn","M","util","js_pending","then","js_complete","catch"],"mappings":";;;;;;;;;qBA8CmBA,mBACXC,OAAOC,QAAQC,MACX,uJACsFH,2CACvEA,aAEZ,IAAII,KAAKJ,YAqBpBK,kBACQC,SACAC,SAFIP,kEAAa,uBAGfQ,eAAiBJ,KAAKC,YAAYI,SAAQ,CAACC,QAASC,UACtDL,SAAWI,QACXH,SAAWI,SACZX,mBACHQ,eAAeE,QAAUJ,SACzBE,eAAeG,OAASJ,SAEjBC,8BA2BII,QAAIZ,kEAAa,uBACtBM,SAAW,IAAIG,SAAQ,CAACC,QAASC,UACnCE,EAAEC,KAAKC,WAAWf,YAElBY,GAAGF,QAASC,kBAGhBL,SAASU,MAAK,KACVH,EAAEC,KAAKG,YAAYjB,eAEpBkB,QAEIZ"} |