@nent/core
Version:
34 lines (31 loc) • 1.06 kB
JavaScript
/*!
* NENT 2022
*/
import { A as ActionActivationStrategy } from './interfaces-837cdb60.js';
/**
* Activates action activators
* @param actionActivators
* @param forEvent
* @param [filter]
*/
async function activateActionActivators(actionActivators, forEvent, filter = _a => true) {
let once = forEvent == ActionActivationStrategy.AtTime ||
forEvent == ActionActivationStrategy.AtTimeEnd;
await Promise.all(actionActivators
.filter(activator => activator.activate === forEvent)
.filter(filter)
.map(async (activator) => {
await activator.activateActions(once);
}));
}
/**
* It sends all the actions in the array that pass the filter function
* @param {IActionElement[]} actions - An array of IActionElement objects.
* @param filter - (action: IActionElement | any) => boolean = _a => true,
*/
async function sendActions(actions, filter = _a => true) {
await Promise.all(actions.filter(filter).map(async (action) => {
await action.sendAction();
}));
}
export { activateActionActivators as a, sendActions as s };