mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-04 23:17:02 +03:00
ES2015 first look / babeljs
This commit is contained in:
parent
5dcceaaca5
commit
445cd155e5
123 changed files with 3214 additions and 3680 deletions
65
dev/Common/Events.jsx
Normal file
65
dev/Common/Events.jsx
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
|
||||
import {_} from 'common';
|
||||
import Utils from 'Common/Utils';
|
||||
import Plugins from 'Common/Plugins';
|
||||
|
||||
class Events
|
||||
{
|
||||
constructor() {
|
||||
this.subs = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string|Object} name
|
||||
* @param {Function} func
|
||||
* @param {Object=} context
|
||||
* @return {Events}
|
||||
*/
|
||||
sub(name, func, context) {
|
||||
|
||||
if (Utils.isObject(name))
|
||||
{
|
||||
context = func || null;
|
||||
func = null;
|
||||
|
||||
_.each(name, (subFunc, subName) => {
|
||||
this.sub(subName, subFunc, context);
|
||||
}, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Utils.isUnd(this.subs[name]))
|
||||
{
|
||||
this.subs[name] = [];
|
||||
}
|
||||
|
||||
this.subs[name].push([func, context]);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {Array=} args
|
||||
* @return {Events}
|
||||
*/
|
||||
pub(name, args) {
|
||||
|
||||
Plugins.runHook('rl-pub', [name, args]);
|
||||
|
||||
if (!Utils.isUnd(this.subs[name]))
|
||||
{
|
||||
_.each(this.subs[name], (items) => {
|
||||
if (items[0])
|
||||
{
|
||||
items[0].apply(items[1] || null, args || []);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new Events();
|
||||
Loading…
Add table
Add a link
Reference in a new issue