 
 window.GitLab ?= {}
 GitLab.GfmAutoComplete =
+  dataLoading: false
+
   dataSource: ''
 
   # Emoji

            title:  sanitize(i.title)
            search: "#{i.iid} #{i.title}"

    input.atwho
      at: '!'
      alias: 'mergerequests'
      searchKey: 'search'

    template: '<li><small>${id}</small> ${title}</li>'

  # Add GFM auto-completion to all input fields, that accept GFM input.
  setup: (wrap) ->
    @input = $('.js-gfm-input')

    # destroy previous instances
    @destroyAtWho()

    # set up instances
    @setupAtWho()

    if @dataSource
      if !@dataLoading
        @dataLoading = true

        # We should wait until initializations are done
        # and only trigger the last .setup since
        # The previous .dataSource belongs to the previous issuable
        # and the last one will have the **proper** .dataSource property
        # TODO: Make this a singleton and turn off events when moving to another page
        setTimeout( =>
          fetch = @fetchData(@dataSource)
          fetch.done (data) =>
            @dataLoading = false
            @loadData(data)
        , 1000)


  setupAtWho: ->
    # Emoji
    @input.atwho
      at: ':'
      displayTpl: @Emoji.template
      insertTpl: ':${name}:'

    # Team Members
    @input.atwho
      at: '@'
      displayTpl: @Members.template
      insertTpl: '${atwho-at}${username}'
