Skip to content

Commit 9d4d2b9

Browse files
committed
perf: improve performance
1 parent f484ff0 commit 9d4d2b9

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

src/clipboard.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function fallbackCopyText(text: string, options?: CopyTextOptions): void
4040
container = document.body
4141
} = isNullish(options) ? {} : options;
4242

43-
const textEl = createFakeElement(text);
43+
let textEl = createFakeElement(text);
4444
container.appendChild(textEl);
4545

4646
select(textEl);
@@ -56,6 +56,8 @@ export function fallbackCopyText(text: string, options?: CopyTextOptions): void
5656
}
5757
} finally {
5858
container.removeChild(textEl);
59+
// @ts-ignore
60+
textEl = null;
5961
window.getSelection()?.removeAllRanges(); // 清除选区
6062
}
6163
}

src/download.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ export function downloadURL(url: string, params?: LooseParams): void {
1818
* @param {Function} callback
1919
*/
2020
export function downloadHref(href: string, filename: string, callback?: Function): void {
21-
const eleLink = document.createElement('a');
21+
let eleLink = document.createElement('a');
2222
eleLink.download = filename;
2323
eleLink.style.display = 'none';
2424
eleLink.href = href;
2525
document.body.appendChild(eleLink);
2626
eleLink.click();
2727
setTimeout(() => {
2828
document.body.removeChild(eleLink);
29+
// @ts-ignore
30+
eleLink = null;
2931
if (isFunction(callback)) {
3032
callback();
3133
}

src/file.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function supportCanvas(): boolean {
1515
* @returns {HTMLInputElement}
1616
*/
1717
export function chooseLocalFile(accept: string, changeCb: (FileList) => any): void {
18-
const inputObj: HTMLInputElement = document.createElement('input');
18+
let inputObj: HTMLInputElement = document.createElement('input');
1919
inputObj.setAttribute('id', String(Date.now()));
2020
inputObj.setAttribute('type', 'file');
2121
inputObj.setAttribute('style', 'visibility:hidden');
@@ -26,7 +26,12 @@ export function chooseLocalFile(accept: string, changeCb: (FileList) => any): vo
2626
inputObj.onchange = (e: PointerEvent): any => {
2727
changeCb((<HTMLInputElement>e.target).files);
2828

29-
setTimeout(() => document.body.removeChild(inputObj));
29+
setTimeout(() => {
30+
document.body.removeChild(inputObj);
31+
32+
// @ts-ignore
33+
inputObj = null;
34+
});
3035
};
3136
}
3237

src/tooltip.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,12 @@ function mouseenter($customTitle: HTMLDivElement, title: string, e: PointerEvent
120120
* @returns {*}
121121
*/
122122
function handleMouseLeave(rootContainer: HTMLElement | string = '#root'): void {
123-
const rootEl = isString(rootContainer) ? document.querySelector(rootContainer) : rootContainer,
124-
titleEl = document.querySelector('#customTitle1494304949567');
123+
const rootEl = isString(rootContainer) ? document.querySelector(rootContainer) : rootContainer;
124+
let titleEl = document.querySelector('#customTitle1494304949567');
125125
if (rootEl && titleEl) {
126126
rootEl.removeChild(titleEl);
127+
// @ts-ignore
128+
titleEl = null;
127129
}
128130
}
129131
const tooltipEvent = { handleMouseEnter, handleMouseLeave };

src/watermark.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function genCanvasWM(content = '请勿外传', canvasWM?: ICanvasWM): voi
8383
const MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
8484
if (MutationObserver) {
8585
let mo: MutationObserver | null = new MutationObserver(function () {
86-
const __wm: HTMLElement | null = document.querySelector(`#${watermarkId}`); // 只在__wm元素变动才重新调用 __canvasWM
86+
let __wm: HTMLElement | null = document.querySelector(`#${watermarkId}`); // 只在__wm元素变动才重新调用 __canvasWM
8787
if (!__wm) {
8888
// 避免一直触发
8989
// console.log('regenerate watermark by delete::')
@@ -102,6 +102,9 @@ export function genCanvasWM(content = '请勿外传', canvasWM?: ICanvasWM): voi
102102
mo!.disconnect();
103103
mo = null;
104104
container.removeChild(__wm);
105+
106+
// @ts-ignore
107+
__wm = null;
105108
genCanvasWM(content, canvasWM);
106109
}
107110
}

0 commit comments

Comments
 (0)