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