event_emitter 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ === 0.2.4 2013-03-21
2
+
3
+ * bugfix multiple once error
4
+
1
5
  === 0.2.3 2013-03-05
2
6
 
3
7
  * catch all events with "EventEmitter#on :*"
@@ -48,14 +48,17 @@ module EventEmitter
48
48
  case e[:type]
49
49
  when type.to_sym
50
50
  listener = e[:listener]
51
- remove_listener e[:id] if e[:params][:once]
51
+ e[:type] = nil if e[:params][:once]
52
52
  instance_exec(*data, &listener)
53
53
  when :*
54
54
  listener = e[:listener]
55
- remove_listener e[:id] if e[:params][:once]
55
+ e[:type] = nil if e[:params][:once]
56
56
  instance_exec(type, *data, &listener)
57
57
  end
58
58
  end
59
+ __events.each do |e|
60
+ remove_listener e[:id] unless e[:type]
61
+ end
59
62
  end
60
63
 
61
64
  def once(type, &block)
@@ -1,3 +1,3 @@
1
1
  module EventEmitter
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
@@ -103,8 +103,8 @@ class TestEventEmitter < MiniTest::Unit::TestCase
103
103
 
104
104
  def test_once
105
105
  total = 0
106
- @foo.once :add do |data|
107
- total += data
106
+ @foo.once :add do |num|
107
+ total += num
108
108
  end
109
109
 
110
110
  @foo.emit :add, 1
@@ -112,4 +112,32 @@ class TestEventEmitter < MiniTest::Unit::TestCase
112
112
  @foo.emit :add, 1
113
113
  assert total == 1, 'call listener only first time'
114
114
  end
115
+
116
+ def test_multiple_once
117
+ total = 0
118
+ @foo.on :add do |num|
119
+ total += num
120
+ end
121
+
122
+ @foo.once :add do |num|
123
+ total += num
124
+ end
125
+
126
+ @foo.once :add do |num|
127
+ total += num
128
+ end
129
+
130
+ @foo.once :add do |num|
131
+ total += num
132
+ end
133
+
134
+ @foo.once :add do |num|
135
+ total += num
136
+ end
137
+
138
+ @foo.emit :add, 1
139
+ assert total == 5, 'first call'
140
+ @foo.emit :add, 1
141
+ assert total == 6, 'call'
142
+ end
115
143
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_emitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-05 00:00:00.000000000 Z
12
+ date: 2013-03-20 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Ruby port of EventEmitter from Node.js
15
15
  email: