MCPcopy Create free account
hub / github.com/codecombat/codecombat / afterRender

Method afterRender

app/views/ladder/LadderView.js:306–351  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

304 }
305
306 afterRender () {
307 let hash
308 super.afterRender()
309 if (!this.supermodel.finished()) { return }
310 this.$el.toggleClass('single-ladder', this.level.isType('ladder'))
311 // tournamentState condition
312 // starting - show leaderboard && mymatches
313 // unset - leaderboard && mymatches
314 // unset and non-ladder - old leadearbod && mymatches
315 //
316 // initializing, ranking, waiting - nothing
317 // waiting for owner - only leaderboard
318 // ended - only leaderboard
319 if ((this.tournamentState === 'ended') || ((['waiting', 'abandoned'].includes(this.tournamentState)) && (me.get('_id') === (this.league != null ? this.league.get('ownerID') : undefined)))) {
320 this.insertSubView(this.ladderTab = new TournamentLeaderboard({ league: this.league, tournament: this.tournamentId, leagueType: 'clan', myTournamentSubmission: this.myTournamentSubmission }, this.level, this.sessions)) // classroom ladder do not have tournament for now
321 } else if (['initializing', 'ranking', 'waiting', 'abandoned'].includes(this.tournamentState)) {
322 null
323 } else { // starting, or unset
324 if (this.level.isType('ladder')) {
325 this.insertSubView(this.ladderTab = new TournamentLeaderboard({ league: this.league, leagueType: this.leagueType, course: this.course, myTournamentSubmission: this.myTournamentSubmission, updateSpectateList: this.updateSpectateList }, this.level, this.sessions, this.anonymousPlayerName))
326 } else {
327 this.insertSubView(this.ladderTab = new LadderTabView({ league: this.league, tournament: this.tournamentId }, this.level, this.sessions))
328 }
329 this.insertSubView(this.myMatchesTab = new MyMatchesTabView({ league: this.league, leagueType: this.leagueType, course: this.course }, this.level, this.sessions))
330 }
331 this.renderSelectors('#ladder-action-columns')
332 if (!this.level.isType('ladder') || !me.isAnonymous()) {
333 this.simulateTab = new SimulateTabView({ league: this.league, level: this.level, leagueID: this.leagueID })
334 this.insertSubView(this.simulateTab)
335 }
336 const highLoad = true
337 this.refreshDelay = (() => {
338 switch (false) {
339 case !!application.isProduction(): return 10 // Refresh very quickly in develompent.
340 case !this.league: return 20 // Refresh quickly when looking at a league ladder.
341 case !!highLoad: return 30 // Refresh slowly when in production.
342 case !!me.isAnonymous(): return 60 // Refresh even more slowly during HoC scaling.
343 default: return 300 // Refresh super slowly if anonymous during HoC scaling.
344 }
345 })()
346 this.refreshInterval = setInterval(this.fetchSessionsAndRefreshViews.bind(this), this.refreshDelay * 1000)
347 if (document.location.hash) { hash = document.location.hash.slice(1) }
348 if ((['humans', 'ogres'].includes(hash)) && !window.currentModal) {
349 if (this.sessions.loaded) { return this.showPlayModal(hash) }
350 }
351 }
352
353 fetchSessionsAndRefreshViews () {
354 if (this.destroyed || application.userIsIdle || ((new Date() - 2000) < this.lastRefreshTime) || !this.supermodel.finished()) { return }

Callers

nothing calls this directly

Calls 4

showPlayModalMethod · 0.95
isTypeMethod · 0.80
isAnonymousMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected