<commit_before>path = require 'path'
{$} = require 'atom-space-pen-views'
{CompositeDisposable} = require 'atom'

module.exports =
class TabView extends HTMLElement
  initialize: (@item) ->
    if typeof @item.getPath is 'function'
      @path = @item.getPath()
      @isPreviewTab = atom.config.get('tabs.usePreviewTabs')

    @classList.add('tab', 'sortable')

    @itemTitle = document.createElement('div')
    @itemTitle.classList.add('title')
    @appendChild(@itemTitle)

    closeIcon = document.createElement('div')
    closeIcon.classList.add('close-icon')
    @appendChild(closeIcon)

    @subscriptions = new CompositeDisposable()

    @handleEvents()
    @updateDataAttributes()
    @updateTitle()
    @updateIcon()
    @updateModifiedStatus()
    @setupTooltip()

    if @isPreviewTab
      @itemTitle.classList.add('temp')
      @classList.add('preview-tab')
      @addEventListener 'dblclick', => @clearPreview()

  handleEvents: ->
    titleChangedHandler = =>
      @updateDataAttributes()
      @updateTitle()
      @updateTooltip()

    if typeof @item.onDidChangeTitle is 'function'
      @subscriptions.add @item.onDidChangeTitle(titleChangedHandler)
    else if typeof @item.on is 'function'
      #TODO Remove once old events are no longer supported
      @item.on('title-changed', titleChangedHandler)
      @subscriptions.add dispose: =>
        @item.off?('title-changed', titleChangedHandler)

    iconChangedHandler = =>
      @updateIcon()

    if typeof @item.onDidChangeIcon is 'function'
      @subscriptions.add @item.onDidChangeIcon? =>
        @updateIcon()
    else if typeof @item.on is 'function'
      #TODO Remove once old events are no longer supported
      @item.on('icon-changed', iconChangedHandler)
      @subscriptions.add dispose: =>
        @item.off?('icon-changed', iconChangedHandler)

    modifiedHandler = =>
      @updateModifiedStatus()

    if typeof @item.onDidChangeModified is 'function'
      @subscriptions.add @item.onDidChangeModified(modifiedHandler)
    else if typeof @item.on is 'function'<commit_msg>Warn when `onDidChange` functions are not valid `Disposable`s<commit_after>path = require 'path'
{$} = require 'atom-space-pen-views'
{Disposable, CompositeDisposable} = require 'atom'

module.exports =
class TabView extends HTMLElement
  initialize: (@item) ->
    if typeof @item.getPath is 'function'
      @path = @item.getPath()
      @isPreviewTab = atom.config.get('tabs.usePreviewTabs')

    @classList.add('tab', 'sortable')

    @itemTitle = document.createElement('div')
    @itemTitle.classList.add('title')
    @appendChild(@itemTitle)

    closeIcon = document.createElement('div')
    closeIcon.classList.add('close-icon')
    @appendChild(closeIcon)

    @subscriptions = new CompositeDisposable()

    @handleEvents()
    @updateDataAttributes()
    @updateTitle()
    @updateIcon()
    @updateModifiedStatus()
    @setupTooltip()

    if @isPreviewTab
      @itemTitle.classList.add('temp')
      @classList.add('preview-tab')
      @addEventListener 'dblclick', => @clearPreview()

  handleEvents: ->
    titleChangedHandler = =>
      @updateDataAttributes()
      @updateTitle()
      @updateTooltip()

    if typeof @item.onDidChangeTitle is 'function'
      onDidChangeTitleDisposable = @item.onDidChangeTitle(titleChangedHandler)
      if Disposable.isDisposable(onDidChangeTitleDisposable)
        @subscriptions.add(onDidChangeTitleDisposable)
      else
        console.warn "::onDidChangeTitle does not return a valid disposable!"
    else if typeof @item.on is 'function'
      #TODO Remove once old events are no longer supported
      @item.on('title-changed', titleChangedHandler)
      @subscriptions.add dispose: =>
        @item.off?('title-changed', titleChangedHandler)

    iconChangedHandler = =>
      @updateIcon()

    if typeof @item.onDidChangeIcon is 'function'
      @subscriptions.add @item.onDidChangeIcon? =>
        @updateIcon()
    else if typeof @item.on is 'function'
      #TODO Remove once old events are no longer supported
      @item.on('icon-changed', iconChangedHandler)
      @subscriptions.add dispose: =>
        @item.off?('icon-changed', iconChangedHandler)

    modifiedHandler = =>
      @updateModifiedStatus()

    if typeof @item.onDidChangeModified is 'function'
      onDidChangeModifiedDisposable = @item.onDidChangeModified(modifiedHandler)
      if Disposable.isDisposable(onDidChangeModifiedDisposable)
        @subscriptions.add(onDidChangeModifiedDisposable)
      else
        console.warn "::onDidChangeModified does not return a valid disposable!"
    else if typeof @item.on is 'function'
{'fraction_non_alphanumeric': 0.11616379310344828, 'fraction_numerical': 0.0, 'mean_word_length': 3.664321608040201, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6095038', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1317, 'n_words': 289}