MDL-73314 core: Accept a Promise which resolves to string for toasts

This commit is contained in:
Andrew Nicols
2022-01-24 09:53:30 +08:00
parent e63604fb6d
commit ce0ac9ce75
2 changed files with 13 additions and 12 deletions
File diff suppressed because one or more lines are too long
+12 -11
View File
@@ -47,7 +47,7 @@ export const addToastRegion = async(parent) => {
* Add a new toast or snackbar notification to the page.
*
* @method
* @param {String} message
* @param {String|Promise<string>} message
* @param {Object} configuration
* @param {String} [configuration.title]
* @param {String} [configuration.subtitle]
@@ -60,16 +60,17 @@ export const addToastRegion = async(parent) => {
* import {add as addToast} from 'core/toast';
* import {get_string as getString} from 'core/str';
*
* getString('example', 'mod_myexample')
* .then(str => {
* addToast(str, {
* type: 'warning',
* autohide: false,
* closeButton: true,
* });
* return;
* })
* .catch();
* addToast('Example string', {
* type: 'warning',
* autohide: false,
* closeButton: true,
* });
*
* addToast(getString('example', 'mod_myexample'), {
* type: 'warning',
* autohide: false,
* closeButton: true,
* });
*/
export const add = async(message, configuration) => {
const pendingPromise = new Pending('addToastRegion');