Class: Reacto::Operations::EachWithObject

Inherits:
Object
  • Object
show all
Defined in:
lib/reacto/operations/each_with_object.rb

Instance Method Summary collapse

Constructor Details

#initialize(action, obj) ⇒ EachWithObject

Returns a new instance of EachWithObject.



6
7
8
9
# File 'lib/reacto/operations/each_with_object.rb', line 6

def initialize(action, obj)
  @action = action
  @obj = obj
end

Instance Method Details

#call(tracker) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/reacto/operations/each_with_object.rb', line 11

def call(tracker)
  memo = @obj

  close = -> () do
    tracker.on_value(memo)
    tracker.on_close
  end

  error = -> (e) do
    tracker.on_value(memo)
    tracker.on_error(e)
  end

  Subscriptions::OperationSubscription.new(
    tracker,
    value: -> (v) { @action.call(v, memo) }, error: error, close: close
  )
end