Skip to content

ludvigalden/exectx

Repository files navigation

exectx

Stable Release Documentation Blazing Fast gzip size license


Classes

ContextExecution

A cancelable that holds mutable values and can inherit from other contexts and executions.

Execution

A cancelable that can inherit cancellation of other contexts and executions.

ExecutionSlotExecution

A cancelable that holds one execution simultaneously and cancels executions when replaced.

Members

defaultContext

The default React context that is used.

Functions

axiosExecutionRequest(config)AxiosPromise.<D>

Makes a request using {@linkcode axios.request} and attaches the specified execution, which will cancel the request whenever the execution is canceled.

createAxiosCancelTokenSource(execution)CancelTokenSource

Creates a {@linkcode CancelTokenSource} based on an execution for use with {@linkcode axios}.

createContext(values, parent)ReactContext.<V>

Creates a React context for a {@linkcode Context}. It can be nested using the {@linkcode ContextProvider}.

useContext(context)Context

React hook for consuming a provided {@linkcode Context}.

useExecution(parent, deps)Execution

React hook for using an {@linkcode Execution} that is canceled when the component is unmounted.

useExecutionFunc(innerFunc, options, deps)ExecutionFunc

React hook for using an execution-dependent function and cancel any pending call when the component is unmounted.

useExecutionSlot(parent, deps)ExecutionSlot

React hook for using an {@linkcode ExecutionSlot} that is canceled when the component is unmounted or when the deps change.

useResolvedValue(options, deps)RT | undefined

React hook for using a resolved value and cancelling any pending resolution of the value when the component unmounts or when any of the specified deps change.

executionFunc(innerFunc, options)ExecutionFunc

Transforms a function so that it always receives an execution as the last argument and only runs the function for one execution at a time. That is, if the function returned from executionFunc(innerFunc) is called with an execution, such as (...args, executionA), and is later called with a different execution before the previous call has finished (or the returned promise has been resolved), such as (...args, executionB), the execution passed to the func will be canceled. On the other hand, if it's called with the same executionA, the same value will be returned as from the previous call.

executionResolve(options)RT | Promise.<(RT|void)>

Resolves the specified value and applies any specified options, such as formatting the resolved value, handling interruptions, using default executions, nesting executions properly, and so on. It is useful if you don't know if a value will be resolved synchronously or asynchronously, and returning a promise in case any of the specified options leads to any asynchronicity. It can also be used as a tool for resolving expensive values.

executionRun(execution, ...actions)RunReturnValue.<T>

Runs one or more actions for an execution and returns the value returned from the last action.

nestContext(options)Execution

Makes a child context that inherits cancellation-state and values from any number of parent(s). It can be pre-constructed by specifying a child or constructed using a custom constructor.

nestExecution(options)Execution

Makes a child execution that inherits cancellation-state from any number of parent(s). It can be pre-constructed by specifying a child or constructed using a customConstructor.

parseExecutionsArg(arg)Array.<Execution>

Parses loosely specified executions into an array of valid executions.

Authors


MIT License.

About

Cancelable and type-safe executions and contexts

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published