forked from xdan/jodit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/*! | ||
* Jodit Editor (https://xdsoft.net/jodit/) | ||
* Released under MIT see LICENSE.txt in the project root for license information. | ||
* Copyright (c) 2013-2021 Valeriy Chupurnov. All rights reserved. https://xdsoft.net | ||
*/ | ||
import type { | ||
DecoratorHandler, | ||
IDictionary, | ||
IViewBased, | ||
IViewComponent | ||
} from '../../types'; | ||
import { Component, STATUSES } from '../component'; | ||
import { error, isFunction, isViewObject } from '../helpers'; | ||
|
||
/** | ||
* Wrap function in requestIdleCallback wrapper* | ||
*/ | ||
export function idle<V = IViewComponent | IViewBased>(): DecoratorHandler { | ||
return <T extends Component & IDictionary>( | ||
target: IDictionary, | ||
propertyKey: string | ||
): void => { | ||
if (!isFunction(target[propertyKey])) { | ||
throw error('Handler must be a Function'); | ||
} | ||
|
||
target.hookStatus(STATUSES.ready, (component: V) => { | ||
const view = isViewObject(component) | ||
? component | ||
: (component as unknown as IViewComponent).jodit; | ||
|
||
const originalMethod = (component as any)[propertyKey]; | ||
|
||
(component as any)[propertyKey] = (...args: unknown[]) => | ||
view.async.requestIdleCallback( | ||
originalMethod.bind(component, ...args) | ||
); | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters