Class: Reacto::Operations::Wrap

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

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Wrap

Returns a new instance of Wrap.



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

def initialize(args)
  if args.key?(:value)
    fail ArgumentError, "'value' is not valid key in the wrapping object"
  end

  if args.key?(:error)
    fail ArgumentError, "'error' is not valid key in the wrapping object"
  end

  @args = args
end

Instance Method Details

#call(tracker) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/reacto/operations/wrap.rb', line 20

def call(tracker)
  value = ->(v) do
    data = @args.each_with_object({}) do |(key, val), obj|
      obj[key] = (val.respond_to? :call) ? val.call(v) : val
    end

    tracker.on_value OpenStruct.new({ value: v }.merge(data))
  end

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