<commit_before>_ = require 'underscore-plus'
{Subscriber, Emitter} = require 'emissary'

idCounter = 0
nextId = -> idCounter++

module.exports =
class Decoration
  Emitter.includeInto(this)

  @isType: (decorationParams, type) ->
    if _.isArray(decorationParams.type)
      type in decorationParams.type
    else
      type is decorationParams.type

  constructor: (@marker, @displayBuffer, @params) ->
    @id = nextId()
    @params.id = @id
    @flashQueue = null

  destroy: ->
    @displayBuffer.removeDecoration(this)
    @emit 'destoryed'

  update: (newParams) ->
    oldParams = @params
    @params = newParams
    @params.id = @id
    @displayBuffer.decorationUpdated(this)
    @emit 'updated', {oldParams, newParams}

  getParams: ->
    @params

  isType: (type) ->
    Decoration.isType(@params, type)

  matchesPattern: (decorationPattern) ->
    return false unless decorationPattern?
    for key, value of decorationPattern
      return false if @params[key] != value
    true

  flash: (klass, duration=500) ->
    flashObject = {class: klass, duration}
    @flashQueue ?= []
    @flashQueue.push(flashObject)
    @emit 'flash'

  consumeNextFlash: ->
    return @flashQueue.shift() if @flashQueue?.length > 0
    null<commit_msg>Add is destroyed flag to decoration<commit_after>_ = require 'underscore-plus'
{Subscriber, Emitter} = require 'emissary'

idCounter = 0
nextId = -> idCounter++

module.exports =
class Decoration
  Emitter.includeInto(this)

  @isType: (decorationParams, type) ->
    if _.isArray(decorationParams.type)
      type in decorationParams.type
    else
      type is decorationParams.type

  constructor: (@marker, @displayBuffer, @params) ->
    @id = nextId()
    @params.id = @id
    @flashQueue = null
    @isDestroyed = false

  destroy: ->
    return if @isDestroyed
    @isDestroyed = true
    @displayBuffer.removeDecoration(this)
    @emit 'destoryed'

  update: (newParams) ->
    return if @isDestroyed
    oldParams = @params
    @params = newParams
    @params.id = @id
    @displayBuffer.decorationUpdated(this)
    @emit 'updated', {oldParams, newParams}

  getParams: ->
    @params

  isType: (type) ->
    Decoration.isType(@params, type)

  matchesPattern: (decorationPattern) ->
    return false unless decorationPattern?
    for key, value of decorationPattern
      return false if @params[key] != value
    true

  flash: (klass, duration=500) ->
    flashObject = {class: klass, duration}
    @flashQueue ?= []
    @flashQueue.push(flashObject)
    @emit 'flash'

  consumeNextFlash: ->
    return @flashQueue.shift() if @flashQueue?.length > 0
    null
{'fraction_non_alphanumeric': 0.11827546737886303, 'fraction_numerical': 0.0038153376573826785, 'mean_word_length': 3.3267326732673266, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '474476', 'n_tokens_mistral': 851, 'n_tokens_neox': 807, 'n_words': 204}