<commit_before>require 'opal-jquery'

module Clearwater
  class Event
    attr_reader :view_selector, :event_type, :target_selector

    def initialize view_selector, event_type, target_selector=nil, &block
      @view_selector = view_selector
      @event_type = event_type
      @target_selector = target_selector
      @block = block
    end

    def call event
      @block.call event
    end

    def set_browser_event
      selector = "#{view_selector} #{target_selector}"
      Element[selector].on event_type, &@block
    end

    def reset_binding? bindings
      selector = "#{view_selector} #{target_selector}"
      element = Element[selector]
      bindings.any? { |binding|
        element.closest(binding.selector).any?
      }
    end
  end
end<commit_msg>Extract event selector to method<commit_after>require 'opal-jquery'

module Clearwater
  class Event
    attr_reader :view_selector, :event_type, :target_selector

    def initialize view_selector, event_type, target_selector=nil, &block
      @view_selector = view_selector
      @event_type = event_type
      @target_selector = target_selector
      @block = block
    end

    def call event
      @block.call event
    end

    def set_browser_event
      Element[selector].on event_type, &@block
    end

    def reset_binding? bindings
      element = Element[selector]
      bindings.any? { |binding|
        element.closest(binding.selector).any?
      }
    end

    def selector
      @selector ||= "#{view_selector} #{target_selector}"
    end
  end
end
{'fraction_non_alphanumeric': 0.08197787898503578, 'fraction_numerical': 0.0, 'mean_word_length': 3.0156657963446474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '628679', 'n_tokens_mistral': 456, 'n_tokens_neox': 443, 'n_words': 111}