Skip to content

Commit

Permalink
fix: dont stop all animations if one animation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aadityataparia committed May 14, 2019
1 parent c6304cb commit 5b3d6ee
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 30 deletions.
13 changes: 9 additions & 4 deletions dist/sifrr.animate.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/sifrr.animate.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/sifrr.animate.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions dist/sifrr.animate.module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/sifrr.animate.module.js.map

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions showcase/showcases.json

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions src/animateone.js
Expand Up @@ -35,7 +35,7 @@ function animateOne({
type = typeof type === 'function' ? type : new Bezier(types[type] || type);
const rawObj = { raw };

return wait(delay).then(() => new Promise(resolve => {
return wait(delay).then(() => new Promise((resolve, reject) => {
let startTime = performance.now();
const frame = function(currentTime) {
const percent = (currentTime - startTime) / time, bper = type(percent >= 1 ? 1 : percent);
Expand All @@ -44,9 +44,14 @@ function animateOne({
return round ? Math.round(n) : n;
});
const val = String.raw(rawObj, ...next);
target[prop] = Number(val) || val;
if (onUp) onUpdate(target, prop, target[prop]);
if (percent >= 1) resolve(frames.delete(frame));
try {
target[prop] = Number(val) || val;
if (onUp) onUpdate(target, prop, target[prop]);
if (percent >= 1) resolve(frames.delete(frame));
} catch(e) {
frames.delete(frame);
reject(e);
}
};
frames.add(frame);
}));
Expand Down
25 changes: 25 additions & 0 deletions test/browser/animate.test.js
Expand Up @@ -24,6 +24,31 @@ describe('animate', () => {
expect(target).to.deep.equal({ a: 100 });
});

it('works even if one animation errors', async () => {
const { i, target, error} = await page.evaluate(async () => {
let target = { a: 0 }, i = 0, onUpdate = () => i++, error;
await animate({
target: 'ok',
to: {
data: 100
}
}).catch(e => error = e);
await animate({
target,
to: {
a: 100
},
onUpdate
});

return { i, target, error };
});

expect(i).to.be.at.least(300/FRAME_TIME);
expect(target).to.deep.equal({ a: 100 });
expect(error).to.exist;
});

it('works with single digit', async () => {
const { i, target } = await page.evaluate(async () => {
let i = 0, onUpdate = () => i++;
Expand Down

0 comments on commit 5b3d6ee

Please sign in to comment.