<commit_before>{EventEmitter} = require 'events'
AppDispatcher = require '../../../AppDispatcher'

module.exports = class Store extends EventEmitter

    # this variable will be shared with all subclasses so we store the items by subclass
    _handlers = {}
    _addHandlers = (type, callback) ->
        storeName = @constructor.name
        _handlers[storeName] = {} unless _handlers[storeName]?
        _handlers[storeName][type] = callback

    # Registers the store's callbacks to the dispatcher
    _processBinding = ->
        storeName = @constructor.name
        @dispatchToken = AppDispatcher.register (payload) =>
            {type, value} = payload.action
            if (callback = _handlers[storeName][type])? then callback.call @, value

        console.log "#{storeName} -- #{@dispatchToken}"


    constructor: ->
        super()
        @__bindHandlers _addHandlers.bind @
        _processBinding.call @

    # Must be overriden by each store
    __bindHandlers: (handle) -> throw new Error "The store #{@constructor.name} must define a `__bindHandlers` method"
<commit_msg>Fixed: stores couldn't work when mangled<commit_after>{EventEmitter} = require 'events'
AppDispatcher = require '../../../AppDispatcher'


module.exports = class Store extends EventEmitter

    uniqID: null

    # this variable will be shared with all subclasses so we store the items by subclass
    # we don't use `@constructor.name` because it breaks when mangled
    _nextUniqID = 0
    _handlers = {}
    _addHandlers = (type, callback) ->

        _handlers[@uniqID] = {} unless _handlers[@uniqID]?
        _handlers[@uniqID][type] = callback

    # Registers the store's callbacks to the dispatcher
    _processBinding = ->
        @dispatchToken = AppDispatcher.register (payload) =>
            {type, value} = payload.action
            if (callback = _handlers[@uniqID][type])? then callback.call @, value


    constructor: ->
        super()
        # set a uniq ID
        @uniqID = _nextUniqID++
        @__bindHandlers _addHandlers.bind @
        _processBinding.call @

    # Must be overriden by each store
    __bindHandlers: (handle) ->
        if __DEV__
            throw new Error "The store #{@constructor.name} must define a `__bindHandlers` method"

{'fraction_non_alphanumeric': 0.1027790030877812, 'fraction_numerical': 0.0004411116012351125, 'mean_word_length': 2.8505942275042444, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '7543674', 'n_tokens_mistral': 648, 'n_tokens_neox': 626, 'n_words': 191}