core/util
A collection of utility methods.
import util from '@enact/core/util';
Members
JobClass
import {Job} from '@enact/core/util';
Statics
- idle({…args})
Executes job when the CPU is idle.
0 or more Params
- args Any
- optional
Any args passed are forwarded to the callback
- idleUntil(timeout, {…args})
Executes job when the CPU is idle, or when the timeout is reached, whichever occurs first.
1 or more Params
- timeout Number
The number of milliseconds to wait before executing the job. This guarantees that the job is run, if a positive value is specified.
- args Any
- optional
Any args passed are forwarded to the callback
- start({…args})
Starts the job.
0 or more Params
- args Any
- optional
Any args passed are forwarded to the callback
- startAfter(timeout, {…args})
Starts the job in
timeout
milliseconds1 or more Params
- timeout Number
The number of milliseconds to wait before starting the job. This supersedes the timeout set at construction or by
setTimeout
.
- args Any
- optional
Any args passed are forwarded to the callback
- startRaf({…args})
Executes job before the next repaint.
0 or more Params
- args Any
- optional
Any args passed are forwarded to the callback
- startRafAfter(timeout, {…args})
Executes job before the next repaint after a given amount of timeout.
1 or more Params
- timeout Number
The number of milliseconds to wait before running requestAnimationFrame.
- args Any
- optional
Any args passed are forwarded to the callback
- stop()
Stops the job.
- throttle(…args)
Executes the job immediately, then prevents any other calls to
throttle()
from running until thetimeout
configured at construction or viasetTimeout
passes.1 or more Params
- args Any
Any args passed are forwarded to the callback
- throttleUntil(timeout, {…args})
Executes the job immediately, then prevents any other calls to
throttle()
from running fortimeout
milliseconds.1 or more Params
- timeout Number
The number of milliseconds to wait before allowing the job to be ran again. This supersedes the timeout set at construction or by
setTimeout
.
- args Any
- optional
Any args passed are forwarded to the callback
capFunction
- cap(str)String
Capitalizes a given string (not locale aware).
1 Param
- str String
The string to capitalize.
Returns
- String
The capitalized string.
childrenEqualsFunction❌
since 1.15.0. Will be removed in 2.0.0
- childrenEquals(prev, next, {ordered})Boolean
Compares the keys of two sets of children and returns
true
if they are equal.2 or more Params
- prev ArrayNode
Array of children
- next ArrayNode
Array of children
- ordered Boolean
- optional
- default: false
true
to require the same order
Returns
- Boolean
true
if the children are the same
coerceArrayFunction
- coerceArray(array)Array
If
arg
is array-like, return it. Otherwise returns a single element array containingarg
Example:
const returnsArray = coerceArray(0); // [0] const returnsArg = coerceArray([0]); // [0] const returnsObjArg = coerceArray({0: 'zeroth', length: 1});
1 Param
- array Any
Array or value
Returns
- Array
Either
array
or[array]
coerceFunctionFunction
- coerceFunction(arg)
If
arg
is a function, return it. Otherwise returns a function that returnsarg
Example:
const returnsZero = coerceFunction(0); const returnsArg = coerceFunction(() => 0);
1 Param
- arg Any
Function or value
extractAriaPropsFunction
- extractAriaProps(props)Object
Removes
aria-
prefixed props and therole
prop fromprops
and returns them in a new object. Useful when redirecting ARIA-related props from a non-focusable root element to a focusable child element.1 Param
- props Object
Props object
Returns
- Object
ARIA-related props
isRenderableFunction
- isRenderable(tag)Boolean
Loosely determines if
tag
is a renderable component (either a string or a function)1 Param
- tag Any
Component to tes
Returns
- Boolean
true
iftag
is renderable
perfNowFunction
- perfNow()Number
Gets current timestamp of either
window.performance.now
orDate.now
Returns
- Number