This repository has been archived on 2025-05-04. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
codecombat/app/lib/NameLoader.coffee

18 lines
455 B
CoffeeScript
Raw Normal View History

2014-04-11 14:19:17 -07:00
CocoClass = require 'lib/CocoClass'
namesCache = {}
class NameLoader extends CocoClass
loadNames: (ids) ->
toLoad = (id for id in ids when not namesCache[id])
return false unless toLoad.length
jqxhr = $.ajax('/db/user/x/names', {type:'POST', data:{ids:toLoad}})
jqxhr.done @loadedNames
loadedNames: (newNames) =>
_.extend namesCache, newNames
getName: (id) -> namesCache[id].name
2014-04-11 14:19:17 -07:00
module.exports = new NameLoader()