rittenhop-ghost/versions/5.94.2/node_modules/@lexical/utils/mergeRegister.d.ts

33 lines
1.3 KiB
TypeScript
Raw Normal View History

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
type Func = () => void;
/**
* Returns a function that will execute all functions passed when called. It is generally used
* to register multiple lexical listeners and then tear them down with a single function call, such
* as React's useEffect hook.
* @example
* ```ts
* useEffect(() => {
* return mergeRegister(
* editor.registerCommand(...registerCommand1 logic),
* editor.registerCommand(...registerCommand2 logic),
* editor.registerCommand(...registerCommand3 logic)
* )
* }, [editor])
* ```
* In this case, useEffect is returning the function returned by mergeRegister as a cleanup
* function to be executed after either the useEffect runs again (due to one of its dependencies
* updating) or the component it resides in unmounts.
* Note the functions don't neccesarily need to be in an array as all arguements
* are considered to be the func argument and spread from there.
* @param func - An array of functions meant to be executed by the returned function.
* @returns the function which executes all the passed register command functions.
*/
export default function mergeRegister(...func: Array<Func>): () => void;
export {};