<commit_before>class window.TopicView extends Backbone.Marionette.Layout
  template: 'topics/topic'

  regions:
    factList: '.js-region-fact-list'
    subChannelsRegion: '.js-region-sub-channels'
    favouriteTopicRegion: '.js-region-favourite-topic'
    creatorProfileRegion: ".js-region-creator-profile"

  events:
    'change .js-channel-topic-switch': 'showChosenFacts'

  templateHelpers: =>
    has_channel: @channel()

  onRender: ->
    @showChosenFacts()
    @showFavouriteTopicButton()

    if @channel()
      @subChannelsRegion.show new SubchannelsView
        collection: @channel().subchannels()
        model: @channel()

  showChosenFacts: ->
    choice = @$('.js-channel-topic-switch').val()
    if choice == 'channel'
      @showFacts @channelFacts()
      @$('.js-region-sub-channels').show()
      mp_track "Topic: People I follow"
    else
      @showFacts @topicFacts()
      @$('.js-region-sub-channels').hide()
      mp_track "Topic: World view"

  showFacts: (facts) ->
    @factList.show new FactsView collection: facts

  showFavouriteTopicButton: ->
    view = new FavouriteTopicButtonView(topic: @model, mini: true)
    @favouriteTopicRegion.show view

  channel: ->
    return false unless Factlink.Global.can_haz['sees_channels']

    @_channel ?= @model.existingChannelFor(currentUser) || false

  channelFacts: -> new ChannelFacts [], channel: @channel()
  topicFacts: -> @model.facts()<commit_msg>Don't show topic favourite button when not signed in<commit_after>class window.TopicView extends Backbone.Marionette.Layout
  template: 'topics/topic'

  regions:
    factList: '.js-region-fact-list'
    subChannelsRegion: '.js-region-sub-channels'
    favouriteTopicRegion: '.js-region-favourite-topic'
    creatorProfileRegion: ".js-region-creator-profile"

  events:
    'change .js-channel-topic-switch': 'showChosenFacts'

  templateHelpers: =>
    has_channel: @channel()

  onRender: ->
    @showChosenFacts()
    @showFavouriteTopicButton()

    if @channel()
      @subChannelsRegion.show new SubchannelsView
        collection: @channel().subchannels()
        model: @channel()

  showChosenFacts: ->
    choice = @$('.js-channel-topic-switch').val()
    if choice == 'channel'
      @showFacts @channelFacts()
      @$('.js-region-sub-channels').show()
      mp_track "Topic: People I follow"
    else
      @showFacts @topicFacts()
      @$('.js-region-sub-channels').hide()
      mp_track "Topic: World view"

  showFacts: (facts) ->
    @factList.show new FactsView collection: facts

  showFavouriteTopicButton: ->
    return unless Factlink.Global.signed_in

    view = new FavouriteTopicButtonView(topic: @model, mini: true)
    @favouriteTopicRegion.show view

  channel: ->
    return false unless Factlink.Global.can_haz['sees_channels']

    @_channel ?= @model.existingChannelFor(currentUser) || false

  channelFacts: -> new ChannelFacts [], channel: @channel()
  topicFacts: -> @model.facts()
{'fraction_non_alphanumeric': 0.13457627118644067, 'fraction_numerical': 0.0, 'mean_word_length': 3.5751937984496123, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '7652419', 'n_tokens_mistral': 963, 'n_tokens_neox': 927, 'n_words': 184}