mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-10 08:48:03 +08:00
ea48f5060b
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
41 lines
765 B
JavaScript
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 || []);
|
|
}
|
|
});
|
|
}
|
|
}
|