Class: Reacto::Operations::Include

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

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Include

Returns a new instance of Include.



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

def initialize(value)
  @value = value
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
29
30
31
32
33
34
35
36
# File 'lib/reacto/operations/include.rb', line 11

def call(tracker)
  includes = false

  behaviour = -> (val) do
    if @value == val
      includes = true

      tracker.on_value(includes)
      tracker.on_close
    end
  end

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

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

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