Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(g-base): delay should not work in toAttrs #427

Merged
merged 1 commit into from
Feb 26, 2020
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
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