mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-25 00:28:31 -05:00
18 lines
450 B
CoffeeScript
18 lines
450 B
CoffeeScript
|
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]
|
||
|
|
||
|
module.exports = new NameLoader()
|