Created
April 4, 2016 14:05
-
-
Save adammagana/7f258739a9c4a6927ce717496fb7a42a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
var colorList = [ | |
'#da1f2d', | |
'#00a550', | |
'#00acdc', | |
'#f37720', | |
'#fbaf17', | |
'#5c5da9', | |
'#c74398', | |
'#00ae9d', | |
'#085866', | |
'#3d5958', | |
'#8cc63e', | |
'#633a1c' | |
], | |
colorCache = {}, | |
colorIndex = 0; | |
function clearKeyAndColorCache() { | |
colorCache = {}; | |
} | |
function getAndCreateColorForKey(authorId) { | |
if (colorCache.hasOwnProperty(authorId) === false) { | |
colorCache[authorId] = colorList[colorIndex]; | |
if (colorList.length - 1 === colorIndex) { | |
colorIndex = 0; | |
} else { | |
colorIndex += 1; | |
} | |
} | |
return colorCache[authorId]; | |
} | |
module.exports = { | |
clearKeyAndColorCache: clearKeyAndColorCache, | |
getAndCreateColorForKey: getAndCreateColorForKey | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment