feat: use "ric-shim" replace "window.requestIdleCallback" fix #829

This commit is contained in:
城危 2022-10-27 20:26:09 +08:00 committed by 刘菊萍(絮黎)
parent 319b13b559
commit b33cd1be88
4 changed files with 11 additions and 7 deletions

View File

@ -24,6 +24,7 @@
"enzyme-adapter-react-16": "^1.15.5", "enzyme-adapter-react-16": "^1.15.5",
"react": "^16", "react": "^16",
"react-dom": "^16.7.0", "react-dom": "^16.7.0",
"ric-shim": "^1.0.1",
"semver": "^7.3.5", "semver": "^7.3.5",
"zen-logger": "^1.1.0" "zen-logger": "^1.1.0"
}, },

View File

@ -1,3 +1,4 @@
import requestIdleCallback, { cancelIdleCallback } from 'ric-shim';
import { obx, computed, makeObservable } from '@alilc/lowcode-editor-core'; import { obx, computed, makeObservable } from '@alilc/lowcode-editor-core';
import { uniqueId } from '@alilc/lowcode-utils'; import { uniqueId } from '@alilc/lowcode-utils';
import { INodeSelector, IViewport } from '../simulator'; import { INodeSelector, IViewport } from '../simulator';
@ -136,7 +137,7 @@ export class OffsetObserver {
this._bottom = rect.bottom; this._bottom = rect.bottom;
this.hasOffset = true; this.hasOffset = true;
} }
this.pid = (window as any).requestIdleCallback(compute); this.pid = requestIdleCallback(compute);
pid = this.pid; pid = this.pid;
}; };
@ -145,13 +146,13 @@ export class OffsetObserver {
// try first // try first
compute(); compute();
// try second, ensure the dom mounted // try second, ensure the dom mounted
this.pid = (window as any).requestIdleCallback(compute); this.pid = requestIdleCallback(compute);
pid = this.pid; pid = this.pid;
} }
purge() { purge() {
if (this.pid) { if (this.pid) {
(window as any).cancelIdleCallback(this.pid); cancelIdleCallback(this.pid);
} }
this.pid = undefined; this.pid = undefined;
} }

View File

@ -19,7 +19,8 @@
"@alilc/lowcode-utils": "1.0.15", "@alilc/lowcode-utils": "1.0.15",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"react": "^16", "react": "^16",
"react-dom": "^16.7.0" "react-dom": "^16.7.0",
"ric-shim": "^1.0.1"
}, },
"devDependencies": { "devDependencies": {
"@alib/build-scripts": "^0.1.18", "@alib/build-scripts": "^0.1.18",

View File

@ -1,3 +1,4 @@
import requestIdleCallback, { cancelIdleCallback } from 'ric-shim';
import { computed, makeObservable, obx } from '@alilc/lowcode-editor-core'; import { computed, makeObservable, obx } from '@alilc/lowcode-editor-core';
import { import {
Designer, Designer,
@ -495,7 +496,7 @@ export class OutlineMain implements ISensor, ITreeBoard, IScrollable {
*/ */
scrollToNode(treeNode: TreeNode, detail?: any, tryTimes = 0) { scrollToNode(treeNode: TreeNode, detail?: any, tryTimes = 0) {
if (tryTimes < 1 && this.tryScrollAgain) { if (tryTimes < 1 && this.tryScrollAgain) {
(window as any).cancelIdleCallback(this.tryScrollAgain); cancelIdleCallback(this.tryScrollAgain);
this.tryScrollAgain = null; this.tryScrollAgain = null;
} }
if (this.sensing || !this.bounds || !this.scroller || !this.scrollTarget) { if (this.sensing || !this.bounds || !this.scroller || !this.scrollTarget) {
@ -512,7 +513,7 @@ export class OutlineMain implements ISensor, ITreeBoard, IScrollable {
if (!rect) { if (!rect) {
if (tryTimes < 3) { if (tryTimes < 3) {
this.tryScrollAgain = (window as any).requestIdleCallback(() => this.scrollToNode(treeNode, detail, tryTimes + 1)); this.tryScrollAgain = requestIdleCallback(() => this.scrollToNode(treeNode, detail, tryTimes + 1));
} }
return; return;
} }
@ -528,7 +529,7 @@ export class OutlineMain implements ISensor, ITreeBoard, IScrollable {
} }
// make tail scroll be sure // make tail scroll be sure
if (tryTimes < 4) { if (tryTimes < 4) {
this.tryScrollAgain = (window as any).requestIdleCallback(() => this.scrollToNode(treeNode, detail, 4)); this.tryScrollAgain = requestIdleCallback(() => this.scrollToNode(treeNode, detail, 4));
} }
} }