Class: Reacto::Operations::Act
- Inherits:
-
Object
- Object
- Reacto::Operations::Act
- Defined in:
- lib/reacto/operations/act.rb
Constant Summary collapse
- ALL =
%i(value error close)
Instance Method Summary collapse
- #call(tracker) ⇒ Object
- #close_action(tracker) ⇒ Object
- #error_action(tracker) ⇒ Object
-
#initialize(action = NO_ACTION, on = ALL) ⇒ Act
constructor
A new instance of Act.
- #value_action(tracker) ⇒ Object
Constructor Details
Instance Method Details
#call(tracker) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/reacto/operations/act.rb', line 19 def call(tracker) value = if @on.include?(:value) value_action(tracker) else tracker.method(:on_value) end error = if @on.include?(:error) error_action(tracker) else tracker.method(:on_error) end close = if @on.include?(:close) close_action(tracker) else tracker.method(:on_close) end Subscriptions::OperationSubscription.new( tracker, value: value, error: error, close: close ) end |
#close_action(tracker) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/reacto/operations/act.rb', line 60 def close_action(tracker) lambda do @action.call(OpenStruct.new(type: :close)) tracker.on_close end end |
#error_action(tracker) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/reacto/operations/act.rb', line 53 def error_action(tracker) lambda do |error| @action.call(OpenStruct.new(error: error, type: :error)) tracker.on_error(error) end end |
#value_action(tracker) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/reacto/operations/act.rb', line 46 def value_action(tracker) lambda do |value| @action.call(OpenStruct.new(value: value, type: :value)) tracker.on_value(value) end end |