Class: Reacto::Operations::Flatten

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

Instance Method Summary collapse

Instance Method Details

#call(tracker) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/reacto/operations/flatten.rb', line 6

def call(tracker)
  behaviour = -> (value) do
    if value.kind_of?(Array)
      value.flatten.each do |sub_value|
        tracker.on_value(sub_value)
      end
    else
      tracker.on_value(value)
    end
  end

  Subscriptions::OperationSubscription.new(tracker, value: behaviour)
end