Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/icon.js

Issue 29334778: Issue 3532 - Improved preformance of icon animation and fixed a memory leak (Closed)
Patch Set: Moved and renamed functions Created Jan. 28, 2016, 10:13 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/icon.js
===================================================================
--- a/lib/icon.js
+++ b/lib/icon.js
@@ -27,6 +27,7 @@
let frameInterval = null;
let animationInterval = null;
+let onActivated = null;
let whitelistedState = new ext.PageMap();
function loadImage(url)
@@ -115,43 +116,53 @@
});
}
-function runAnimation(notificationType)
+function animateIcon(notificationType, frames)
{
- function playAnimation(frames)
+ ext.pages.query({active: true}, pages =>
{
let animationStep = 0;
- ext.pages.query({active: true}, pages =>
+ let opacity = 0;
+
+ onActivated = page =>
{
- function appendActivePage(page)
+ pages.push(page);
+ setIcon(page, notificationType, opacity, frames);
+ };
+ ext.pages.onActivated.addListener(onActivated);
+
+ frameInterval = setInterval(() =>
+ {
+ let oldOpacity = opacity;
+ opacity = frameOpacities[animationStep++];
+
+ if (opacity != oldOpacity)
{
- pages.push(page);
- }
- ext.pages.onActivated.addListener(appendActivePage);
-
- frameInterval = setInterval(() =>
- {
- let opacity = frameOpacities[animationStep++];
for (let page of pages)
{
if (whitelistedState.has(page))
setIcon(page, notificationType, opacity, frames);
- };
+ }
+ }
- if (animationStep > numberOfFrames)
- {
- animationStep = 0;
- clearInterval(frameInterval);
- frameInterval = null;
- ext.pages.onActivated.removeListener(appendActivePage);
- }
- }, 100);
- });
- }
+ if (animationStep > numberOfFrames)
+ {
+ clearInterval(frameInterval);
+ ext.pages.onActivated.removeListener(onActivated);
+ frameInterval = onActivated = null;
+ }
+ }, 100);
+ });
+}
+function runAnimationLoop(notificationType)
+{
renderFrames(notificationType).then(frames =>
{
- playAnimation(frames);
- animationInterval = setInterval(() => { playAnimation(frames); }, 10000);
+ animateIcon(notificationType, frames);
+ animationInterval = setInterval(() =>
+ {
+ animateIcon(notificationType, frames);
+ }, 10000);
});
}
@@ -179,7 +190,9 @@
clearInterval(frameInterval);
if (animationInterval != null)
clearInterval(animationInterval);
- frameInterval = animationInterval = null;
+ if (onActivated)
+ ext.pages.onActivated.removeListener(onActivated);
+ frameInterval = animationInterval = onActivated = null;
};
/**
@@ -190,5 +203,5 @@
exports.startIconAnimation = function(type)
{
stopIconAnimation();
- runAnimation(type);
+ runAnimationLoop(type);
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld