MDL-65493 core: Add pendingJS around pubsub.publish

This commit is contained in:
Andrew Nicols
2019-09-06 08:40:56 +08:00
parent 2cd63188aa
commit 05abf2cf2f
3 changed files with 43 additions and 48 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
define ("core/pubsub",[],function(){var a={};return{subscribe:function subscribe(b,c){a[b]=a[b]||[];a[b].push(c)},unsubscribe:function unsubscribe(b,c){if(a[b]){for(var d=0;d<a[b].length;d++){if(a[b][d]===c){a[b].splice(d,1);break}}}},publish:function publish(b,c){if(a[b]){a[b].forEach(function(a){a(c)})}}}});
define ("core/pubsub",["exports","core/pending"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.publish=a.unsubscribe=a.subscribe=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c={};a.subscribe=function subscribe(a,b){c[a]=c[a]||[];c[a].push(b)};a.unsubscribe=function unsubscribe(a,b){if(c[a]){for(var d=0;d<c[a].length;d++){if(c[a][d]===b){c[a].splice(d,1);break}}}};var d=function(a,d){var e=new b.default("Publishing "+a);if(c[a]){c[a].forEach(function(a){a(d)})}e.resolve()};a.publish=d});
//# sourceMappingURL=pubsub.min.js.map
+1 -1
View File
@@ -1 +1 @@
{"version":3,"sources":["../src/pubsub.js"],"names":["define","events","subscribe","eventName","callback","push","unsubscribe","i","length","splice","publish","data","forEach"],"mappings":"AAsBAA,OAAM,eAAC,EAAD,CAAK,UAAW,IAEdC,CAAAA,CAAM,CAAG,EAFK,CA8ClB,MAAO,CACHC,SAAS,CArCG,QAAZA,CAAAA,SAAY,CAASC,CAAT,CAAoBC,CAApB,CAA8B,CAC1CH,CAAM,CAACE,CAAD,CAAN,CAAoBF,CAAM,CAACE,CAAD,CAAN,EAAqB,EAAzC,CACAF,CAAM,CAACE,CAAD,CAAN,CAAkBE,IAAlB,CAAuBD,CAAvB,CACH,CAiCM,CAEHE,WAAW,CA3BG,QAAdA,CAAAA,WAAc,CAASH,CAAT,CAAoBC,CAApB,CAA8B,CAC5C,GAAIH,CAAM,CAACE,CAAD,CAAV,CAAuB,CACnB,IAAK,GAAII,CAAAA,CAAC,CAAG,CAAb,CAAgBA,CAAC,CAAGN,CAAM,CAACE,CAAD,CAAN,CAAkBK,MAAtC,CAA8CD,CAAC,EAA/C,CAAmD,CAC/C,GAAIN,CAAM,CAACE,CAAD,CAAN,CAAkBI,CAAlB,IAAyBH,CAA7B,CAAuC,CACnCH,CAAM,CAACE,CAAD,CAAN,CAAkBM,MAAlB,CAAyBF,CAAzB,CAA4B,CAA5B,EACA,KACH,CACJ,CACJ,CACJ,CAgBM,CAGHG,OAAO,CAXG,QAAVA,CAAAA,OAAU,CAASP,CAAT,CAAoBQ,CAApB,CAA0B,CACpC,GAAIV,CAAM,CAACE,CAAD,CAAV,CAAuB,CACnBF,CAAM,CAACE,CAAD,CAAN,CAAkBS,OAAlB,CAA0B,SAASR,CAAT,CAAmB,CACzCA,CAAQ,CAACO,CAAD,CACX,CAFD,CAGH,CACJ,CAEM,CAKV,CAnDK,CAAN","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 simple Javascript PubSub implementation.\n *\n * @module core/pubsub\n * @copyright 2018 Ryan Wyllie <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([], function() {\n\n var events = {};\n\n /**\n * Subscribe to an event.\n *\n * @param {string} eventName The name of the event to subscribe to.\n * @param {function} callback The callback function to run when eventName occurs.\n */\n var subscribe = function(eventName, callback) {\n events[eventName] = events[eventName] || [];\n events[eventName].push(callback);\n };\n\n /**\n * Unsubscribe from an event.\n *\n * @param {string} eventName The name of the event to unsubscribe from.\n * @param {function} callback The callback to unsubscribe.\n */\n var unsubscribe = function(eventName, callback) {\n if (events[eventName]) {\n for (var i = 0; i < events[eventName].length; i++) {\n if (events[eventName][i] === callback) {\n events[eventName].splice(i, 1);\n break;\n }\n }\n }\n };\n\n /**\n * Publish an event to all subscribers.\n *\n * @param {string} eventName The name of the event to publish.\n * @param {any} data The data to provide to the subscribed callbacks.\n */\n var publish = function(eventName, data) {\n if (events[eventName]) {\n events[eventName].forEach(function(callback) {\n callback(data);\n });\n }\n };\n\n return {\n subscribe: subscribe,\n unsubscribe: unsubscribe,\n publish: publish\n };\n});\n"],"file":"pubsub.min.js"}
{"version":3,"sources":["../src/pubsub.js"],"names":["events","subscribe","eventName","callback","push","unsubscribe","i","length","splice","publish","data","pendingPromise","Pending","forEach","resolve"],"mappings":"wKAsBA,uD,GAEMA,CAAAA,CAAM,CAAG,E,aAQU,QAAZC,CAAAA,SAAY,CAASC,CAAT,CAAoBC,CAApB,CAA8B,CACnDH,CAAM,CAACE,CAAD,CAAN,CAAoBF,CAAM,CAACE,CAAD,CAAN,EAAqB,EAAzC,CACAF,CAAM,CAACE,CAAD,CAAN,CAAkBE,IAAlB,CAAuBD,CAAvB,CACH,C,eAQ0B,QAAdE,CAAAA,WAAc,CAASH,CAAT,CAAoBC,CAApB,CAA8B,CACrD,GAAIH,CAAM,CAACE,CAAD,CAAV,CAAuB,CACnB,IAAK,GAAII,CAAAA,CAAC,CAAG,CAAb,CAAgBA,CAAC,CAAGN,CAAM,CAACE,CAAD,CAAN,CAAkBK,MAAtC,CAA8CD,CAAC,EAA/C,CAAmD,CAC/C,GAAIN,CAAM,CAACE,CAAD,CAAN,CAAkBI,CAAlB,IAAyBH,CAA7B,CAAuC,CACnCH,CAAM,CAACE,CAAD,CAAN,CAAkBM,MAAlB,CAAyBF,CAAzB,CAA4B,CAA5B,EACA,KACH,CACJ,CACJ,CACJ,C,CAQM,GAAMG,CAAAA,CAAO,CAAG,SAASP,CAAT,CAAoBQ,CAApB,CAA0B,CAC7C,GAAMC,CAAAA,CAAc,CAAG,GAAIC,UAAJ,CAAY,cAAgBV,CAA5B,CAAvB,CACA,GAAIF,CAAM,CAACE,CAAD,CAAV,CAAuB,CACnBF,CAAM,CAACE,CAAD,CAAN,CAAkBW,OAAlB,CAA0B,SAASV,CAAT,CAAmB,CACzCA,CAAQ,CAACO,CAAD,CACX,CAFD,CAGH,CACDC,CAAc,CAACG,OAAf,EACH,CARM,C","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 simple Javascript PubSub implementation.\n *\n * @module core/pubsub\n * @copyright 2018 Ryan Wyllie <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport Pending from 'core/pending';\n\nconst events = {};\n\n/**\n * Subscribe to an event.\n *\n * @param {string} eventName The name of the event to subscribe to.\n * @param {function} callback The callback function to run when eventName occurs.\n */\nexport const subscribe = function(eventName, callback) {\n events[eventName] = events[eventName] || [];\n events[eventName].push(callback);\n};\n\n/**\n * Unsubscribe from an event.\n *\n * @param {string} eventName The name of the event to unsubscribe from.\n * @param {function} callback The callback to unsubscribe.\n */\nexport const unsubscribe = function(eventName, callback) {\n if (events[eventName]) {\n for (var i = 0; i < events[eventName].length; i++) {\n if (events[eventName][i] === callback) {\n events[eventName].splice(i, 1);\n break;\n }\n }\n }\n};\n\n/**\n * Publish an event to all subscribers.\n *\n * @param {string} eventName The name of the event to publish.\n * @param {any} data The data to provide to the subscribed callbacks.\n */\nexport const publish = function(eventName, data) {\n const pendingPromise = new Pending(\"Publishing \" + eventName);\n if (events[eventName]) {\n events[eventName].forEach(function(callback) {\n callback(data);\n });\n }\n pendingPromise.resolve();\n};\n"],"file":"pubsub.min.js"}
+41 -46
View File
@@ -20,55 +20,50 @@
* @copyright 2018 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define([], function() {
import Pending from 'core/pending';
var events = {};
const events = {};
/**
* Subscribe to an event.
*
* @param {string} eventName The name of the event to subscribe to.
* @param {function} callback The callback function to run when eventName occurs.
*/
var subscribe = function(eventName, callback) {
events[eventName] = events[eventName] || [];
events[eventName].push(callback);
};
/**
* Subscribe to an event.
*
* @param {string} eventName The name of the event to subscribe to.
* @param {function} callback The callback function to run when eventName occurs.
*/
export const subscribe = function(eventName, callback) {
events[eventName] = events[eventName] || [];
events[eventName].push(callback);
};
/**
* Unsubscribe from an event.
*
* @param {string} eventName The name of the event to unsubscribe from.
* @param {function} callback The callback to unsubscribe.
*/
var unsubscribe = function(eventName, callback) {
if (events[eventName]) {
for (var i = 0; i < events[eventName].length; i++) {
if (events[eventName][i] === callback) {
events[eventName].splice(i, 1);
break;
}
/**
* Unsubscribe from an event.
*
* @param {string} eventName The name of the event to unsubscribe from.
* @param {function} callback The callback to unsubscribe.
*/
export const unsubscribe = function(eventName, callback) {
if (events[eventName]) {
for (var i = 0; i < events[eventName].length; i++) {
if (events[eventName][i] === callback) {
events[eventName].splice(i, 1);
break;
}
}
};
}
};
/**
* Publish an event to all subscribers.
*
* @param {string} eventName The name of the event to publish.
* @param {any} data The data to provide to the subscribed callbacks.
*/
var publish = function(eventName, data) {
if (events[eventName]) {
events[eventName].forEach(function(callback) {
callback(data);
});
}
};
return {
subscribe: subscribe,
unsubscribe: unsubscribe,
publish: publish
};
});
/**
* Publish an event to all subscribers.
*
* @param {string} eventName The name of the event to publish.
* @param {any} data The data to provide to the subscribed callbacks.
*/
export const publish = function(eventName, data) {
const pendingPromise = new Pending("Publishing " + eventName);
if (events[eventName]) {
events[eventName].forEach(function(callback) {
callback(data);
});
}
pendingPromise.resolve();
};