lib/stimulus_reflex/callbacks.rb in stimulus_reflex-3.5.0.pre9 vs lib/stimulus_reflex/callbacks.rb in stimulus_reflex-3.5.0.pre10

- old
+ new

@@ -1,13 +1,29 @@ +# frozen_string_literal: true + require "active_support/concern" module StimulusReflex module Callbacks extend ActiveSupport::Concern included do include ActiveSupport::Callbacks - define_callbacks :process, skip_after_callbacks_if_terminated: true + define_callbacks :process, skip_after_callbacks_if_terminated: true, terminator: ->(target, result_lambda) do + halted = true + forbidden = true + catch(:abort) do + catch(:forbidden) do + result_lambda.call + forbidden = false + end + halted = false + end + forbidden = false if halted == true + target.instance_variable_set(:@halted, halted) + target.instance_variable_set(:@forbidden, forbidden) + halted || forbidden + end end class_methods do def before_reflex(*args, &block) add_callback(:before, *args, &block)