snappymail/dev/Common/Events.js
djmaze ea48f5060b isArray to native Array.isArray
isUnd(*) to native undefined === *
isFunc to native typeof * === 'function'
isObject to native typeof * === 'object'
microtime() to native Date().getTime();
noop to native ()=>{}
noopFalse to native ()=>false
noopTrue to native ()=>true
boolToAjax to native *?'1':'0'
Underscore.js to native
2020-07-29 21:49:41 +02:00

41 lines
765 B
JavaScript

import * as Plugins from 'Common/Plugins';
const SUBS = {};
/**
* @param {string|Object} name
* @param {Function} func
* @param {Object=} context
*/
export function sub(name, func, context) {
if (typeof name === 'object') {
context = func || null;
func = null;
Object.entries(name).forEach(([subFunc, subName]) => {
sub(subName, subFunc, context);
});
} else {
if (undefined === SUBS[name]) {
SUBS[name] = [];
}
SUBS[name].push([func, context]);
}
}
/**
* @param {string} name
* @param {Array=} args
*/
export function pub(name, args) {
Plugins.runHook('rl-pub', [name, args]);
if (undefined !== SUBS[name]) {
SUBS[name].forEach(items => {
if (items[0]) {
items[0].apply(items[1] || null, args || []);
}
});
}
}