mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 08:08:15 -05:00
User loading now have async callbacks
This commit is contained in:
parent
ec78f95da1
commit
75b738f126
2 changed files with 8 additions and 5 deletions
|
@ -33,9 +33,12 @@ module.exports = class User extends CocoModel
|
|||
return "/file/#{photoURL}#{prefix}s=#{size}"
|
||||
return "/db/user/#{@id}/avatar?s=#{size}"
|
||||
|
||||
@getByID = (id, properties, force) ->
|
||||
# Callbacks can be either 'success' or 'error'
|
||||
@getByID = (id, properties, force, callbacks={}) ->
|
||||
{me} = require 'lib/auth'
|
||||
return me if me.id is id
|
||||
if me.id is id
|
||||
callbacks.success me if callbacks.success?
|
||||
return me
|
||||
user = cache[id] or new module.exports({_id: id})
|
||||
if force or not cache[id]
|
||||
user.loading = true
|
||||
|
@ -43,7 +46,8 @@ module.exports = class User extends CocoModel
|
|||
success: ->
|
||||
user.loading = false
|
||||
Backbone.Mediator.publish('user:fetched')
|
||||
#user.trigger 'sync' # needed?
|
||||
callbacks.success arguments... if callbacks.success?
|
||||
error: -> callbacks.error arguments... if callbacks.error?
|
||||
)
|
||||
cache[id] = user
|
||||
user
|
||||
|
|
|
@ -12,8 +12,7 @@ module.exports = class UserView extends RootView
|
|||
@listenTo @, 'userLoaded', @onUserLoaded
|
||||
|
||||
# TODO Ruben Assume ID for now
|
||||
@user = User.getByID(@nameOrID, {}, true) # Force fetching a user isn't really the clean way to go
|
||||
@user.fetch
|
||||
@user = User.getByID @nameOrID, {}, true,
|
||||
success: =>
|
||||
@trigger 'userLoaded', @user
|
||||
|
||||
|
|
Loading…
Reference in a new issue