Javascript

Helper

Allowing plugins to interact

core/js/helper.js utilizes a custom hook system in JavaScript to allow plugins to integrate seamlessly into the functionality of the application. The hook system in JavaScript enables a modular and extensible architecture, allowing plugins to interact and influence the application's behavior without tightly coupling their code.

function add_to_function(name, func) {
  if (!hooks[name]) hooks[name] = [];
  hooks[name].push(func);
}

This JavaScript function facilitates the addition of functions to specific hooks. It checks if a hook with the given name exists in the hooks object. If not, it creates an array to store associated functions. Then, it adds the provided function to that hook.

function call_my_function(name, params) {
  if (hooks[name])
     hooks[name].forEach(func => func(params));
}

This JavaScript function is responsible for executing all functions associated with a specific hook. If the hook exists in the hooks object, it iterates through the array of functions linked to that hook and executes each function, passing along any provided parameters.