Skip to content

Commit

Permalink
Fix switching log when redirecting without changing routes
Browse files Browse the repository at this point in the history
When the log changes, but without a route change (like when you switch
from one job to another job), we need to properly clean up and set up a
new log. The best way I figured out is to do it in didUpdateAttrs hook,
but only when the log actually changes. In such situation the old and
the new log should be past to teardown and setup functions.
  • Loading branch information
drogus committed Aug 18, 2015
1 parent ee52bea commit 86cd0f8
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions app/components/log-content.coffee
Expand Up @@ -56,19 +56,21 @@ LogContentComponent = Ember.Component.extend
console.log 'log view: will destroy' if Log.DEBUG
@teardownLog()

teardownLog: ->
if log = @get('log')
teardownLog: (log) ->
if log || log = @get('log')
parts = log.get('parts')
parts.removeArrayObserver(@, didChange: 'partsDidChange', willChange: 'noop')
parts.destroy()
log.notifyPropertyChange('parts')
@lineSelector?.willDestroy()
# log should do it on destroy
this.$('#log').empty()
if logElement = this.$('#log')
logElement.empty()

createEngine: (log) ->
if log || log = @get('log')
if logElement = this.$('#log')
logElement.empty()

createEngine: ->
if log = @get('log')
console.log 'log view: create engine' if Log.DEBUG
log.onClear =>
@teardownLog()
@createEngine()
Expand All @@ -81,17 +83,24 @@ LogContentComponent = Ember.Component.extend
@engine.limit = @limit
@logFolder = new LogFolder(@$('#log'))
@lineSelector = new LinesSelector(@$('#log'), @scroll, @logFolder)
@observeParts()
@observeParts(log)

didUpdateAttrs: ->
@teardownLog()
@createEngine()
didUpdateAttrs: (changes) ->
@_super.apply(this, arguments)

return unless changes.oldAttrs

if changes.newAttrs.job.value && changes.oldAttrs.job.value &&
changes.newAttrs.job.value != changes.oldAttrs.job.value

@teardownLog(changes.oldAttrs.job.value.get('log'))
@createEngine(changes.newAttrs.job.value.get('log'))

unfoldHighlight: ->
@lineSelector.unfoldLines()

observeParts: ->
if log = @get('log')
observeParts: (log) ->
if log || log = @get('log')
parts = log.get('parts')
parts.addArrayObserver(@, didChange: 'partsDidChange', willChange: 'noop')
parts = parts.slice(0)
Expand Down

0 comments on commit 86cd0f8

Please sign in to comment.