Class: Reacto::Operations::SplitLabeled

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

Instance Method Summary collapse

Constructor Details

#initialize(label, chose_label, executor = nil) ⇒ SplitLabeled

Returns a new instance of SplitLabeled.



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

def initialize(label, chose_label, executor = nil)
  @label = label
  @chose_label = chose_label
  @executor = executor
end

Instance Method Details

#call(tracker) ⇒ Object



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

def call(tracker)
  value = -> (v) do
    if v.is_a?(LabeledTrackable) && v.label == @label
      action = -> (labeled_trackable) do
        tracker.on_value(labeled_trackable)
      end

      v.group_by_label(executor: @executor, &@chose_label)
        .on(value: action)
    else
      tracker.on_value(v)
    end
  end

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