<commit_before>pubsub = require('../utils/pubsub.js')
isFunction = require('../utils/isType.js').Function
plugin = require('./plugin.js')

# Actions module for DOM function binding
#
class Actions

  ACTIVE_ELEMENT: 'data-yaks-action-active'
  TYPE: 'data-yaks-action-type'

  _actions = {}

  # Constructor 
  #
  constructor: () ->
    pubsub.subscribe 'load', @findActions.bind(@)
    pubsub.subscribe 'new_content', @findActions.bind(@)

  # Register Action
  #
  # @param [String] name Action name (or type)
  # @param [Function] action Action function
  #
  registerAction: (name, action) -> 
    _actions[name] = action if isFunction(action)

  # Find action in DOM
  #
  findActions: ->
    @_fireAction(action) for action in document.querySelectorAll("[#{@ACTIVE_ELEMENT}]")

  # Subscribe actions to PubSub
  #
  # @param [Element] el Action element
  #
  _fireAction: (el) ->
    type = el.getAttribute(@TYPE)
    return false unless _actions[type]?
    _actions[type](el)
    el.removeAttribute @ACTIVE_ELEMENT

  # Expose a clone of the actions for testing
  #
  _getActions: ()-> Object.create(_actions)

module.exports = a = new Actions()<commit_msg>Adds functionality for piped action typed<commit_after>pubsub = require('../utils/pubsub.js')
isFunction = require('../utils/isType.js').Function
plugin = require('./plugin.js')

# Actions module for DOM function binding
#
class Actions

  ACTIVE_ELEMENT: 'data-yaks-action-active'
  TYPE: 'data-yaks-action-type'

  _actions = {}

  # Constructor 
  #
  constructor: () ->
    pubsub.subscribe 'load', @findActions.bind(@)
    pubsub.subscribe 'new_content', @findActions.bind(@)

  # Register Action
  #
  # @param [String] name Action name (or type)
  # @param [Function] action Action function
  #
  registerAction: (name, action) -> 
    _actions[name] = action if isFunction(action)

  # Find action in DOM
  #
  findActions: ->
    for actions in document.querySelectorAll("[#{@ACTIVE_ELEMENT}]")
      @_fireAction(action) for action in actions.split('|')

  # Subscribe actions to PubSub
  #
  # @param [Element] el Action element
  #
  _fireAction: (el) ->
    type = el.getAttribute(@TYPE)
    return false unless _actions[type]?
    _actions[type](el)
    el.removeAttribute @ACTIVE_ELEMENT

  # Expose a clone of the actions for testing
  #
  _getActions: ()-> Object.create(_actions)

module.exports = a = new Actions()
{'fraction_non_alphanumeric': 0.13427856547122602, 'fraction_numerical': 0.0, 'mean_word_length': 3.713163064833006, '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': '3485950', 'n_tokens_mistral': 775, 'n_tokens_neox': 762, 'n_words': 192}