Skip to content

Commit

Permalink
fix(g-base): delay should not work in toAttrs, ref PR: #424
Browse files Browse the repository at this point in the history
  • Loading branch information
dengfuping committed Feb 26, 2020
1 parent 289af3e commit c7f33fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions packages/g-base/src/abstract/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const ARRAY_ATTRS = {

const CLONE_CFGS = ['zIndex', 'capture', 'visible', 'type'];

const RESERVED_PORPS = ['delay', 'repeat'];
// 可以在 toAttrs 中设置,但不属于绘图属性的字段
const RESERVED_PORPS = ['repeat'];

const DELEGATION_SPLIT = ':';
const WILDCARD = '*';
Expand Down Expand Up @@ -468,18 +469,17 @@ abstract class Element extends Base implements IElement {
onFrame = toAttrs as OnFrame;
toAttrs = {};
} else if (isObject(toAttrs) && (toAttrs as any).onFrame) {
// 兼容 3.0 中的写法,onFrame、delay 和 repeat 可在 toAttrs 中设置
// 兼容 3.0 中的写法,onFrame 和 repeat 可在 toAttrs 中设置
onFrame = (toAttrs as any).onFrame as OnFrame;
delay = (toAttrs as any).delay;
repeat = (toAttrs as any).repeat;
}
// 第二个参数,既可以是执行时间 duration,也可以是动画参数 animateCfg
if (isObject(duration)) {
animateCfg = duration as AnimateCfg;
duration = animateCfg.duration;
easing = animateCfg.easing || 'easeLinear';
delay = animateCfg.delay || 0;
// animateCfg 中的设置优先级更高
delay = animateCfg.delay || delay || 0;
repeat = animateCfg.repeat || repeat || false;
callback = animateCfg.callback || noop;
pauseCallback = animateCfg.pauseCallback || noop;
Expand Down
8 changes: 4 additions & 4 deletions packages/g-base/tests/unit/animate-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ describe('animate', () => {
}, 700);
});

// 兼容 3.0 中的写法,onFrame 可在 toAttrs 中设置
it('animate(toAttrs, duration, easing, callback, delay) and toAttrs has onFrame, delay and repeat property', (done) => {
// 兼容 3.0 中的写法,onFrame 和 repeat 可在 toAttrs 中设置
it('animate(toAttrs, duration, easing, callback, delay) and toAttrs has onFrame and repeat property', (done) => {
const shape = new Shape({
attrs: {
x: 50,
Expand All @@ -79,14 +79,14 @@ describe('animate', () => {
y: 50 + ratio * (100 - 50),
};
},
delay: 100,
repeat: true,
},
500,
'easeLinear',
() => {
flag = true;
}
},
100
);
expect(shape.attr('x')).eqls(50);
expect(shape.attr('y')).eqls(50);
Expand Down

0 comments on commit c7f33fe

Please sign in to comment.