tilia-event 2.0.2 → 2.0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.simplecov +1 -1
- data/Gemfile +2 -3
- data/Gemfile.lock +16 -13
- data/lib/tilia/event/event_emitter.rb +0 -5
- data/lib/tilia/event/event_emitter_interface.rb +20 -20
- data/lib/tilia/event/event_emitter_trait.rb +14 -68
- data/lib/tilia/event/promise.rb +10 -33
- data/lib/tilia/event/promise_already_resolved_exception.rb +1 -1
- data/lib/tilia/event/version.rb +1 -1
- data/test/continue_callback_test.rb +12 -12
- data/test/event_emitter_test.rb +41 -41
- data/test/promise_test.rb +7 -7
- data/tilia-event.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd62eda4d7ad27d38ac0646a1ed55ced5d1f7a36
|
4
|
+
data.tar.gz: a62e52f647e8e57f96cb3d71f565b14884724f05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ed6f9171f2a35753e2478444efde70bd8e31342038dbd482a70b134876be432d084e4f2a0a8200a50d1277c21f35e857c5c1141cd510021be286d12c3dfe21a
|
7
|
+
data.tar.gz: 2d98457d04bf88779e1275201004a1e613e7437a853392a178e6f6a046658774d958af5ceecd9cb9821b2f8e2d9316a0d604eb3eb4b2abad2862bed97b60b63a
|
data/.simplecov
CHANGED
data/Gemfile
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
gem 'activesupport', '~> 4.2'
|
3
|
+
gemspec
|
5
4
|
|
6
5
|
# Testing
|
7
6
|
gem 'rake'
|
8
7
|
gem 'minitest', '~> 5.8'
|
9
8
|
gem 'simplecov', '~> 0.10'
|
10
|
-
gem 'rubocop', '~> 0.
|
9
|
+
gem 'rubocop', '~> 0.36'
|
11
10
|
gem 'yard', '~> 0.8'
|
data/Gemfile.lock
CHANGED
@@ -1,30 +1,33 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tilia-event (2.0.2.1)
|
5
|
+
activesupport (>= 4.0)
|
6
|
+
|
1
7
|
GEM
|
2
8
|
remote: https://rubygems.org/
|
3
9
|
specs:
|
4
|
-
activesupport (4.2.
|
10
|
+
activesupport (4.2.5.1)
|
5
11
|
i18n (~> 0.7)
|
6
12
|
json (~> 1.7, >= 1.7.7)
|
7
13
|
minitest (~> 5.1)
|
8
14
|
thread_safe (~> 0.3, >= 0.3.4)
|
9
15
|
tzinfo (~> 1.1)
|
10
|
-
ast (2.
|
11
|
-
astrolabe (1.3.1)
|
12
|
-
parser (~> 2.2)
|
16
|
+
ast (2.2.0)
|
13
17
|
docile (1.1.5)
|
14
18
|
i18n (0.7.0)
|
15
19
|
json (1.8.3)
|
16
20
|
minitest (5.8.1)
|
17
|
-
parser (2.
|
18
|
-
ast (
|
21
|
+
parser (2.3.0.2)
|
22
|
+
ast (~> 2.2)
|
19
23
|
powerpack (0.1.1)
|
20
|
-
rainbow (2.
|
24
|
+
rainbow (2.1.0)
|
21
25
|
rake (10.4.2)
|
22
|
-
rubocop (0.
|
23
|
-
|
24
|
-
parser (>= 2.2.2.5, < 3.0)
|
26
|
+
rubocop (0.36.0)
|
27
|
+
parser (>= 2.3.0.0, < 3.0)
|
25
28
|
powerpack (~> 0.1)
|
26
29
|
rainbow (>= 1.99.1, < 3.0)
|
27
|
-
ruby-progressbar (~> 1.
|
30
|
+
ruby-progressbar (~> 1.7)
|
28
31
|
ruby-progressbar (1.7.5)
|
29
32
|
simplecov (0.10.0)
|
30
33
|
docile (~> 1.1.0)
|
@@ -40,11 +43,11 @@ PLATFORMS
|
|
40
43
|
ruby
|
41
44
|
|
42
45
|
DEPENDENCIES
|
43
|
-
activesupport (~> 4.2)
|
44
46
|
minitest (~> 5.8)
|
45
47
|
rake
|
46
|
-
rubocop (~> 0.
|
48
|
+
rubocop (~> 0.36)
|
47
49
|
simplecov (~> 0.10)
|
50
|
+
tilia-event!
|
48
51
|
yard (~> 0.8)
|
49
52
|
|
50
53
|
BUNDLED WITH
|
@@ -7,20 +7,20 @@ module Tilia
|
|
7
7
|
module EventEmitterInterface
|
8
8
|
# Subscribe to an event.
|
9
9
|
#
|
10
|
-
# @param
|
11
|
-
# @param [
|
12
|
-
# @param [Fixnum]
|
10
|
+
# @param event_name
|
11
|
+
# @param [#call] call_back
|
12
|
+
# @param [Fixnum] priority
|
13
13
|
# @return [void]
|
14
|
-
def on(
|
14
|
+
def on(event_name, call_back, priority = 100)
|
15
15
|
end
|
16
16
|
|
17
17
|
# Subscribe to an event exactly once.
|
18
18
|
#
|
19
|
-
# @param
|
20
|
-
# @param [
|
21
|
-
# @param [Fixnum]
|
19
|
+
# @param event_name
|
20
|
+
# @param [#call] call_back
|
21
|
+
# @param [Fixnum] priority
|
22
22
|
# @return [void]
|
23
|
-
def once(
|
23
|
+
def once(event_name, call_back, priority = 100)
|
24
24
|
end
|
25
25
|
|
26
26
|
# Emits an event.
|
@@ -43,11 +43,11 @@ module Tilia
|
|
43
43
|
# Lastly, if there are 5 event handlers for an event. The continueCallback
|
44
44
|
# will be called at most 4 times.
|
45
45
|
#
|
46
|
-
# @param
|
47
|
-
# @param [Array]
|
48
|
-
# @param [
|
46
|
+
# @param event_name
|
47
|
+
# @param [Array] arguments
|
48
|
+
# @param [#call, nil] continue_call_back
|
49
49
|
# @return [Boolean]
|
50
|
-
def emit(
|
50
|
+
def emit(event_name, arguments = [], continue_call_back = nil)
|
51
51
|
end
|
52
52
|
|
53
53
|
# Returns the list of listeners for an event.
|
@@ -55,9 +55,9 @@ module Tilia
|
|
55
55
|
# The list is returned as an array, and the list of events are sorted by
|
56
56
|
# their priority.
|
57
57
|
#
|
58
|
-
# @param
|
59
|
-
# @return [Array
|
60
|
-
def listeners(
|
58
|
+
# @param event_name
|
59
|
+
# @return [Array<#call>]
|
60
|
+
def listeners(event_name)
|
61
61
|
end
|
62
62
|
|
63
63
|
# Removes a specific listener from an event.
|
@@ -65,10 +65,10 @@ module Tilia
|
|
65
65
|
# If the listener could not be found, this method will return false. If it
|
66
66
|
# was removed it will return true.
|
67
67
|
#
|
68
|
-
# @param
|
69
|
-
# @param [
|
68
|
+
# @param event_name
|
69
|
+
# @param [#call] listener
|
70
70
|
# @return [Boolean]
|
71
|
-
def remove_listener(
|
71
|
+
def remove_listener(event_name, listener)
|
72
72
|
end
|
73
73
|
|
74
74
|
# Removes all listeners.
|
@@ -77,9 +77,9 @@ module Tilia
|
|
77
77
|
# removed. If it is not specified, every listener for every event is
|
78
78
|
# removed.
|
79
79
|
#
|
80
|
-
# @param
|
80
|
+
# @param event_name
|
81
81
|
# @return [void]
|
82
|
-
def remove_all_listeners(
|
82
|
+
def remove_all_listeners(event_name = nil)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
@@ -8,17 +8,16 @@ module Tilia
|
|
8
8
|
# Using the trait + interface allows you to add EventEmitter capabilities
|
9
9
|
# without having to change your base-class.
|
10
10
|
module EventEmitterTrait
|
11
|
-
#
|
11
|
+
# Initializes the instance variables of the trait
|
12
12
|
#
|
13
|
-
#
|
14
|
-
|
13
|
+
# Do not forget to call super when initializing classes including this
|
14
|
+
# module
|
15
|
+
def initialize(*args)
|
16
|
+
@listeners = {}
|
17
|
+
super
|
18
|
+
end
|
15
19
|
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# @param [String] event_name
|
19
|
-
# @param [Proc, Method] call_back
|
20
|
-
# @param [Fixnum] priority
|
21
|
-
# @return [void]
|
20
|
+
# (see EventEmitterInterface#on)
|
22
21
|
def on(event_name, call_back, priority = 100)
|
23
22
|
@listeners[event_name] ||= [false, [], []]
|
24
23
|
|
@@ -27,12 +26,7 @@ module Tilia
|
|
27
26
|
@listeners[event_name][2] << call_back
|
28
27
|
end
|
29
28
|
|
30
|
-
#
|
31
|
-
#
|
32
|
-
# @param [String] event_name
|
33
|
-
# @param [Proc, Method] call_back
|
34
|
-
# @param [Fixnum] priority
|
35
|
-
# @return [void]
|
29
|
+
# (see EventEmitterInterface#once)
|
36
30
|
def once(event_name, call_back, priority = 100)
|
37
31
|
wrapper = nil
|
38
32
|
wrapper = lambda do |*arguments|
|
@@ -43,30 +37,7 @@ module Tilia
|
|
43
37
|
on(event_name, wrapper, priority)
|
44
38
|
end
|
45
39
|
|
46
|
-
#
|
47
|
-
#
|
48
|
-
# This method will return true if 0 or more listeners were succesfully
|
49
|
-
# handled. false is returned if one of the events broke the event chain.
|
50
|
-
#
|
51
|
-
# If the continueCallBack is specified, this callback will be called every
|
52
|
-
# time before the next event handler is called.
|
53
|
-
#
|
54
|
-
# If the continueCallback returns false, event propagation stops. This
|
55
|
-
# allows you to use the eventEmitter as a means for listeners to implement
|
56
|
-
# functionality in your application, and break the event loop as soon as
|
57
|
-
# some condition is fulfilled.
|
58
|
-
#
|
59
|
-
# Note that returning false from an event subscriber breaks propagation
|
60
|
-
# and returns false, but if the continue-callback stops propagation, this
|
61
|
-
# is still considered a 'successful' operation and returns true.
|
62
|
-
#
|
63
|
-
# Lastly, if there are 5 event handlers for an event. The continueCallback
|
64
|
-
# will be called at most 4 times.
|
65
|
-
#
|
66
|
-
# @param [String] event_name
|
67
|
-
# @param [Array] arguments
|
68
|
-
# @param [Proc, method] continue_call_back
|
69
|
-
# @return [Boolean]
|
40
|
+
# (see EventEmitterInterface#emit)
|
70
41
|
def emit(event_name, arguments = [], continue_call_back = nil)
|
71
42
|
if !continue_call_back.is_a?(Proc)
|
72
43
|
|
@@ -91,13 +62,7 @@ module Tilia
|
|
91
62
|
true
|
92
63
|
end
|
93
64
|
|
94
|
-
#
|
95
|
-
#
|
96
|
-
# The list is returned as an array, and the list of events are sorted by
|
97
|
-
# their priority.
|
98
|
-
#
|
99
|
-
# @param [String] event_name
|
100
|
-
# @return [Array<Proc, Method>]
|
65
|
+
# (see EventEmitterInterface#listeners)
|
101
66
|
def listeners(event_name)
|
102
67
|
return [] unless @listeners.key? event_name
|
103
68
|
|
@@ -123,14 +88,7 @@ module Tilia
|
|
123
88
|
@listeners[event_name][2]
|
124
89
|
end
|
125
90
|
|
126
|
-
#
|
127
|
-
#
|
128
|
-
# If the listener could not be found, this method will return false. If it
|
129
|
-
# was removed it will return true.
|
130
|
-
#
|
131
|
-
# @param [String] event_name
|
132
|
-
# @param [Proc, Method] listener
|
133
|
-
# @return [Boolean]
|
91
|
+
# (see EventEmitterInterface#remove_listener)
|
134
92
|
def remove_listener(event_name, listener)
|
135
93
|
return false unless @listeners.key?(event_name)
|
136
94
|
|
@@ -144,26 +102,14 @@ module Tilia
|
|
144
102
|
false
|
145
103
|
end
|
146
104
|
|
147
|
-
#
|
148
|
-
#
|
149
|
-
# If the eventName argument is specified, all listeners for that event are
|
150
|
-
# removed. If it is not specified, every listener for every event is
|
151
|
-
# removed.
|
152
|
-
#
|
153
|
-
# @param [String] event_name
|
154
|
-
# @return [void]
|
105
|
+
# (see EventEmitterInterface#remove_all_listeners)
|
155
106
|
def remove_all_listeners(event_name = nil)
|
156
|
-
if
|
107
|
+
if event_name
|
157
108
|
@listeners.delete(event_name)
|
158
109
|
else
|
159
110
|
@listeners = {}
|
160
111
|
end
|
161
112
|
end
|
162
|
-
|
163
|
-
# TODO: document
|
164
|
-
def initialize_event_emitter_trait
|
165
|
-
@listeners = {}
|
166
|
-
end
|
167
113
|
end
|
168
114
|
end
|
169
115
|
end
|
data/lib/tilia/event/promise.rb
CHANGED
@@ -14,27 +14,6 @@ module Tilia
|
|
14
14
|
# The promise was rejected. The operation failed.
|
15
15
|
REJECTED = 2
|
16
16
|
|
17
|
-
protected
|
18
|
-
|
19
|
-
# The current state of this promise.
|
20
|
-
#
|
21
|
-
# @return [Fixnum]
|
22
|
-
attr_accessor :state
|
23
|
-
|
24
|
-
# A list of subscribers. Subscribers are the callbacks that want us to let
|
25
|
-
# them know if the callback was fulfilled or rejected.
|
26
|
-
#
|
27
|
-
# @return [Array]
|
28
|
-
attr_accessor :subscribers
|
29
|
-
|
30
|
-
# The result of the promise.
|
31
|
-
#
|
32
|
-
# If the promise was fulfilled, this will be the result value. If the
|
33
|
-
# promise was rejected, this is most commonly an exception.
|
34
|
-
attr_accessor :value
|
35
|
-
|
36
|
-
public
|
37
|
-
|
38
17
|
# Creates the promise.
|
39
18
|
#
|
40
19
|
# The passed argument is the executor. The executor is automatically
|
@@ -43,7 +22,7 @@ module Tilia
|
|
43
22
|
# Each are callbacks that map to self.fulfill and self.reject.
|
44
23
|
# Using the executor is optional.
|
45
24
|
#
|
46
|
-
# @param [
|
25
|
+
# @param [#call, nil] executor
|
47
26
|
# @return [void]
|
48
27
|
def initialize(executor = nil)
|
49
28
|
@state = PENDING
|
@@ -71,11 +50,11 @@ module Tilia
|
|
71
50
|
# If either of the callbacks throw an exception, the returned promise will
|
72
51
|
# be rejected and the exception will be passed back.
|
73
52
|
#
|
74
|
-
# @param [
|
75
|
-
# @param [
|
53
|
+
# @param [#call, nil] on_fulfilled
|
54
|
+
# @param [#call, nil] on_rejected
|
76
55
|
# @return [Promise]
|
77
56
|
def then(on_fulfilled = nil, on_rejected = nil)
|
78
|
-
sub_promise =
|
57
|
+
sub_promise = Promise.new
|
79
58
|
case @state
|
80
59
|
when PENDING
|
81
60
|
@subscribers << [sub_promise, on_fulfilled, on_rejected]
|
@@ -92,7 +71,7 @@ module Tilia
|
|
92
71
|
# I would have used the word 'catch', but it's a reserved word in PHP, so
|
93
72
|
# we're not allowed to call our function that.
|
94
73
|
#
|
95
|
-
# @param [
|
74
|
+
# @param [#call] on_rejected
|
96
75
|
# @return [Promise]
|
97
76
|
def error(on_rejected)
|
98
77
|
self.then(nil, on_rejected)
|
@@ -169,13 +148,13 @@ module Tilia
|
|
169
148
|
# rejected.
|
170
149
|
#
|
171
150
|
# @param [Promise] sub_promise
|
172
|
-
# @param [
|
151
|
+
# @param [#call, nil] call_back
|
173
152
|
# @return [void]
|
174
153
|
def invoke_callback(sub_promise, call_back = nil)
|
175
154
|
if call_back.is_a?(Proc) || call_back.is_a?(Method)
|
176
155
|
begin
|
177
156
|
result = call_back.call(@value)
|
178
|
-
if result.is_a?(
|
157
|
+
if result.is_a?(Promise)
|
179
158
|
result.then(sub_promise.method(:fulfill), sub_promise.method(:reject))
|
180
159
|
else
|
181
160
|
sub_promise.fulfill(result)
|
@@ -183,12 +162,10 @@ module Tilia
|
|
183
162
|
rescue => e
|
184
163
|
sub_promise.reject(e.to_s)
|
185
164
|
end
|
165
|
+
elsif @state == FULFILLED
|
166
|
+
sub_promise.fulfill(@value)
|
186
167
|
else
|
187
|
-
|
188
|
-
sub_promise.fulfill(@value)
|
189
|
-
else
|
190
|
-
sub_promise.reject(@value)
|
191
|
-
end
|
168
|
+
sub_promise.reject(@value)
|
192
169
|
end
|
193
170
|
end
|
194
171
|
end
|
@@ -2,7 +2,7 @@ module Tilia
|
|
2
2
|
module Event
|
3
3
|
# This exception is thrown when the user tried to reject or fulfill a promise,
|
4
4
|
# after either of these actions were already performed.
|
5
|
-
class PromiseAlreadyResolvedException <
|
5
|
+
class PromiseAlreadyResolvedException < StandardError
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
data/lib/tilia/event/version.rb
CHANGED
@@ -11,13 +11,13 @@ module Tilia
|
|
11
11
|
handler_counter += 1
|
12
12
|
end
|
13
13
|
|
14
|
-
ee.on(
|
15
|
-
ee.on(
|
16
|
-
ee.on(
|
14
|
+
ee.on(:foo, bla)
|
15
|
+
ee.on(:foo, bla)
|
16
|
+
ee.on(:foo, bla)
|
17
17
|
|
18
18
|
continue_counter = 0
|
19
19
|
r = ee.emit(
|
20
|
-
|
20
|
+
:foo,
|
21
21
|
[],
|
22
22
|
lambda do
|
23
23
|
continue_counter += 1
|
@@ -38,13 +38,13 @@ module Tilia
|
|
38
38
|
handler_counter += 1
|
39
39
|
end
|
40
40
|
|
41
|
-
ee.on(
|
42
|
-
ee.on(
|
43
|
-
ee.on(
|
41
|
+
ee.on(:foo, bla)
|
42
|
+
ee.on(:foo, bla)
|
43
|
+
ee.on(:foo, bla)
|
44
44
|
|
45
45
|
continue_counter = 0
|
46
46
|
r = ee.emit(
|
47
|
-
|
47
|
+
:foo,
|
48
48
|
[],
|
49
49
|
lambda do
|
50
50
|
continue_counter += 1
|
@@ -66,13 +66,13 @@ module Tilia
|
|
66
66
|
false
|
67
67
|
end
|
68
68
|
|
69
|
-
ee.on(
|
70
|
-
ee.on(
|
71
|
-
ee.on(
|
69
|
+
ee.on(:foo, bla)
|
70
|
+
ee.on(:foo, bla)
|
71
|
+
ee.on(:foo, bla)
|
72
72
|
|
73
73
|
continue_counter = 0
|
74
74
|
r = ee.emit(
|
75
|
-
|
75
|
+
:foo,
|
76
76
|
[],
|
77
77
|
lambda do
|
78
78
|
continue_counter += 1
|
data/test/event_emitter_test.rb
CHANGED
@@ -12,19 +12,19 @@ module Tilia
|
|
12
12
|
ee = EventEmitter.new
|
13
13
|
callback1 = -> {}
|
14
14
|
callback2 = -> {}
|
15
|
-
ee.on(
|
16
|
-
ee.on(
|
15
|
+
ee.on(:foo, callback1, 200)
|
16
|
+
ee.on(:foo, callback2, 100)
|
17
17
|
|
18
|
-
assert_equal([callback2, callback1], ee.listeners(
|
18
|
+
assert_equal([callback2, callback1], ee.listeners(:foo))
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_handle_event
|
22
22
|
arg_result = nil
|
23
23
|
|
24
24
|
ee = EventEmitter.new
|
25
|
-
ee.on(
|
25
|
+
ee.on(:foo, ->(arg) { arg_result = arg })
|
26
26
|
|
27
|
-
assert(ee.emit(
|
27
|
+
assert(ee.emit(:foo, ['bar']))
|
28
28
|
assert_equal('bar', arg_result)
|
29
29
|
end
|
30
30
|
|
@@ -33,15 +33,15 @@ module Tilia
|
|
33
33
|
|
34
34
|
ee = EventEmitter.new
|
35
35
|
ee.on(
|
36
|
-
|
36
|
+
:foo,
|
37
37
|
lambda do |_|
|
38
38
|
arg_result = 1
|
39
39
|
false
|
40
40
|
end
|
41
41
|
)
|
42
|
-
ee.on(
|
42
|
+
ee.on(:foo, ->(_) { arg_result = 2 })
|
43
43
|
|
44
|
-
refute(ee.emit(
|
44
|
+
refute(ee.emit(:foo, ['bar']))
|
45
45
|
assert_equal(1, arg_result)
|
46
46
|
end
|
47
47
|
|
@@ -50,14 +50,14 @@ module Tilia
|
|
50
50
|
|
51
51
|
ee = EventEmitter.new
|
52
52
|
ee.on(
|
53
|
-
|
53
|
+
:foo,
|
54
54
|
lambda do |_|
|
55
55
|
arg_result = 1
|
56
56
|
false
|
57
57
|
end
|
58
58
|
)
|
59
59
|
ee.on(
|
60
|
-
|
60
|
+
:foo,
|
61
61
|
lambda do |_|
|
62
62
|
arg_result = 2
|
63
63
|
false
|
@@ -65,7 +65,7 @@ module Tilia
|
|
65
65
|
1
|
66
66
|
)
|
67
67
|
|
68
|
-
refute(ee.emit(
|
68
|
+
refute(ee.emit(:foo, ['bar']))
|
69
69
|
assert_equal(2, arg_result)
|
70
70
|
end
|
71
71
|
|
@@ -73,12 +73,12 @@ module Tilia
|
|
73
73
|
result = []
|
74
74
|
ee = EventEmitter.new
|
75
75
|
|
76
|
-
ee.on(
|
77
|
-
ee.on(
|
78
|
-
ee.on(
|
79
|
-
ee.on(
|
76
|
+
ee.on(:foo, -> { result << 'a' }, 200)
|
77
|
+
ee.on(:foo, -> { result << 'b' }, 50)
|
78
|
+
ee.on(:foo, -> { result << 'c' }, 300)
|
79
|
+
ee.on(:foo, -> { result << 'd' })
|
80
80
|
|
81
|
-
ee.emit(
|
81
|
+
ee.emit(:foo)
|
82
82
|
assert_equal(%w(b d a c), result)
|
83
83
|
end
|
84
84
|
|
@@ -89,15 +89,15 @@ module Tilia
|
|
89
89
|
|
90
90
|
ee = EventEmitter.new
|
91
91
|
|
92
|
-
ee.on(
|
93
|
-
ee.emit(
|
92
|
+
ee.on(:foo, call_back)
|
93
|
+
ee.emit(:foo)
|
94
94
|
|
95
95
|
assert(result)
|
96
96
|
result = false
|
97
97
|
|
98
|
-
assert(ee.remove_listener(
|
98
|
+
assert(ee.remove_listener(:foo, call_back))
|
99
99
|
|
100
|
-
ee.emit(
|
100
|
+
ee.emit(:foo)
|
101
101
|
refute(result)
|
102
102
|
end
|
103
103
|
|
@@ -108,15 +108,15 @@ module Tilia
|
|
108
108
|
|
109
109
|
ee = EventEmitter.new
|
110
110
|
|
111
|
-
ee.on(
|
112
|
-
ee.emit(
|
111
|
+
ee.on(:foo, call_back)
|
112
|
+
ee.emit(:foo)
|
113
113
|
|
114
114
|
assert(result)
|
115
115
|
result = false
|
116
116
|
|
117
117
|
refute(ee.remove_listener('bar', call_back))
|
118
118
|
|
119
|
-
ee.emit(
|
119
|
+
ee.emit(:foo)
|
120
120
|
assert(result)
|
121
121
|
end
|
122
122
|
|
@@ -127,16 +127,16 @@ module Tilia
|
|
127
127
|
|
128
128
|
ee = EventEmitter.new
|
129
129
|
|
130
|
-
ee.on(
|
131
|
-
ee.emit(
|
130
|
+
ee.on(:foo, call_back)
|
131
|
+
ee.emit(:foo)
|
132
132
|
|
133
133
|
assert(result)
|
134
134
|
result = false
|
135
135
|
|
136
|
-
assert(ee.remove_listener(
|
137
|
-
refute(ee.remove_listener(
|
136
|
+
assert(ee.remove_listener(:foo, call_back))
|
137
|
+
refute(ee.remove_listener(:foo, call_back))
|
138
138
|
|
139
|
-
ee.emit(
|
139
|
+
ee.emit(:foo)
|
140
140
|
refute(result)
|
141
141
|
end
|
142
142
|
|
@@ -147,15 +147,15 @@ module Tilia
|
|
147
147
|
|
148
148
|
ee = EventEmitter.new
|
149
149
|
|
150
|
-
ee.on(
|
151
|
-
ee.emit(
|
150
|
+
ee.on(:foo, call_back)
|
151
|
+
ee.emit(:foo)
|
152
152
|
|
153
153
|
assert(result)
|
154
154
|
result = false
|
155
155
|
|
156
|
-
ee.remove_all_listeners(
|
156
|
+
ee.remove_all_listeners(:foo)
|
157
157
|
|
158
|
-
ee.emit(
|
158
|
+
ee.emit(:foo)
|
159
159
|
refute(result)
|
160
160
|
end
|
161
161
|
|
@@ -166,15 +166,15 @@ module Tilia
|
|
166
166
|
|
167
167
|
ee = EventEmitter.new
|
168
168
|
|
169
|
-
ee.on(
|
170
|
-
ee.emit(
|
169
|
+
ee.on(:foo, call_back)
|
170
|
+
ee.emit(:foo)
|
171
171
|
|
172
172
|
assert(result)
|
173
173
|
result = false
|
174
174
|
|
175
175
|
ee.remove_all_listeners
|
176
176
|
|
177
|
-
ee.emit(
|
177
|
+
ee.emit(:foo)
|
178
178
|
refute(result)
|
179
179
|
end
|
180
180
|
|
@@ -184,10 +184,10 @@ module Tilia
|
|
184
184
|
call_back = -> { result += 1 }
|
185
185
|
|
186
186
|
ee = EventEmitter.new
|
187
|
-
ee.once(
|
187
|
+
ee.once(:foo, call_back)
|
188
188
|
|
189
|
-
ee.emit(
|
190
|
-
ee.emit(
|
189
|
+
ee.emit(:foo)
|
190
|
+
ee.emit(:foo)
|
191
191
|
|
192
192
|
assert_equal(1, result)
|
193
193
|
end
|
@@ -197,14 +197,14 @@ module Tilia
|
|
197
197
|
|
198
198
|
ee = EventEmitter.new
|
199
199
|
ee.once(
|
200
|
-
|
200
|
+
:foo,
|
201
201
|
lambda do |_|
|
202
202
|
arg_result = 1
|
203
203
|
false
|
204
204
|
end
|
205
205
|
)
|
206
206
|
ee.once(
|
207
|
-
|
207
|
+
:foo,
|
208
208
|
lambda do |_|
|
209
209
|
arg_result = 2
|
210
210
|
false
|
@@ -212,7 +212,7 @@ module Tilia
|
|
212
212
|
1
|
213
213
|
)
|
214
214
|
|
215
|
-
refute(ee.emit(
|
215
|
+
refute(ee.emit(:foo, ['bar']))
|
216
216
|
assert_equal(2, arg_result)
|
217
217
|
end
|
218
218
|
end
|
data/test/promise_test.rb
CHANGED
@@ -75,8 +75,8 @@ module Tilia
|
|
75
75
|
|
76
76
|
def test_executor_success
|
77
77
|
real_result = ''
|
78
|
-
|
79
|
-
|
78
|
+
Promise.new(
|
79
|
+
->(success, _failing) { success.call('hi') }
|
80
80
|
).then(
|
81
81
|
->(result) { real_result = result }
|
82
82
|
)
|
@@ -86,8 +86,8 @@ module Tilia
|
|
86
86
|
|
87
87
|
def test_executor_fail
|
88
88
|
real_result = ''
|
89
|
-
|
90
|
-
|
89
|
+
Promise.new(
|
90
|
+
->(_success, failing) { failing.call('hi') }
|
91
91
|
).then(
|
92
92
|
->(_result) { real_result = 'incorrect' },
|
93
93
|
->(reason) { real_result = reason }
|
@@ -113,7 +113,7 @@ module Tilia
|
|
113
113
|
promise = Promise.new
|
114
114
|
promise.error(
|
115
115
|
lambda do |reason|
|
116
|
-
assert_equal(
|
116
|
+
assert_equal(:foo, reason)
|
117
117
|
fail 'hi'
|
118
118
|
end
|
119
119
|
).then(
|
@@ -122,7 +122,7 @@ module Tilia
|
|
122
122
|
)
|
123
123
|
|
124
124
|
assert_equal(0, ok)
|
125
|
-
promise.reject(
|
125
|
+
promise.reject(:foo)
|
126
126
|
assert_equal(1, ok)
|
127
127
|
end
|
128
128
|
|
@@ -148,7 +148,7 @@ module Tilia
|
|
148
148
|
final_value = 0
|
149
149
|
Promise.all([promise1, promise2]).then(
|
150
150
|
lambda do |_value|
|
151
|
-
final_value =
|
151
|
+
final_value = :foo
|
152
152
|
'test'
|
153
153
|
end,
|
154
154
|
->(value) { final_value = value }
|
data/tilia-event.gemspec
CHANGED
@@ -9,5 +9,5 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = 'tilia@jakobsack.de'
|
10
10
|
s.files = `git ls-files`.split("\n")
|
11
11
|
s.homepage = 'https://github.com/tilia/tilia-event'
|
12
|
-
s.add_runtime_dependency 'activesupport', '
|
12
|
+
s.add_runtime_dependency 'activesupport', '>= 4.0'
|
13
13
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tilia-event
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.2
|
4
|
+
version: 2.0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakob Sack
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '4.
|
19
|
+
version: '4.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '4.
|
26
|
+
version: '4.0'
|
27
27
|
description: tilia-event is a library for lightweight event-based programming.
|
28
28
|
email: tilia@jakobsack.de
|
29
29
|
executables: []
|