Support event hook arguments in Dispatcher
This commit is contained in:
parent
520a0c87c9
commit
7b9854b499
@ -15,8 +15,8 @@ module Uh
|
|||||||
@hooks[translate_key key] << block
|
@hooks[translate_key key] << block
|
||||||
end
|
end
|
||||||
|
|
||||||
def emit *key
|
def emit *key, args: []
|
||||||
@hooks[translate_key key].each { |e| e.call }
|
@hooks[translate_key key].each { |e| e.call *args }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,6 +57,14 @@ module Uh
|
|||||||
expect { dispatcher.emit :hook_key }.not_to raise_error
|
expect { dispatcher.emit :hook_key }.not_to raise_error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when args keyword argument is given' do
|
||||||
|
it 'calls hooks with given args' do
|
||||||
|
dispatcher.on(:hook_key) { |arg1, arg2| throw arg2 }
|
||||||
|
expect { dispatcher.emit :hook_key, args: %i[arg1 arg2] }
|
||||||
|
.to throw_symbol :arg2
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user