mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Migrate .on, .once - Batch 1
This commit is contained in:
parent
5852b87aa3
commit
67f5270bfc
11 changed files with 32 additions and 43 deletions
|
@ -58,7 +58,7 @@ init = ->
|
||||||
storage.save(CURRENT_USER_KEY, me.attributes)
|
storage.save(CURRENT_USER_KEY, me.attributes)
|
||||||
|
|
||||||
me.loadGravatarProfile() if me.get('email')
|
me.loadGravatarProfile() if me.get('email')
|
||||||
me.on('sync', userSynced)
|
@listenTo(me, 'sync', userSynced)
|
||||||
|
|
||||||
userSynced = (user) ->
|
userSynced = (user) ->
|
||||||
Backbone.Mediator.publish('me:synced', {me:user})
|
Backbone.Mediator.publish('me:synced', {me:user})
|
||||||
|
|
|
@ -11,14 +11,14 @@ module.exports = class ProfileView extends View
|
||||||
super options
|
super options
|
||||||
@user = User.getByID(@userID)
|
@user = User.getByID(@userID)
|
||||||
@loading = false if 'gravatarProfile' of @user
|
@loading = false if 'gravatarProfile' of @user
|
||||||
@user.on('change', @userChanged)
|
@listenTo(@user, 'change', @userChanged)
|
||||||
@user.on('error', @userError)
|
@listenTo(@user, 'error', @userError)
|
||||||
|
|
||||||
userChanged: (user) =>
|
userChanged: (user) ->
|
||||||
@loading = false if 'gravatarProfile' of user
|
@loading = false if 'gravatarProfile' of user
|
||||||
@render()
|
@render()
|
||||||
|
|
||||||
userError: (user) =>
|
userError: (user) ->
|
||||||
@loading = false
|
@loading = false
|
||||||
@render()
|
@render()
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,11 @@ module.exports = class SettingsView extends View
|
||||||
@save = _.debounce(@save, 200)
|
@save = _.debounce(@save, 200)
|
||||||
super options
|
super options
|
||||||
return unless me
|
return unless me
|
||||||
me.on('change', @refreshPicturePane) # depends on gravatar load
|
@listenTo(me, 'change', @refreshPicturePane) # depends on gravatar load
|
||||||
me.on('invalid', (errors) -> forms.applyErrorsToForm(@$el, me.validationError))
|
@listenTo(me, 'invalid', (errors) -> forms.applyErrorsToForm(@$el, me.validationError))
|
||||||
window.f = @getSubscriptions
|
window.f = @getSubscriptions
|
||||||
|
|
||||||
refreshPicturePane: =>
|
refreshPicturePane: ->
|
||||||
h = $(@template(@getRenderData()))
|
h = $(@template(@getRenderData()))
|
||||||
newPane = $('#picture-pane', h)
|
newPane = $('#picture-pane', h)
|
||||||
oldPane = $('#picture-pane')
|
oldPane = $('#picture-pane')
|
||||||
|
|
|
@ -18,7 +18,7 @@ module.exports = class LevelSessionsView extends View
|
||||||
getLevelSessions: ->
|
getLevelSessions: ->
|
||||||
@sessions = new LevelSessionCollection
|
@sessions = new LevelSessionCollection
|
||||||
@sessions.fetch()
|
@sessions.fetch()
|
||||||
@sessions.on('all', @render)
|
@listenTo(@sessions, 'all', @render)
|
||||||
|
|
||||||
getRenderData: =>
|
getRenderData: =>
|
||||||
c = super()
|
c = super()
|
||||||
|
|
|
@ -36,7 +36,7 @@ module.exports = class UsersView extends View
|
||||||
})
|
})
|
||||||
@users = new UserCollection()
|
@users = new UserCollection()
|
||||||
@users.fetch()
|
@users.fetch()
|
||||||
@users.on('all', @render)
|
@listenTo(@users, 'all', @render)
|
||||||
|
|
||||||
getRenderData: =>
|
getRenderData: =>
|
||||||
c = super()
|
c = super()
|
||||||
|
|
|
@ -20,15 +20,15 @@ module.exports = class ArticleEditView extends View
|
||||||
@article = new Article(_id: @articleID)
|
@article = new Article(_id: @articleID)
|
||||||
@article.saveBackups = true
|
@article.saveBackups = true
|
||||||
@article.fetch()
|
@article.fetch()
|
||||||
@article.once('sync', @onArticleSync)
|
@listenToOnce(@article, 'sync', @onArticleSync)
|
||||||
@article.on('schema-loaded', @buildTreema)
|
@listenTo(@article, 'schema-loaded', @buildTreema)
|
||||||
@pushChangesToPreview = _.throttle(@pushChangesToPreview, 500)
|
@pushChangesToPreview = _.throttle(@pushChangesToPreview, 500)
|
||||||
|
|
||||||
onArticleSync: =>
|
onArticleSync: ->
|
||||||
@article.loaded = true
|
@article.loaded = true
|
||||||
@buildTreema()
|
@buildTreema()
|
||||||
|
|
||||||
buildTreema: =>
|
buildTreema: ->
|
||||||
return if @treema? or (not @article.loaded) or (not Article.hasSchema())
|
return if @treema? or (not @article.loaded) or (not Article.hasSchema())
|
||||||
unless @article.attributes.body
|
unless @article.attributes.body
|
||||||
@article.set('body', '')
|
@article.set('body', '')
|
||||||
|
|
|
@ -64,7 +64,7 @@ module.exports = class ThangTypeHomeView extends View
|
||||||
|
|
||||||
@collection = new SearchCollection(@modelURL, @model, term)
|
@collection = new SearchCollection(@modelURL, @model, term)
|
||||||
@collection.term = term # needed?
|
@collection.term = term # needed?
|
||||||
@collection.on('sync', @onSearchChange)
|
@listenTo(@collection, 'sync', @onSearchChange)
|
||||||
@showLoading(@$el.find('.results'))
|
@showLoading(@$el.find('.results'))
|
||||||
|
|
||||||
@updateHash(term)
|
@updateHash(term)
|
||||||
|
@ -79,7 +79,7 @@ module.exports = class ThangTypeHomeView extends View
|
||||||
return false unless @collection
|
return false unless @collection
|
||||||
return term is @collection.term
|
return term is @collection.term
|
||||||
|
|
||||||
onSearchChange: =>
|
onSearchChange: ->
|
||||||
@hideLoading()
|
@hideLoading()
|
||||||
documents = @collection.models
|
documents = @collection.models
|
||||||
table = $(@tableTemplate(documents:documents))
|
table = $(@tableTemplate(documents:documents))
|
||||||
|
@ -88,7 +88,6 @@ module.exports = class ThangTypeHomeView extends View
|
||||||
|
|
||||||
removeOldSearch: ->
|
removeOldSearch: ->
|
||||||
return unless @collection?
|
return unless @collection?
|
||||||
@collection.off()
|
|
||||||
@collection = null
|
@collection = null
|
||||||
|
|
||||||
makeNewModel: (e) ->
|
makeNewModel: (e) ->
|
||||||
|
|
|
@ -23,14 +23,14 @@ module.exports = class VersionsModalView extends ModalView
|
||||||
super options
|
super options
|
||||||
@view = new model(_id: @ID)
|
@view = new model(_id: @ID)
|
||||||
@view.fetch()
|
@view.fetch()
|
||||||
@view.once('sync', @onViewSync)
|
@listenToOnce(@view, 'sync', @onViewSync)
|
||||||
|
|
||||||
onViewSync: =>
|
onViewSync: ->
|
||||||
@collection = new VersionsViewCollection(@url, @view.attributes.original, @model)
|
@collection = new VersionsViewCollection(@url, @view.attributes.original, @model)
|
||||||
@collection.fetch()
|
@collection.fetch()
|
||||||
@collection.on('sync', @onVersionFetched)
|
@listenTo(@collection, 'sync', @onVersionFetched)
|
||||||
|
|
||||||
onVersionFetched: =>
|
onVersionFetched: ->
|
||||||
@startsLoading = false
|
@startsLoading = false
|
||||||
@render()
|
@render()
|
||||||
|
|
||||||
|
|
|
@ -43,13 +43,13 @@ module.exports = class PlaybackView extends View
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
super(arguments...)
|
super(arguments...)
|
||||||
me.on('change:music', @updateMusicButton, @)
|
@listenTo(me, 'change:music', @updateMusicButton)
|
||||||
|
|
||||||
afterRender: ->
|
afterRender: ->
|
||||||
super()
|
super()
|
||||||
@hookUpScrubber()
|
@hookUpScrubber()
|
||||||
@updateMusicButton()
|
@updateMusicButton()
|
||||||
$(window).on('resize', @onWindowResize)
|
@listenTo($(window), 'resize', @onWindowResize)
|
||||||
|
|
||||||
# callbacks
|
# callbacks
|
||||||
|
|
||||||
|
@ -223,7 +223,5 @@ module.exports = class PlaybackView extends View
|
||||||
$(document.activeElement).blur()
|
$(document.activeElement).blur()
|
||||||
|
|
||||||
destroy: ->
|
destroy: ->
|
||||||
me.off('change:music', @updateMusicButton, @)
|
|
||||||
$(window).off('resize', @onWindowResize)
|
|
||||||
@onWindowResize = null
|
@onWindowResize = null
|
||||||
super()
|
super()
|
||||||
|
|
|
@ -82,8 +82,8 @@ module.exports = class PlayLevelView extends View
|
||||||
@isEditorPreview = @getQueryVariable 'dev'
|
@isEditorPreview = @getQueryVariable 'dev'
|
||||||
@sessionID = @getQueryVariable 'session'
|
@sessionID = @getQueryVariable 'session'
|
||||||
|
|
||||||
$(window).on('resize', @onWindowResize)
|
@listenTo($(window), 'resize', @onWindowResize)
|
||||||
@supermodel.once 'error', @onLevelLoadError
|
@listenToOnce(@supermodel, 'error', @onLevelLoadError)
|
||||||
@saveScreenshot = _.throttle @saveScreenshot, 30000
|
@saveScreenshot = _.throttle @saveScreenshot, 30000
|
||||||
|
|
||||||
if @isEditorPreview
|
if @isEditorPreview
|
||||||
|
@ -95,7 +95,7 @@ module.exports = class PlayLevelView extends View
|
||||||
else
|
else
|
||||||
@load()
|
@load()
|
||||||
|
|
||||||
onLevelLoadError: (e) =>
|
onLevelLoadError: (e) ->
|
||||||
application.router.navigate "/play?not_found=#{@levelID}", {trigger: true}
|
application.router.navigate "/play?not_found=#{@levelID}", {trigger: true}
|
||||||
|
|
||||||
setLevel: (@level, @supermodel) ->
|
setLevel: (@level, @supermodel) ->
|
||||||
|
@ -108,8 +108,8 @@ module.exports = class PlayLevelView extends View
|
||||||
|
|
||||||
load: ->
|
load: ->
|
||||||
@levelLoader = new LevelLoader supermodel: @supermodel, levelID: @levelID, sessionID: @sessionID, opponentSessionID: @getQueryVariable('opponent'), team: @getQueryVariable("team")
|
@levelLoader = new LevelLoader supermodel: @supermodel, levelID: @levelID, sessionID: @sessionID, opponentSessionID: @getQueryVariable('opponent'), team: @getQueryVariable("team")
|
||||||
@levelLoader.once 'loaded-all', @onLevelLoaderLoaded, @
|
@listenToOnce(@levelLoader, 'loaded-all', @onLevelLoaderLoaded)
|
||||||
@levelLoader.on 'progress', @onLevelLoaderProgressChanged, @
|
@listenTo(@levelLoader, 'progress', @onLevelLoaderProgressChanged)
|
||||||
@god = new God()
|
@god = new God()
|
||||||
|
|
||||||
getRenderData: ->
|
getRenderData: ->
|
||||||
|
@ -168,7 +168,7 @@ module.exports = class PlayLevelView extends View
|
||||||
@initScriptManager()
|
@initScriptManager()
|
||||||
@insertSubviews ladderGame: (@level.get('type') is "ladder")
|
@insertSubviews ladderGame: (@level.get('type') is "ladder")
|
||||||
@initVolume()
|
@initVolume()
|
||||||
@session.on 'change:multiplayer', @onMultiplayerChanged, @
|
@listenTo(@session, 'change:multiplayer', @onMultiplayerChanged)
|
||||||
@originalSessionState = $.extend(true, {}, @session.get('state'))
|
@originalSessionState = $.extend(true, {}, @session.get('state'))
|
||||||
@register()
|
@register()
|
||||||
@controlBar.setBus(@bus)
|
@controlBar.setBus(@bus)
|
||||||
|
@ -462,20 +462,16 @@ module.exports = class PlayLevelView extends View
|
||||||
AudioPlayer.preloadSoundReference sound
|
AudioPlayer.preloadSoundReference sound
|
||||||
|
|
||||||
destroy: ->
|
destroy: ->
|
||||||
@supermodel?.off 'error', @onLevelLoadError
|
|
||||||
@levelLoader?.off 'loaded-all', @onLevelLoaderLoaded
|
|
||||||
@levelLoader?.destroy()
|
@levelLoader?.destroy()
|
||||||
@surface?.destroy()
|
@surface?.destroy()
|
||||||
@god?.destroy()
|
@god?.destroy()
|
||||||
@goalManager?.destroy()
|
@goalManager?.destroy()
|
||||||
@scriptManager?.destroy()
|
@scriptManager?.destroy()
|
||||||
$(window).off('resize', @onWindowResize)
|
|
||||||
delete window.world # not sure where this is set, but this is one way to clean it up
|
delete window.world # not sure where this is set, but this is one way to clean it up
|
||||||
clearInterval(@pointerInterval)
|
clearInterval(@pointerInterval)
|
||||||
@bus?.destroy()
|
@bus?.destroy()
|
||||||
#@instance.save() unless @instance.loading
|
#@instance.save() unless @instance.loading
|
||||||
console.profileEnd?() if PROFILE_ME
|
console.profileEnd?() if PROFILE_ME
|
||||||
@session?.off 'change:multiplayer', @onMultiplayerChanged, @
|
|
||||||
@onLevelLoadError = null
|
@onLevelLoadError = null
|
||||||
@onLevelLoaderLoaded = null
|
@onLevelLoaderLoaded = null
|
||||||
@onSupermodelLoadedOne = null
|
@onSupermodelLoadedOne = null
|
||||||
|
|
|
@ -68,8 +68,8 @@ module.exports = class SpectateLevelView extends View
|
||||||
constructor: (options, @levelID) ->
|
constructor: (options, @levelID) ->
|
||||||
console.profile?() if PROFILE_ME
|
console.profile?() if PROFILE_ME
|
||||||
super options
|
super options
|
||||||
$(window).on('resize', @onWindowResize)
|
@listenTo($(window), 'resize', @onWindowResize)
|
||||||
@supermodel.once 'error', @onLevelLoadError
|
@listenToOnce(@supermodel, 'error', @onLevelLoadError)
|
||||||
|
|
||||||
@sessionOne = @getQueryVariable 'session-one'
|
@sessionOne = @getQueryVariable 'session-one'
|
||||||
@sessionTwo = @getQueryVariable 'session-two'
|
@sessionTwo = @getQueryVariable 'session-two'
|
||||||
|
@ -105,8 +105,8 @@ module.exports = class SpectateLevelView extends View
|
||||||
opponentSessionID: @sessionTwo
|
opponentSessionID: @sessionTwo
|
||||||
spectateMode: true
|
spectateMode: true
|
||||||
team: @getQueryVariable("team")
|
team: @getQueryVariable("team")
|
||||||
@levelLoader.once 'loaded-all', @onLevelLoaderLoaded, @
|
@listenToOnce(@levelLoader, 'loaded-all', @onLevelLoaderLoaded)
|
||||||
@levelLoader.on 'progress', @onLevelLoaderProgressChanged, @
|
@listenTo(@levelLoader, 'progress', @onLevelLoaderProgressChanged)
|
||||||
@god = new God maxWorkerPoolSize: 1, maxAngels: 1
|
@god = new God maxWorkerPoolSize: 1, maxAngels: 1
|
||||||
|
|
||||||
getRenderData: ->
|
getRenderData: ->
|
||||||
|
@ -467,18 +467,14 @@ module.exports = class SpectateLevelView extends View
|
||||||
cb(null, $.parseJSON(jqxhr.responseText))
|
cb(null, $.parseJSON(jqxhr.responseText))
|
||||||
|
|
||||||
destroy: ()->
|
destroy: ()->
|
||||||
@supermodel?.off 'error', @onLevelLoadError
|
|
||||||
@levelLoader?.off 'loaded-all', @onLevelLoaderLoaded
|
|
||||||
@levelLoader?.destroy()
|
@levelLoader?.destroy()
|
||||||
@surface?.destroy()
|
@surface?.destroy()
|
||||||
@god?.destroy()
|
@god?.destroy()
|
||||||
@goalManager?.destroy()
|
@goalManager?.destroy()
|
||||||
@scriptManager?.destroy()
|
@scriptManager?.destroy()
|
||||||
$(window).off('resize', @onWindowResize)
|
|
||||||
delete window.world # not sure where this is set, but this is one way to clean it up
|
delete window.world # not sure where this is set, but this is one way to clean it up
|
||||||
clearInterval(@pointerInterval)
|
clearInterval(@pointerInterval)
|
||||||
console.profileEnd?() if PROFILE_ME
|
console.profileEnd?() if PROFILE_ME
|
||||||
@session?.off 'change:multiplayer', @onMultiplayerChanged, @
|
|
||||||
@onLevelLoadError = null
|
@onLevelLoadError = null
|
||||||
@onLevelLoaderLoaded = null
|
@onLevelLoaderLoaded = null
|
||||||
@onSupermodelLoadedOne = null
|
@onSupermodelLoadedOne = null
|
||||||
|
|
Loading…
Reference in a new issue