microevent 1.0.0 → 1.1.1
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 +5 -5
- data/CHANGELOG.md +21 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +9 -1
- data/README.md +15 -3
- data/Rakefile +41 -0
- data/lib/microevent.rb +5 -5
- data/microevent.gemspec +3 -2
- data/spec/microevent_spec.rb +47 -8
- metadata +9 -9
- data/.travis.yml +0 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 2fb5c4d651245d3f8658996389c8dc59fe8f4c5703fb09063203b85d9fb2aa0f
|
|
4
|
+
data.tar.gz: d0bf7f138bb2058562792f641f711b5bcbcfffbf7869c0480a1052d76b439201
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 87adc99974e72f9f463a388e32e2fec5335e0d73e19aebd7a6fda37c849596f24505b5c4a209ce33ab72b6178cc735b51a03afcc593f8eaa03d85f4d9f078e16
|
|
7
|
+
data.tar.gz: 60e378d3135c886cd54abd0257a46a89b13204ce73f5aaf215259160bbf9a9a5bae5aae8d5d960f34a7e8197b331a53b5cae3f3e24f8e79701b013d124c76292
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## CHANGELOG
|
|
2
|
+
|
|
3
|
+
### 1.1.1
|
|
4
|
+
|
|
5
|
+
- 2022 re-release: Update Gemspec and CI
|
|
6
|
+
|
|
7
|
+
### 1.1.0
|
|
8
|
+
|
|
9
|
+
* Only check if event store hash should be created on #bind, not on #unbind and #trigger
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### 1.0.2
|
|
13
|
+
|
|
14
|
+
* Dupping event array before triggering for better thread safety
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### 1.0.1
|
|
18
|
+
|
|
19
|
+
* Fix wrong gem uploded to rubygems
|
|
20
|
+
|
|
21
|
+
|
|
1
22
|
### 1.0.0
|
|
2
23
|
|
|
3
24
|
* Release
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
microevent (1.
|
|
4
|
+
microevent (1.1.0)
|
|
5
|
+
added (~> 1.0.1)
|
|
6
|
+
thread_safe (~> 0.3.5)
|
|
5
7
|
|
|
6
8
|
GEM
|
|
7
9
|
remote: https://rubygems.org/
|
|
8
10
|
specs:
|
|
11
|
+
added (1.0.1)
|
|
12
|
+
minitest (5.5.1)
|
|
13
|
+
thread_safe (0.3.5)
|
|
14
|
+
thread_safe (0.3.5-java)
|
|
9
15
|
|
|
10
16
|
PLATFORMS
|
|
17
|
+
java
|
|
11
18
|
ruby
|
|
12
19
|
|
|
13
20
|
DEPENDENCIES
|
|
14
21
|
microevent!
|
|
22
|
+
minitest
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# MicroEvent.rb [![[
|
|
1
|
+
# MicroEvent.rb [![[version]](https://badge.fury.io/rb/microevent.svg)](https://badge.fury.io/rb/microevent) [![[CI]](https://github.com/janlelis/microevent.rb/workflows/Test/badge.svg)](https://github.com/janlelis/microevent.rb/actions?query=workflow%3ATest)
|
|
2
2
|
|
|
3
3
|
MicroEvent.rb is a event emitter library which provides the observer pattern to Ruby objects. It is inspired by [MicroEvent.js](https://github.com/jeromeetienne/microevent.js), implemented in less than [20 lines of Ruby](https://github.com/janlelis/microevent.rb/blob/master/lib/microevent.rb).
|
|
4
4
|
|
|
@@ -46,8 +46,20 @@ end
|
|
|
46
46
|
Klass.trigger :slot # => Go
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
You will find more examples in the [tests](https://github.com/janlelis/microevent.rb/blob/master/spec/
|
|
49
|
+
You will find more examples in the [tests](https://github.com/janlelis/microevent.rb/blob/master/spec/microevent_spec.rb).
|
|
50
|
+
|
|
51
|
+
## Alternative Variants
|
|
52
|
+
|
|
53
|
+
* [threadsafe](https://github.com/janlelis/microevent.rb/tree/threadsafe) - Thread safe version
|
|
54
|
+
* [added](https://github.com/janlelis/microevent.rb/tree/added) - Thread safe version based on [added](https://github.com/janlelis/added) hook
|
|
55
|
+
* [min](https://github.com/janlelis/microevent.rb/tree/min) - 275 bytes version
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
## Projects Using MicroEvent.rb
|
|
59
|
+
|
|
60
|
+
* [micrologger](https://github.com/janlelis/micrologger)
|
|
61
|
+
|
|
50
62
|
|
|
51
63
|
## MIT License
|
|
52
64
|
|
|
53
|
-
Ruby version by [Jan Lelis](
|
|
65
|
+
Ruby version by [Jan Lelis](https://janlelis.com). Inspired by [MicroEvent.js](https://github.com/jeromeetienne/microevent.js) by Jerome Etienne.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# # #
|
|
2
|
+
# Get gemspec info
|
|
3
|
+
|
|
4
|
+
gemspec_file = Dir["*.gemspec"].first
|
|
5
|
+
gemspec = eval File.read(gemspec_file), binding, gemspec_file
|
|
6
|
+
info = "#{gemspec.name} | #{gemspec.version} | " \
|
|
7
|
+
"#{gemspec.runtime_dependencies.size} dependencies | " \
|
|
8
|
+
"#{gemspec.files.size} files"
|
|
9
|
+
|
|
10
|
+
# # #
|
|
11
|
+
# Gem build and install task
|
|
12
|
+
|
|
13
|
+
desc info
|
|
14
|
+
task :gem do
|
|
15
|
+
puts info + "\n\n"
|
|
16
|
+
print " "; sh "gem build #{gemspec_file}"
|
|
17
|
+
FileUtils.mkdir_p "pkg"
|
|
18
|
+
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", "pkg"
|
|
19
|
+
puts; sh %{gem install --no-document pkg/#{gemspec.name}-#{gemspec.version}.gem}
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# # #
|
|
23
|
+
# Start an IRB session with the gem loaded
|
|
24
|
+
|
|
25
|
+
desc "#{gemspec.name} | IRB"
|
|
26
|
+
task :irb do
|
|
27
|
+
sh "irb -I ./lib -r #{gemspec.name.gsub '-','/'}"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# # #
|
|
31
|
+
# Run specs
|
|
32
|
+
|
|
33
|
+
desc "#{gemspec.name} | Spec"
|
|
34
|
+
task :spec do
|
|
35
|
+
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
|
36
|
+
sh "for %f in (spec/\*.rb) do ruby spec/%f"
|
|
37
|
+
else
|
|
38
|
+
sh "for file in spec/*.rb; do ruby $file; done"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
task default: :spec
|
data/lib/microevent.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module MicroEvent
|
|
2
|
-
VERSION = "1.
|
|
4
|
+
VERSION = "1.1.1"
|
|
3
5
|
|
|
4
6
|
def bind(event, &fn)
|
|
5
7
|
@_ ||= Hash.new{ |h,k| h[k] = [] }
|
|
@@ -7,12 +9,10 @@ module MicroEvent
|
|
|
7
9
|
end
|
|
8
10
|
|
|
9
11
|
def unbind(event, &fn)
|
|
10
|
-
@_
|
|
11
|
-
fn ? @_[event].delete(fn) : @_.delete(event) || []
|
|
12
|
+
fn ? @_ && @_[event].delete(fn) : @_ && @_.delete(event) || []
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def trigger(event, *args)
|
|
15
|
-
|
|
16
|
-
!@_[event].each{ |fn| instance_exec(*args, &fn) }.empty?
|
|
16
|
+
!!@_ && !@_[event].dup.each{ |fn| instance_exec(*args, &fn) }.empty?
|
|
17
17
|
end
|
|
18
18
|
end
|
data/microevent.gemspec
CHANGED
|
@@ -6,14 +6,15 @@ Gem::Specification.new do |gem|
|
|
|
6
6
|
gem.name = "microevent"
|
|
7
7
|
gem.version = MicroEvent::VERSION
|
|
8
8
|
gem.summary = 'MicroEvent.rb is a event emitter library which provides the observer pattern to Ruby objects.'
|
|
9
|
-
gem.description = 'MicroEvent.rb is a event emitter library which provides the observer pattern to Ruby objects. It is inspired by
|
|
9
|
+
gem.description = 'MicroEvent.rb is a event emitter library which provides the observer pattern to Ruby objects. It is inspired by MicroEvent.js and implemented in less than 20 lines of Ruby.'
|
|
10
10
|
gem.license = "MIT"
|
|
11
11
|
gem.authors = ["Jan Lelis"]
|
|
12
|
-
gem.email = "
|
|
12
|
+
gem.email = ["hi@ruby.consulting"]
|
|
13
13
|
gem.homepage = "https://github.com/janlelis/microevent.rb"
|
|
14
14
|
|
|
15
15
|
gem.files = Dir['{**/}{.*,*}'].select { |path| File.file?(path) }
|
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
18
18
|
gem.require_paths = ['lib']
|
|
19
|
+
gem.metadata = { "rubygems_mfa_required" => "true" }
|
|
19
20
|
end
|
data/spec/microevent_spec.rb
CHANGED
|
@@ -139,14 +139,6 @@ describe MicroEvent do
|
|
|
139
139
|
assert_equal [23], result
|
|
140
140
|
end
|
|
141
141
|
|
|
142
|
-
it "will do nothing if there is nothing to remove" do
|
|
143
|
-
result = []
|
|
144
|
-
|
|
145
|
-
object.unbind :slot
|
|
146
|
-
|
|
147
|
-
assert_equal [], result
|
|
148
|
-
end
|
|
149
|
-
|
|
150
142
|
it "returns deleted callbacks" do
|
|
151
143
|
fn = proc{}
|
|
152
144
|
object.bind :slot, &fn
|
|
@@ -156,6 +148,14 @@ describe MicroEvent do
|
|
|
156
148
|
end
|
|
157
149
|
|
|
158
150
|
it "will return nil if nothing is removed" do
|
|
151
|
+
fn = proc{}
|
|
152
|
+
object.bind :another_slot, &fn
|
|
153
|
+
result = object.unbind :slot, &fn
|
|
154
|
+
|
|
155
|
+
assert_equal nil, result
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it "will return nil if no callback is registered at all" do
|
|
159
159
|
fn = proc{}
|
|
160
160
|
result = object.unbind :slot, &fn
|
|
161
161
|
|
|
@@ -186,6 +186,14 @@ describe MicroEvent do
|
|
|
186
186
|
end
|
|
187
187
|
|
|
188
188
|
it 'will return emtpy array if no block is given and no callback deleted' do
|
|
189
|
+
fn = proc{}
|
|
190
|
+
object.bind :another_slot, &fn
|
|
191
|
+
result = object.unbind :slot
|
|
192
|
+
|
|
193
|
+
assert_equal [], result
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
it 'will return emtpy array if no block is given and no callback is registered at all' do
|
|
189
197
|
result = object.unbind :slot
|
|
190
198
|
|
|
191
199
|
assert_equal [], result
|
|
@@ -210,9 +218,40 @@ describe MicroEvent do
|
|
|
210
218
|
end
|
|
211
219
|
|
|
212
220
|
it "will return false if there is no callback listening" do
|
|
221
|
+
fn = proc{}
|
|
222
|
+
object.bind :other_slot, &fn
|
|
223
|
+
result = object.trigger :slot
|
|
224
|
+
|
|
225
|
+
assert_equal false, result
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
it "will return false if there is no callback at all registered" do
|
|
213
229
|
result = object.trigger :slot
|
|
214
230
|
|
|
215
231
|
assert_equal false, result
|
|
216
232
|
end
|
|
217
233
|
end
|
|
234
|
+
|
|
235
|
+
describe "thread safety" do
|
|
236
|
+
it "is thread safe when unbinding while triggering" do
|
|
237
|
+
mutex = Mutex.new
|
|
238
|
+
result = []
|
|
239
|
+
|
|
240
|
+
procs = (0...5000).map {
|
|
241
|
+
proc{ mutex.synchronize{ result << 42 } }
|
|
242
|
+
}
|
|
243
|
+
procs.each{ |proc|
|
|
244
|
+
object.bind :slot, &proc
|
|
245
|
+
}
|
|
246
|
+
thread = Thread.new do
|
|
247
|
+
procs.each{ |proc|
|
|
248
|
+
object.unbind :slot, &proc
|
|
249
|
+
}
|
|
250
|
+
end
|
|
251
|
+
object.trigger :slot
|
|
252
|
+
thread.join
|
|
253
|
+
|
|
254
|
+
assert_equal 5000, result.size
|
|
255
|
+
end
|
|
256
|
+
end
|
|
218
257
|
end
|
metadata
CHANGED
|
@@ -1,37 +1,39 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: microevent
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jan Lelis
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-01-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: MicroEvent.rb is a event emitter library which provides the observer
|
|
14
|
-
pattern to Ruby objects. It is inspired by
|
|
14
|
+
pattern to Ruby objects. It is inspired by MicroEvent.js and implemented in less
|
|
15
15
|
than 20 lines of Ruby.
|
|
16
|
-
email:
|
|
16
|
+
email:
|
|
17
|
+
- hi@ruby.consulting
|
|
17
18
|
executables: []
|
|
18
19
|
extensions: []
|
|
19
20
|
extra_rdoc_files: []
|
|
20
21
|
files:
|
|
21
22
|
- ".gitignore"
|
|
22
|
-
- ".travis.yml"
|
|
23
23
|
- CHANGELOG.md
|
|
24
24
|
- Gemfile
|
|
25
25
|
- Gemfile.lock
|
|
26
26
|
- MIT-LICENSE.txt
|
|
27
27
|
- README.md
|
|
28
|
+
- Rakefile
|
|
28
29
|
- lib/microevent.rb
|
|
29
30
|
- microevent.gemspec
|
|
30
31
|
- spec/microevent_spec.rb
|
|
31
32
|
homepage: https://github.com/janlelis/microevent.rb
|
|
32
33
|
licenses:
|
|
33
34
|
- MIT
|
|
34
|
-
metadata:
|
|
35
|
+
metadata:
|
|
36
|
+
rubygems_mfa_required: 'true'
|
|
35
37
|
post_install_message:
|
|
36
38
|
rdoc_options: []
|
|
37
39
|
require_paths:
|
|
@@ -47,12 +49,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
47
49
|
- !ruby/object:Gem::Version
|
|
48
50
|
version: '0'
|
|
49
51
|
requirements: []
|
|
50
|
-
|
|
51
|
-
rubygems_version: 2.4.5
|
|
52
|
+
rubygems_version: 3.2.22
|
|
52
53
|
signing_key:
|
|
53
54
|
specification_version: 4
|
|
54
55
|
summary: MicroEvent.rb is a event emitter library which provides the observer pattern
|
|
55
56
|
to Ruby objects.
|
|
56
57
|
test_files:
|
|
57
58
|
- spec/microevent_spec.rb
|
|
58
|
-
has_rdoc:
|