Ƭ LoaderState: Map
<Function
, LoaderStateArgs
>
• Const
loaderWildcard: typeof loaderWildcard
Using a this as an argument in the arguments list of getLoader will match any argument in that position
▸ getLoader<A
>(loaderState
, fn
, functionArgs?
): boolean
Returns true if the function with given arguments is loading and false otherwise.
example
if fn(1, 'a')
is currently loading, then
getLoader(loaderState, fn) // true
getLoader(loaderState, fn, [1, 'a']) // true
getLoader(loaderState, fn, [5, 'a']) // false
getLoader(loaderState, fn, [loaderWildcard, 'a']) //true
Name | Type |
---|---|
A |
extends any [] |
Name | Type | Default value | Description |
---|---|---|---|
loaderState |
LoaderState |
undefined |
An object where loading information is persisted |
fn |
(...args : A ) => any |
undefined |
The function to be tracked |
functionArgs |
undefined | A |
undefined |
The arguments to check for. The number and types of arguments should match the definition of the supplied function. functionArgs can be unspecified or undefined to check for any combination of arguments. Use loaderWildcard as an argument to match any argument in that position. |
boolean
▸ makeAutoLoader(loaderState
, item
, options?
): void
Automatically wraps all functions with wrapLoader in an object or class.
Name | Type | Description |
---|---|---|
loaderState |
object |
An object where loading information is persisted |
item |
object |
An object, class or array |
options |
Object |
- |
options.overrides? |
Object |
Disable wrapping on certain props. E.g. { myFn: false } will disable wrapping for myFn. Currently only supported for top level props. |
options.recursive? |
boolean |
Wraps objects, arrays and classes which are deeply nested in the input item. Defaults to true |
void
▸ setLoader<A
>(loaderState
, fn
, functionArgs
, isLoading
): void
Sets the loader state to indicate that a given function, called with a specific set of arguments, is running / finished. This function should be called every time a tracked function is started or finishes.
Name | Type |
---|---|
A |
extends any [] |
Name | Type | Description |
---|---|---|
loaderState |
LoaderState |
An object where loading information is persisted |
fn |
(...args : A ) => any |
The function to be tracked |
functionArgs |
A |
The arguments that the tracked function was called with. The length of this should be the same as the number of arguments that fn was defined with |
isLoading |
boolean |
True when the function starts and false when it ends |
void
▸ wrapLoader<A
, R
>(loaderState
, fn
): (...args
: A
) => R
Wraps a function so that it automatically sets the loading state to be true while the function is running. Any kind of function can be wrapped, but wrapLoader will only actually set loading state for asynchronous functions.
Name | Type |
---|---|
A |
extends any [] |
R |
R |
Name | Type | Description |
---|---|---|
loaderState |
LoaderState |
An object where loading information is persisted |
fn |
(...args : A ) => R |
Can be any function |
fn
A wrapped version of fn
▸ (...args
): R
Name | Type |
---|---|
...args |
A |
R