Class: Reacto::Operations::Map

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

Instance Method Summary collapse

Constructor Details

#initialize(mapping, error: nil, close: nil) ⇒ Map

Returns a new instance of Map.



7
8
9
10
11
# File 'lib/reacto/operations/map.rb', line 7

def initialize(mapping, error: nil, close: nil)
  @mapping = mapping
  @error = error
  @close = close
end

Instance Method Details

#call(tracker) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/reacto/operations/map.rb', line 13

def call(tracker)
  error =
    if @error
      -> (e) { tracker.on_error(@error.call(e)) }
    else
      tracker.method(:on_error)
    end

  close =
    if @close
      -> () do
        tracker.on_value(@close.call)
        tracker.on_close
      end
    else
      tracker.method(:on_close)
    end

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