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
data/Gemfile.lock
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
reacto (0.1.0)
|
5
|
-
concurrent-ruby (~> 1.0.0)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
concurrent-ruby (1.0.2)
|
11
|
-
diff-lcs (1.2.5)
|
12
|
-
rspec (3.3.0)
|
13
|
-
rspec-core (~> 3.3.0)
|
14
|
-
rspec-expectations (~> 3.3.0)
|
15
|
-
rspec-mocks (~> 3.3.0)
|
16
|
-
rspec-core (3.3.2)
|
17
|
-
rspec-support (~> 3.3.0)
|
18
|
-
rspec-expectations (3.3.1)
|
19
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
-
rspec-support (~> 3.3.0)
|
21
|
-
rspec-mocks (3.3.2)
|
22
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
-
rspec-support (~> 3.3.0)
|
24
|
-
rspec-support (3.3.0)
|
25
|
-
|
26
|
-
PLATFORMS
|
27
|
-
ruby
|
28
|
-
|
29
|
-
DEPENDENCIES
|
30
|
-
bundler (~> 1.3)
|
31
|
-
reacto!
|
32
|
-
rspec (~> 3.3.0)
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'reacto/constants'
|
2
|
-
require 'reacto/subscriptions/operation_subscription'
|
3
|
-
require 'reacto/cache/memory'
|
4
|
-
require 'reacto/cache/file'
|
5
|
-
|
6
|
-
module Reacto
|
7
|
-
module Operations
|
8
|
-
class Cache
|
9
|
-
TYPES = {
|
10
|
-
memory: Reacto::Cache::Memory,
|
11
|
-
file: Reacto::Cache::File
|
12
|
-
}
|
13
|
-
|
14
|
-
def initialize(type: :memory, **settings)
|
15
|
-
type = TYPES[type] if TYPES.key?(type)
|
16
|
-
|
17
|
-
@cache = type.new(**settings)
|
18
|
-
end
|
19
|
-
|
20
|
-
def call(tracker)
|
21
|
-
if @cache.ready?
|
22
|
-
@cache.each do |value|
|
23
|
-
tracker.on_value(value)
|
24
|
-
end
|
25
|
-
|
26
|
-
if @cache.error?
|
27
|
-
tracker.on_error(@cache.error)
|
28
|
-
else
|
29
|
-
tracker.on_close
|
30
|
-
end
|
31
|
-
|
32
|
-
NOTHING
|
33
|
-
else
|
34
|
-
Subscriptions::OperationSubscription.new(
|
35
|
-
tracker,
|
36
|
-
value: -> (v) do
|
37
|
-
@cache.on_value(v)
|
38
|
-
tracker.on_value(v)
|
39
|
-
end,
|
40
|
-
error: -> (e) do
|
41
|
-
@cache.on_error(e)
|
42
|
-
tracker.on_error(e)
|
43
|
-
end,
|
44
|
-
close: -> () do
|
45
|
-
@cache.on_close
|
46
|
-
tracker.on_close
|
47
|
-
end
|
48
|
-
)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
context Reacto::Trackable do
|
4
|
-
let(:source_updates) { [] }
|
5
|
-
let(:source) do
|
6
|
-
Reacto::Trackable.make do |tracker|
|
7
|
-
source_updates << true
|
8
|
-
|
9
|
-
tracker.on_value(3)
|
10
|
-
tracker.on_value(4)
|
11
|
-
tracker.on_value(5)
|
12
|
-
tracker.on_close
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def check_cache(trackable)
|
17
|
-
trackable.on(value: test_on_value, close: test_on_close)
|
18
|
-
expect(test_data).to be == [3, 4, 5, '|']
|
19
|
-
expect(source_updates).to be == [true]
|
20
|
-
|
21
|
-
trackable.on(value: test_on_value, close: test_on_close)
|
22
|
-
expect(test_data).to be == [3, 4, 5, '|', 3, 4, 5, '|']
|
23
|
-
expect(source_updates).to be == [true]
|
24
|
-
end
|
25
|
-
|
26
|
-
context '#cache' do
|
27
|
-
context 'memory' do
|
28
|
-
it 'caches all the values received before the closing notifincation and ' \
|
29
|
-
'replayes them on subsequent subscriptions' do
|
30
|
-
check_cache(source.cache)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'file' do
|
35
|
-
after(:each) do
|
36
|
-
File.delete('tmp/test.cache')
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'caches all the values received before the closing notifincation and ' \
|
40
|
-
'replayes them on subsequent subscriptions' do
|
41
|
-
check_cache(source.cache(type: :file, location: 'tmp/test.cache'))
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'uses the cache only if it is fresh' do
|
45
|
-
trackable1 =
|
46
|
-
source.cache(type: :file, location: 'tmp/test.cache', ttl: 0.5)
|
47
|
-
|
48
|
-
check_cache(trackable1)
|
49
|
-
|
50
|
-
trackable2 =
|
51
|
-
source.cache(type: :file, location: 'tmp/test.cache', ttl: 0.5)
|
52
|
-
trackable2.on
|
53
|
-
expect(source_updates).to be == [true]
|
54
|
-
|
55
|
-
sleep(1)
|
56
|
-
|
57
|
-
trackable3 =
|
58
|
-
source.cache(type: :file, location: 'tmp/test.cache', ttl: 0.5)
|
59
|
-
trackable3.on
|
60
|
-
expect(source_updates).to be == [true] * 2
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|