microevent 1.0.2 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fbf1f4dea535fbe569255678e4f67f0cd8e43020
4
- data.tar.gz: 4884dcaf58058a989850f79a02c7d5a3b8382aac
3
+ metadata.gz: ac30af2eb689ccc6201226879572337d52c9f688
4
+ data.tar.gz: f05995920b3c89d921477fb26eb08114cdcad381
5
5
  SHA512:
6
- metadata.gz: 7f0cb47876884449a46f952adf7eb35f7b1f57110d64f518e98952dbc509f17f702bb62b830b737deeb0cadb0c436fc187e11d6ed9d97f00c44993e6c979dd2a
7
- data.tar.gz: 2daea356bbbd803388a491855e39fa53f9e3f071d8379a5b01de9b6cc017cc8704113bea4977987caa30b6a599d910a08d594d9200e3301802fd58c6aaa0b485
6
+ metadata.gz: 11bd4332a8beda1045a8bf2cebc7dcd4f66c9bcb4e37a3ddcd0115141235f35086300cb015cc2753cc388564015c526f252ac2fc3ea8290f7ca31cb926c5c6d9
7
+ data.tar.gz: 9604ad8913e1447872d6e3137cf070dd8b06bdf3ea154f308159be2e2bca973fe3ff15de0f0293ff8d4aae62ef86d2ef229e8a9da56f8c702caf1edfc30df715
@@ -1,3 +1,10 @@
1
+ ## CHANGELOG
2
+
3
+ ### 1.1.0
4
+
5
+ * Only check if event store hash should be created on #bind, not on #unbind and #trigger
6
+
7
+
1
8
  ### 1.0.2
2
9
 
3
10
  * Dupping event array before triggering for better thread safety
@@ -1,5 +1,5 @@
1
1
  module MicroEvent
2
- VERSION = "1.0.2".freeze
2
+ VERSION = "1.1.0".freeze
3
3
 
4
4
  def bind(event, &fn)
5
5
  @_ ||= Hash.new{ |h,k| h[k] = [] }
@@ -7,12 +7,10 @@ module MicroEvent
7
7
  end
8
8
 
9
9
  def unbind(event, &fn)
10
- @_ ||= Hash.new{ |h,k| h[k] = [] }
11
- fn ? @_[event].delete(fn) : @_.delete(event) || []
10
+ fn ? @_ && @_[event].delete(fn) : @_ && @_.delete(event) || []
12
11
  end
13
12
 
14
13
  def trigger(event, *args)
15
- @_ ||= Hash.new{ |h,k| h[k] = [] }
16
- !@_[event].dup.each{ |fn| instance_exec(*args, &fn) }.empty?
14
+ !!@_ && !@_[event].dup.each{ |fn| instance_exec(*args, &fn) }.empty?
17
15
  end
18
16
  end
@@ -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,6 +218,14 @@ 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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: microevent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Lelis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-13 00:00:00.000000000 Z
11
+ date: 2015-03-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: MicroEvent.rb is a event emitter library which provides the observer
14
14
  pattern to Ruby objects. It is inspired by MicroEvent.js and implemented in less