lib/fusuma/plugin/buffers/gesture_buffer.rb in fusuma-1.5.0 vs lib/fusuma/plugin/buffers/gesture_buffer.rb in fusuma-1.6.0

- old
+ new

@@ -16,19 +16,25 @@ 'seconds_to_keep': [Float, Integer] } end # @param event [Event] + # @return [Buffer, false] def buffer(event) # TODO: buffering events into buffer plugins # - gesture event buffer # - window event buffer # - other event buffer return if event&.tag != source - @events.push(event) - clear unless updating? + if bufferable?(event) + @events.push(event) + self + else + clear + false + end end def clear_expired(current_time: Time.now) @seconds_to_keep ||= (config_params(:seconds_to_keep) || DEFAULT_SECONDS_TO_KEEP) @events.each do |e| @@ -75,13 +81,16 @@ events = @events.select { |event| yield event } self.class.new events end - private - - def updating? - return true unless @events.last.record.status =~ /begin|end/ + def bufferable?(event) + case event.record.status + when 'begin', 'end' + false + else + true + end end end end end end