Class: Reacto::Operations::Diff
- Inherits:
-
Object
- Object
- Reacto::Operations::Diff
- Defined in:
- lib/reacto/operations/diff.rb
Constant Summary collapse
- DEFAULT_FN =
-> (a, b) { [a, b] }
Instance Method Summary collapse
- #call(tracker) ⇒ Object
-
#initialize(fn = DEFAULT_FN, initial = NO_VALUE) ⇒ Diff
constructor
A new instance of Diff.
Constructor Details
#initialize(fn = DEFAULT_FN, initial = NO_VALUE) ⇒ Diff
Returns a new instance of Diff.
9 10 11 12 |
# File 'lib/reacto/operations/diff.rb', line 9 def initialize(fn = DEFAULT_FN, initial = NO_VALUE) @fn = fn @initial = initial end |
Instance Method Details
#call(tracker) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/reacto/operations/diff.rb', line 14 def call(tracker) prev = @initial value = -> (v) do if prev == NO_VALUE prev = v return end current = @fn.call(prev, v) prev = v tracker.on_value(current) end Subscriptions::OperationSubscription.new(tracker, value: value) end |