Return last hook return value in Dispatcher#emit
This commit is contained in:
parent
7c440e28d2
commit
c69a600ca4
@ -16,7 +16,9 @@ module Uh
|
||||
end
|
||||
|
||||
def emit *key, args: []
|
||||
@hooks[translate_key key].each { |e| e.call *args }
|
||||
value = nil
|
||||
@hooks[translate_key key].each { |e| value = e.call *args }
|
||||
value
|
||||
end
|
||||
|
||||
|
||||
|
@ -45,6 +45,11 @@ module Uh
|
||||
expect { dispatcher.emit :hook_key }.to throw_symbol :hook_code
|
||||
end
|
||||
|
||||
it 'returns the value returned by a registered hook' do
|
||||
dispatcher.on(:hook_key) { :hook_code }
|
||||
expect(dispatcher.emit :hook_key).to eq :hook_code
|
||||
end
|
||||
|
||||
context 'when no hooks are registered for given key' do
|
||||
it 'does not call another hook' do
|
||||
dispatcher.on(:hook_key) { throw :hook_code }
|
||||
|
Loading…
x
Reference in New Issue
Block a user