codecombat/app/lib/NameLoader.coffee

24 lines
520 B
CoffeeScript
Raw Normal View History

2014-04-11 17:19:17 -04:00
CocoClass = require 'lib/CocoClass'
namesCache = {}
class NameLoader extends CocoClass
loadNames: (ids) ->
toLoad = _.uniq (id for id in ids when not namesCache[id])
2014-04-11 17:19:17 -04:00
return false unless toLoad.length
jqxhrOptions = {
url: '/db/user/x/names',
type:'POST',
data:{ids:toLoad},
success: @loadedNames
}
return jqxhrOptions
2014-04-11 17:19:17 -04:00
loadedNames: (newNames) =>
_.extend namesCache, newNames
2014-06-24 17:25:01 -04:00
getName: (id) -> namesCache[id]?.name or id
2014-04-11 17:19:17 -04:00
module.exports = new NameLoader()