Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vrender-animate/src/custom/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export class Update extends ACustomAnimate<Record<string, number>> {
let { diffAttrs = {} } = this.target.context ?? ({} as any);
const { options } = this.params as any;

diffAttrs = { ...diffAttrs };
if (options?.excludeChannels?.length) {
diffAttrs = { ...diffAttrs };
options.excludeChannels.forEach((channel: string) => {
delete diffAttrs[channel];
});
Expand Down
23 changes: 10 additions & 13 deletions packages/vrender-core/src/common/performance-raf.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { application } from '../application';

let idx = 0;

/**
* 性能优化,将requestAnimationFrame的回调函数存储起来,在下一帧执行
*/
export class PerformanceRAF {
nextAnimationFrameCbs: FrameRequestCallback[] = [];
nextAnimationFrameCbs: Map<number, FrameRequestCallback> = new Map();
private _rafHandle: number | null = null;

addAnimationFrameCb(callback: FrameRequestCallback) {
this.nextAnimationFrameCbs.push(callback);
this.nextAnimationFrameCbs.set(++idx, callback);
// 下一帧执行nextAnimationFrameCbs
this.tryRunAnimationFrameNextFrame();
return this.nextAnimationFrameCbs.length;
return idx;
}

/**
Expand All @@ -20,9 +22,8 @@ export class PerformanceRAF {
* @returns 是否移除成功
*/
removeAnimationFrameCb(index: number): boolean {
if (index > 0 && index <= this.nextAnimationFrameCbs.length) {
// Set to null instead of empty function to avoid linter error
this.nextAnimationFrameCbs[index - 1] = null;
if (this.nextAnimationFrameCbs.has(index)) {
this.nextAnimationFrameCbs.delete(index);
return true;
}
return false;
Expand All @@ -31,16 +32,12 @@ export class PerformanceRAF {
protected runAnimationFrame = (time: number) => {
this._rafHandle = null;
const cbs = this.nextAnimationFrameCbs;
this.nextAnimationFrameCbs = [];
for (let i = 0; i < cbs.length; i++) {
if (cbs[i]) {
cbs[i](time);
}
}
this.nextAnimationFrameCbs = new Map();
cbs.forEach(cb => cb(time));
};

protected tryRunAnimationFrameNextFrame = () => {
if (this._rafHandle !== null || this.nextAnimationFrameCbs.length === 0) {
if (this._rafHandle !== null || this.nextAnimationFrameCbs.size === 0) {
return;
}
this._rafHandle = application.global.getRequestAnimationFrame()(this.runAnimationFrame);
Expand Down
Loading