reacto 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +932 -11
- data/doc/reactive_programming_with_reacto.md +238 -0
- data/lib/reacto.rb +70 -0
- data/lib/reacto/behaviours.rb +24 -1
- data/lib/reacto/constants.rb +4 -1
- data/lib/reacto/executors.rb +8 -10
- data/lib/reacto/labeled_trackable.rb +14 -2
- data/lib/reacto/operations.rb +23 -2
- data/lib/reacto/operations/act.rb +69 -0
- data/lib/reacto/operations/append.rb +45 -0
- data/lib/reacto/operations/blocking_enumerable.rb +40 -0
- data/lib/reacto/operations/buffer.rb +1 -4
- data/lib/reacto/operations/chunk.rb +81 -0
- data/lib/reacto/operations/chunk_while.rb +56 -0
- data/lib/reacto/operations/cycle.rb +27 -0
- data/lib/reacto/operations/delay_each.rb +75 -0
- data/lib/reacto/operations/depend_on.rb +4 -5
- data/lib/reacto/operations/diff.rb +8 -10
- data/lib/reacto/operations/drop.rb +6 -8
- data/lib/reacto/operations/drop_while.rb +23 -0
- data/lib/reacto/operations/each_collect.rb +57 -0
- data/lib/reacto/operations/each_with_object.rb +31 -0
- data/lib/reacto/operations/extremums.rb +54 -0
- data/lib/reacto/operations/find_index.rb +28 -0
- data/lib/reacto/operations/flat_map.rb +2 -2
- data/lib/reacto/operations/flatten.rb +2 -7
- data/lib/reacto/operations/flatten_labeled.rb +44 -0
- data/lib/reacto/operations/{label.rb → group_by_label.rb} +1 -1
- data/lib/reacto/operations/include.rb +40 -0
- data/lib/reacto/operations/inject.rb +15 -9
- data/lib/reacto/operations/map.rb +15 -13
- data/lib/reacto/operations/merge.rb +17 -16
- data/lib/reacto/operations/operation_on_labeled.rb +29 -0
- data/lib/reacto/operations/partition.rb +52 -0
- data/lib/reacto/operations/prepend.rb +0 -3
- data/lib/reacto/operations/rescue_and_replace_error.rb +21 -0
- data/lib/reacto/operations/retry.rb +26 -0
- data/lib/reacto/operations/retry_when.rb +30 -0
- data/lib/reacto/operations/select.rb +2 -6
- data/lib/reacto/operations/slice.rb +50 -0
- data/lib/reacto/operations/slice_when.rb +41 -0
- data/lib/reacto/operations/split_labeled.rb +32 -0
- data/lib/reacto/operations/take.rb +9 -14
- data/lib/reacto/operations/take_while.rb +28 -0
- data/lib/reacto/operations/throttle.rb +2 -3
- data/lib/reacto/operations/track_on.rb +1 -3
- data/lib/reacto/shared_trackable.rb +2 -5
- data/lib/reacto/subscriptions/buffered_subscription.rb +10 -9
- data/lib/reacto/subscriptions/executor_subscription.rb +12 -4
- data/lib/reacto/subscriptions/tracker_subscription.rb +0 -4
- data/lib/reacto/subscriptions/zipping_subscription.rb +0 -1
- data/lib/reacto/trackable.rb +429 -64
- data/lib/reacto/version.rb +1 -1
- data/reacto.gemspec +2 -3
- data/spec/reacto/labeled_trackable_spec.rb +17 -0
- data/spec/reacto/trackable/act_spec.rb +15 -0
- data/spec/reacto/trackable/all_spec.rb +38 -0
- data/spec/reacto/trackable/any_spec.rb +39 -0
- data/spec/reacto/trackable/append_spec.rb +38 -0
- data/spec/reacto/trackable/buffer_spec.rb +11 -15
- data/spec/reacto/trackable/chunk_spec.rb +86 -0
- data/spec/reacto/trackable/chunk_while_spec.rb +22 -0
- data/spec/reacto/trackable/class_level/combine_last_spec.rb +1 -3
- data/spec/reacto/trackable/class_level/interval_spec.rb +4 -6
- data/spec/reacto/trackable/class_level/make_spec.rb +0 -15
- data/spec/reacto/trackable/{zip_spec.rb → class_level/zip_spec.rb} +0 -2
- data/spec/reacto/trackable/concat_spec.rb +12 -12
- data/spec/reacto/trackable/count_spec.rb +38 -0
- data/spec/reacto/trackable/cycle_spec.rb +14 -0
- data/spec/reacto/trackable/delay_each_spec.rb +18 -0
- data/spec/reacto/trackable/depend_on_spec.rb +6 -9
- data/spec/reacto/trackable/diff_spec.rb +3 -5
- data/spec/reacto/trackable/drop_errors_spec.rb +1 -3
- data/spec/reacto/trackable/drop_while_spec.rb +15 -0
- data/spec/reacto/trackable/each_cons_spec.rb +53 -0
- data/spec/reacto/trackable/each_slice_spec.rb +37 -0
- data/spec/reacto/trackable/each_with_index_spec.rb +33 -0
- data/spec/reacto/trackable/each_with_object_spec.rb +26 -0
- data/spec/reacto/trackable/entries_spec.rb +25 -0
- data/spec/reacto/trackable/execute_on_spec.rb +33 -0
- data/spec/reacto/trackable/find_index_spec.rb +31 -0
- data/spec/reacto/trackable/find_spec.rb +34 -0
- data/spec/reacto/trackable/first_spec.rb +36 -0
- data/spec/reacto/trackable/flat_map_latest_spec.rb +5 -5
- data/spec/reacto/trackable/flat_map_spec.rb +25 -0
- data/spec/reacto/trackable/flatten_labeled_spec.rb +48 -0
- data/spec/reacto/trackable/grep_spec.rb +29 -0
- data/spec/reacto/trackable/grep_v_spec.rb +23 -0
- data/spec/reacto/trackable/{label_spec.rb → group_by_label_spec.rb} +4 -11
- data/spec/reacto/trackable/include_spec.rb +23 -0
- data/spec/reacto/trackable/inject_spec.rb +30 -4
- data/spec/reacto/trackable/lift_spec.rb +1 -3
- data/spec/reacto/trackable/map_spec.rb +17 -3
- data/spec/reacto/trackable/max_by_spec.rb +12 -0
- data/spec/reacto/trackable/max_spec.rb +19 -0
- data/spec/reacto/trackable/merge_spec.rb +6 -7
- data/spec/reacto/trackable/min_by_spec.rb +12 -0
- data/spec/reacto/trackable/min_spec.rb +19 -0
- data/spec/reacto/trackable/minmax_by_spec.rb +12 -0
- data/spec/reacto/trackable/minmax_spec.rb +19 -0
- data/spec/reacto/trackable/none_spec.rb +38 -0
- data/spec/reacto/trackable/on_spec.rb +11 -4
- data/spec/reacto/trackable/one_spec.rb +38 -0
- data/spec/reacto/trackable/partition_spec.rb +23 -0
- data/spec/reacto/trackable/prepend_spec.rb +1 -3
- data/spec/reacto/trackable/reject_spec.rb +21 -0
- data/spec/reacto/trackable/rescue_and_replace_error_spec.rb +48 -0
- data/spec/reacto/trackable/rescue_and_replace_error_with_spec.rb +26 -0
- data/spec/reacto/trackable/retry_spec.rb +50 -0
- data/spec/reacto/trackable/retry_when_spec.rb +33 -0
- data/spec/reacto/trackable/select_spec.rb +18 -7
- data/spec/reacto/trackable/slice_after_spec.rb +38 -0
- data/spec/reacto/trackable/slice_before_spec.rb +38 -0
- data/spec/reacto/trackable/slice_when_spec.rb +26 -0
- data/spec/reacto/trackable/sort_by_spec.rb +16 -0
- data/spec/reacto/trackable/sort_spec.rb +23 -0
- data/spec/reacto/trackable/split_labeled_spec.rb +37 -0
- data/spec/reacto/trackable/take_while_spec.rb +16 -0
- data/spec/reacto/trackable/throttle_spec.rb +2 -3
- data/spec/reacto/trackable/track_on_spec.rb +2 -3
- data/spec/reacto/trackable/uniq_spec.rb +2 -4
- data/spec/support/helpers.rb +9 -1
- metadata +135 -25
- data/Gemfile.lock +0 -32
- data/lib/reacto/operations/cache.rb +0 -53
- data/spec/reacto/trackable/cache_spec.rb +0 -64
@@ -0,0 +1,19 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
subject(:source) { described_class.enumerable(%w(albatross dog horse snake)) }
|
3
|
+
|
4
|
+
context '#min' do
|
5
|
+
it 'emits the minimum value emitted by source assuming that all the ' \
|
6
|
+
'values implement Comparable' do
|
7
|
+
attach_test_trackers(source.min)
|
8
|
+
|
9
|
+
expect(test_data).to eq(%w(albatross |))
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'emits the minimum value emitted by source using the block given to ' \
|
13
|
+
'compare the values ' do
|
14
|
+
attach_test_trackers(source.min { |val1, val2| val1.size <=> val2.size })
|
15
|
+
|
16
|
+
expect(test_data).to eq(%w(dog |))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
subject(:source) { described_class.enumerable(%w(albatross dog horse snake)) }
|
3
|
+
|
4
|
+
context '#minmax_by' do
|
5
|
+
it 'emits the values emitted by source that give the minimum value and ' \
|
6
|
+
'the maximum value from the given block. ' do
|
7
|
+
attach_test_trackers(source.minmax_by { |val| val.size })
|
8
|
+
|
9
|
+
expect(test_data).to eq(%w(dog albatross |))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
subject(:source) { described_class.enumerable(%w(albatross dog horse snake)) }
|
3
|
+
|
4
|
+
context '#minmax' do
|
5
|
+
it 'emits the minimum and then the maximum values emitted by source ' \
|
6
|
+
'assuming that all the values implement Comparable' do
|
7
|
+
attach_test_trackers(source.minmax)
|
8
|
+
|
9
|
+
expect(test_data).to eq(%w(albatross snake |))
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'emits the maximum and then the maximum values emitted by source ' \
|
13
|
+
'using the block given to compare the values ' do
|
14
|
+
attach_test_trackers(source.minmax { |v1, v2| v1.size <=> v2.size })
|
15
|
+
|
16
|
+
expect(test_data).to eq(%w(dog albatross |))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
context '#none?' do
|
3
|
+
it 'passes each incoming value to the given block. The resulting ' \
|
4
|
+
'Reacto::Trackable emits only one value - `true` if the block never ' \
|
5
|
+
'returns `true`. Test true.' do
|
6
|
+
trackable = described_class.enumerable((5..10)).none? do |value|
|
7
|
+
value < 5
|
8
|
+
end
|
9
|
+
|
10
|
+
trackable.on(value: test_on_value)
|
11
|
+
|
12
|
+
expect(test_data.size).to be(1)
|
13
|
+
expect(test_data.first).to be(true)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'passes each incoming value to the given block. The resulting ' \
|
17
|
+
'Reacto::Trackable emits only one value - `true` if the block never ' \
|
18
|
+
'returns `true`. Test false.' do
|
19
|
+
trackable = described_class.enumerable((6..10)).none? do |value|
|
20
|
+
value < 7
|
21
|
+
end
|
22
|
+
|
23
|
+
trackable.on(value: test_on_value)
|
24
|
+
|
25
|
+
expect(test_data.size).to be(1)
|
26
|
+
expect(test_data.first).to be(false)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'if the block is not given, adds an implicit block of { |obj| obj }' do
|
30
|
+
trackable = described_class.enumerable([nil, nil]).none?
|
31
|
+
|
32
|
+
trackable.on(value: test_on_value)
|
33
|
+
|
34
|
+
expect(test_data.size).to be(1)
|
35
|
+
expect(test_data.first).to be(true)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,9 +1,7 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
context Reacto::Trackable do
|
4
2
|
context '#on' do
|
5
3
|
it 'returns a Reacto::Subscription' do
|
6
|
-
actual = described_class.new
|
4
|
+
actual = described_class.new.on
|
7
5
|
|
8
6
|
expect(actual).to_not be(nil)
|
9
7
|
expect(actual).to be_kind_of(Reacto::Subscriptions::Subscription)
|
@@ -12,7 +10,16 @@ context Reacto::Trackable do
|
|
12
10
|
context('value') do
|
13
11
|
it 'the trackable behavior uses a subscription which `on_value` ' \
|
14
12
|
'is the passed value action' do
|
15
|
-
described_class.new(test_behaviour).on(value: test_on_value)
|
13
|
+
described_class.new(&test_behaviour).on(value: test_on_value)
|
14
|
+
|
15
|
+
expect(test_data.size).to be(1)
|
16
|
+
expect(test_data[0]).to be(5)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with block' do
|
21
|
+
it 'behaves as #on value: <lambda>' do
|
22
|
+
described_class.new(&test_behaviour).on(&test_on_value)
|
16
23
|
|
17
24
|
expect(test_data.size).to be(1)
|
18
25
|
expect(test_data[0]).to be(5)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
context '#one?' do
|
3
|
+
it 'passes each incoming value to the given block. The resulting ' \
|
4
|
+
'Reacto::Trackable emits only one value - `true` if the block returns ' \
|
5
|
+
'`true` exactly once. Test true.' do
|
6
|
+
trackable = described_class.enumerable((5..10)).one? do |value|
|
7
|
+
value < 6
|
8
|
+
end
|
9
|
+
|
10
|
+
trackable.on(value: test_on_value)
|
11
|
+
|
12
|
+
expect(test_data.size).to be(1)
|
13
|
+
expect(test_data.first).to be(true)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'passes each incoming value to the given block. The resulting ' \
|
17
|
+
'Reacto::Trackable emits only one value - `true` if the block returns ' \
|
18
|
+
'`true` exactly once. Test false.' do
|
19
|
+
trackable = described_class.enumerable((4..10)).one? do |value|
|
20
|
+
value < 6
|
21
|
+
end
|
22
|
+
|
23
|
+
trackable.on(value: test_on_value)
|
24
|
+
|
25
|
+
expect(test_data.size).to be(1)
|
26
|
+
expect(test_data.first).to be(false)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'if the block is not given, adds an implicit block of { |obj| obj }' do
|
30
|
+
trackable = described_class.enumerable([0, nil, 1]).one?
|
31
|
+
|
32
|
+
trackable.on(value: test_on_value)
|
33
|
+
|
34
|
+
expect(test_data.size).to be(1)
|
35
|
+
expect(test_data.first).to be(false)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
context '#partition' do
|
3
|
+
def expect_values(trackable, label, expected)
|
4
|
+
expect_trackable_values(trackable, expected, label: label)
|
5
|
+
end
|
6
|
+
|
7
|
+
let(:data) { [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5] }
|
8
|
+
subject(:test_source) { described_class.enumerable(data) }
|
9
|
+
|
10
|
+
it 'creates a Reacto::Trackable which emits two LabeledTrackable ' \
|
11
|
+
'instances, the first with label `true`, emitting values for which' \
|
12
|
+
'the given block evaluates to true, the second emitting the rest' do
|
13
|
+
trackable = test_source.partition { |v| v.even? }
|
14
|
+
|
15
|
+
attach_test_trackers(trackable)
|
16
|
+
|
17
|
+
expect(test_data.length).to be(3)
|
18
|
+
expect_values(test_data.first, true, [4, 2, 6])
|
19
|
+
expect_values(test_data[1], false, [3, 1, 1, 5, 9, 5, 3, 5])
|
20
|
+
expect(test_data.last).to eq('|')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
context Reacto::Trackable do
|
4
2
|
context '#prepend' do
|
5
|
-
it 'emits the passed enumerable before the values,
|
3
|
+
it 'emits the passed enumerable before the values, emitted by the caller' do
|
6
4
|
source = described_class.enumerable((1..5))
|
7
5
|
trackable = source.prepend((-5..0))
|
8
6
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
context '#reject' do
|
3
|
+
it 'notifies with values not passing the filter block' do
|
4
|
+
trackable = source.reject { |v| v % 2 == 0 }
|
5
|
+
trackable.on(value: test_on_value)
|
6
|
+
|
7
|
+
expect(test_data.size).to be(1)
|
8
|
+
expect(test_data.first).to be(5)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'does not notify with values passing the filter block' do
|
12
|
+
trackable = source.reject do |v|
|
13
|
+
v % 2 == 1
|
14
|
+
end
|
15
|
+
|
16
|
+
trackable.on(value: test_on_value)
|
17
|
+
|
18
|
+
expect(test_data.size).to be(0)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
context '#rescue_and_replace_error' do
|
3
|
+
let(:test_error) { StandardError.new('Bang!') }
|
4
|
+
|
5
|
+
subject(:test_source) do
|
6
|
+
described_class.make do |tracker|
|
7
|
+
tracker.on_value('Hi!')
|
8
|
+
|
9
|
+
tracker.on_error(test_error)
|
10
|
+
|
11
|
+
tracker.on_value('Bye.')
|
12
|
+
tracker.on_close
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'replaces the emitted error with the a new sequence emitted by the ' \
|
17
|
+
'Reacto::Trackable instance, returned by the passed block' do
|
18
|
+
|
19
|
+
trackable = test_source.rescue_and_replace_error do |error|
|
20
|
+
if error.message == 'Bang!'
|
21
|
+
Reacto::Trackable.enumerable(%w(so that's a goodbye then))
|
22
|
+
else
|
23
|
+
Reacto::Trackable.error(error)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
attach_test_trackers(trackable)
|
28
|
+
|
29
|
+
expect(test_data).to eq(%w(Hi! so that's a goodbye then |))
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'replaces the emitted error with the a new sequence emitted by the ' \
|
33
|
+
'Reacto::Trackable instance, returned by the passed block. Error case' do
|
34
|
+
|
35
|
+
trackable = test_source.rescue_and_replace_error do |error|
|
36
|
+
if error.message == 'Gang!'
|
37
|
+
Reacto::Trackable.enumerable(%w(so that's a goodbye then))
|
38
|
+
else
|
39
|
+
Reacto::Trackable.error(error)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
attach_test_trackers(trackable)
|
44
|
+
|
45
|
+
expect(test_data).to eq(['Hi!', test_error])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
context '#rescue_and_replace_error_with' do
|
3
|
+
let(:test_error) { StandardError.new('Bang!') }
|
4
|
+
|
5
|
+
subject(:test_source) do
|
6
|
+
described_class.make do |tracker|
|
7
|
+
tracker.on_value('Hi!')
|
8
|
+
|
9
|
+
tracker.on_error(test_error)
|
10
|
+
|
11
|
+
tracker.on_value('Bye.')
|
12
|
+
tracker.on_close
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'replaces the emitted error with the a new sequence emitted by the ' \
|
17
|
+
'given Reacto::Trackable instance' do
|
18
|
+
trackable = test_source.rescue_and_replace_error_with(
|
19
|
+
Reacto::Trackable.enumerable(%w(so that's a goodbye then))
|
20
|
+
)
|
21
|
+
attach_test_trackers(trackable)
|
22
|
+
|
23
|
+
expect(test_data).to eq(%w(Hi! so that's a goodbye then |))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
context '#retry' do
|
3
|
+
let(:error_checker) do
|
4
|
+
array = []
|
5
|
+
->() do
|
6
|
+
array << 1
|
7
|
+
|
8
|
+
array.length % 2 == 1
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it 're-runs the whole behaviour of the source trackable if there is ' \
|
13
|
+
'an error' do
|
14
|
+
trackable = Reacto::Trackable.make do |tracker|
|
15
|
+
tracker.on_value('Hi!')
|
16
|
+
|
17
|
+
tracker.on_error(StandardError.new('Bang!')) if error_checker.call
|
18
|
+
|
19
|
+
tracker.on_value('Bye.')
|
20
|
+
tracker.on_close
|
21
|
+
end.retry
|
22
|
+
|
23
|
+
trackable.on(
|
24
|
+
value: test_on_value, error: test_on_error, close: test_on_close
|
25
|
+
)
|
26
|
+
|
27
|
+
expect(test_data).to eq(['Hi!', 'Hi!', 'Bye.', '|'])
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'emits the error if it persists the retry count times' do
|
31
|
+
power_error = StandardError.new('Bang! Bang!')
|
32
|
+
|
33
|
+
trackable = Reacto::Trackable.make do |tracker|
|
34
|
+
tracker.on_value('Hi!')
|
35
|
+
|
36
|
+
tracker.on_error(StandardError.new('Bang!')) if error_checker.call
|
37
|
+
tracker.on_error(power_error) if error_checker.call
|
38
|
+
|
39
|
+
tracker.on_value('Bye.')
|
40
|
+
tracker.on_close
|
41
|
+
end.retry(3)
|
42
|
+
|
43
|
+
trackable.on(
|
44
|
+
value: test_on_value, error: test_on_error, close: test_on_close
|
45
|
+
)
|
46
|
+
|
47
|
+
expect(test_data).to eq(['Hi!', 'Hi!', 'Hi!', 'Hi!', power_error])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
context '#retry_when' do
|
3
|
+
let(:error_checker) do
|
4
|
+
array = []
|
5
|
+
->() do
|
6
|
+
array << 1
|
7
|
+
|
8
|
+
array.length % 2 == 1
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it 're-runs the whole behaviour of the source trackable if there is ' \
|
13
|
+
'an error and the block passed evaluates to `true`' do
|
14
|
+
power_error = ArgumentError.new('Bang! Bang!')
|
15
|
+
|
16
|
+
trackable = Reacto::Trackable.make do |tracker|
|
17
|
+
tracker.on_value('Hi!')
|
18
|
+
|
19
|
+
tracker.on_error(StandardError.new('Bang!')) if error_checker.call
|
20
|
+
tracker.on_error(power_error) if error_checker.call
|
21
|
+
|
22
|
+
tracker.on_value('Bye.')
|
23
|
+
tracker.on_close
|
24
|
+
end.retry_when { |_error, retries| retries < 4 }
|
25
|
+
|
26
|
+
trackable.on(
|
27
|
+
value: test_on_value, error: test_on_error, close: test_on_close
|
28
|
+
)
|
29
|
+
|
30
|
+
expect(test_data).to eq(['Hi!', 'Hi!', 'Hi!', 'Hi!', 'Hi!', power_error])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,12 +1,7 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
context Reacto::Trackable do
|
4
2
|
context '#select' do
|
5
3
|
it 'doesn\'t notify with values not passing the filter block' do
|
6
|
-
trackable = source.select
|
7
|
-
v % 2 == 0
|
8
|
-
end
|
9
|
-
|
4
|
+
trackable = source.select { |v| v % 2 == 0 }
|
10
5
|
trackable.on(value: test_on_value)
|
11
6
|
|
12
7
|
expect(test_data.size).to be(0)
|
@@ -20,7 +15,23 @@ context Reacto::Trackable do
|
|
20
15
|
trackable.on(value: test_on_value)
|
21
16
|
|
22
17
|
expect(test_data.size).to be(1)
|
23
|
-
expect(test_data
|
18
|
+
expect(test_data.first).to be(5)
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with label' do
|
22
|
+
it 'applies the filtering passed only to the emitted values of type ' \
|
23
|
+
'LabeledTrackable with the matching label' do
|
24
|
+
source = described_class.enumerable((1..10)).group_by_label do |value|
|
25
|
+
[(value % 3), value]
|
26
|
+
end
|
27
|
+
|
28
|
+
trackable = source.select(label: 1) { |value| value < 5 }
|
29
|
+
trackable.on(value: test_on_value)
|
30
|
+
|
31
|
+
expect_trackable_values(test_data.first, [1, 4], label: 1)
|
32
|
+
expect_trackable_values(test_data[1], [2, 5, 8], label: 2)
|
33
|
+
expect_trackable_values(test_data.last, [3, 6, 9], label: 0)
|
34
|
+
end
|
24
35
|
end
|
25
36
|
end
|
26
37
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
context '#slice_after' do
|
3
|
+
subject(:test_source) do
|
4
|
+
described_class.enumerable(['A', 'B', 0, 'C', 2, true, false, 3, 'DE'])
|
5
|
+
end
|
6
|
+
|
7
|
+
it 'emits Reacto::Trackable instances emitting slices of the values, ' \
|
8
|
+
'emitted by the source. The slices are determined by the last value ' \
|
9
|
+
'for which <pattern> === value is true' do
|
10
|
+
trackable = test_source.slice_after(Integer)
|
11
|
+
|
12
|
+
attach_test_trackers(trackable)
|
13
|
+
|
14
|
+
expect(test_data.size).to eq(5)
|
15
|
+
expect_trackable_values(test_data.first, ['A', 'B', 0])
|
16
|
+
expect_trackable_values(test_data[1], ['C', 2])
|
17
|
+
expect_trackable_values(test_data[2], [true, false, 3])
|
18
|
+
expect_trackable_values(test_data[3], %w(DE))
|
19
|
+
expect(test_data.last).to eq('|')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'emits Reacto::Trackable instances emitting slices of the values, ' \
|
23
|
+
'emitted by the source. The slices are determined by the last value ' \
|
24
|
+
'the block given returns true' do
|
25
|
+
trackable = test_source.slice_after do |val|
|
26
|
+
val == false || val == 0
|
27
|
+
end
|
28
|
+
|
29
|
+
attach_test_trackers(trackable)
|
30
|
+
|
31
|
+
expect(test_data.size).to eq(4)
|
32
|
+
expect_trackable_values(test_data.first, ['A', 'B', 0])
|
33
|
+
expect_trackable_values(test_data[1], ['C', 2, true, false])
|
34
|
+
expect_trackable_values(test_data[2], [3, 'DE'])
|
35
|
+
expect(test_data.last).to eq('|')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|