core/utils

Utility functions.

Source:
License:
  • http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Members

(static, constant) getNormalisedComponent

Source:

Normalise the provided component such that '', 'moodle', and 'core' are treated consistently.

(inner, constant) debounceMap

Source:
Properties:
Name Type Description
debounceMap Map

A map of functions to their debounced pending promises.

Methods

(static) debounce(func, wait, optionsopt) → {function}

Source:

Create a wrapper function to debounce the execution of the given function. Each attempt to execute the function will reset the cooldown period.

Parameters:
Name Type Attributes Description
func function

The function to debounce

wait Number

The number of milliseconds to wait after the final attempt to execute

options Object <optional>
Properties
Name Type Attributes Default Description
pending boolean <optional>
false

Whether to wrap the debounced method in a pending promise

cancel boolean <optional>
false

Whether to add a cancel method to the debounced function

Returns:
Type
function

(static) throttle(func, wait) → {function}

Source:

Create a wrapper function to throttle the execution of the given

function to at most once every specified period.

If the function is attempted to be executed while it's in cooldown (during the wait period) then it'll immediately execute again as soon as the cooldown is over.

Parameters:
Name Type Description
func function

The function to throttle

wait Number

The number of milliseconds to wait between executions

Returns:
Type
function