mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-02-14 16:38:39 +00:00
implement todos
This commit is contained in:
parent
f9cacd2629
commit
58c84b1bb2
|
|
@ -88,38 +88,53 @@ export class EventManager
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger event finished
|
* Trigger event based on regex for group and/or id
|
||||||
*
|
*
|
||||||
* Executes the callback specified for this group if all events are finished
|
* @param {string|int} group Group id (can be regex)
|
||||||
*
|
* @param {string|int} [id] Event id (can be regex)
|
||||||
* @param {string|int} group Group id
|
|
||||||
* @param {string|int} [id] Event id
|
|
||||||
* @param {Object} [data] Data for event
|
* @param {Object} [data] Data for event
|
||||||
*
|
*
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
trigger (group, id = '', data = null)
|
triggerSimilar (group, id = '', data = null)
|
||||||
{
|
{
|
||||||
if (this.callbacks.hasOwnProperty(group)) {
|
const groupIsRegex = group.startsWith('/');
|
||||||
return this.triggerSingleEvent(group, id, data);
|
const idIsRegex = id.startsWith('/');
|
||||||
|
|
||||||
|
const groups = {};
|
||||||
|
if (groupIsRegex) {
|
||||||
|
for (const groupName in this.groups) {
|
||||||
|
if (groupName.match(group)) {
|
||||||
|
groups[groupName] = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
groups[group] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const allGroups = Object.keys(this.callbacks),
|
for (const groupName in groups) {
|
||||||
regex = new RegExp(group),
|
if (idIsRegex) {
|
||||||
length = allGroups.length;
|
for (const idName in this.groups[groupName]) {
|
||||||
|
if (idName.match(id)) {
|
||||||
let result = false;
|
groups[groupName].push(idName);
|
||||||
|
}
|
||||||
for (let i = 0; i < length; ++i) {
|
}
|
||||||
if (regex.test(allGroups[i])) {
|
} else {
|
||||||
result = result && this.triggerSingleEvent(allGroups[i], id, data);
|
groups[groupName].push(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
let triggerValue = false;
|
||||||
};
|
for (const groupName in groups) {
|
||||||
|
for (const id in groups[groupName]) {
|
||||||
|
triggerValue = triggerValue || this.trigger(groupName, id, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return triggerValue;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger event finished
|
* Trigger event finished
|
||||||
|
|
@ -134,8 +149,12 @@ export class EventManager
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
triggerSingleEvent (group, id = '', data = null)
|
trigger (group, id = '', data = null)
|
||||||
{
|
{
|
||||||
|
if (typeof this.callback[group] === 'undefined') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (Math.abs(Date.now() - this.callbacks[group].lastRun) < 500) {
|
if (Math.abs(Date.now() - this.callbacks[group].lastRun) < 500) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user