codecombat/app/lib/NameLoader.coffee
Scott Erickson 3dc3f62473 Merge branch 'master' into feature/loading-views
Conflicts:
	app/views/editor/components/main.coffee
2014-04-25 14:31:58 -07:00

23 lines
506 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
jqxhrOptions = {
url: '/db/user/x/names',
type:'POST',
data:{ids:toLoad},
success: @loadedNames
}
return jqxhrOptions
loadedNames: (newNames) =>
_.extend namesCache, newNames
getName: (id) -> namesCache[id].name
module.exports = new NameLoader()