mirror of
https://github.com/vlang/v.git
synced 2025-09-09 07:15:50 -04:00
eventbus: V ui on_key_down fix
This commit is contained in:
parent
ff452cc514
commit
551a065ce6
@ -47,13 +47,13 @@ pub fn new[T]() &EventBus[T] {
|
||||
return &EventBus[T]{registry, &Publisher[T]{registry}, &Subscriber[T]{registry}}
|
||||
}
|
||||
|
||||
// publish publish an event with provided Params & name.
|
||||
// publish publishes an event with provided Params & name.
|
||||
pub fn (eb &EventBus[T]) publish(name T, sender voidptr, args voidptr) {
|
||||
mut publisher := eb.publisher
|
||||
publisher.publish(name, sender, args)
|
||||
}
|
||||
|
||||
// clear_all clear all subscribers.
|
||||
// clear_all clears all subscribers.
|
||||
pub fn (eb &EventBus[T]) clear_all() {
|
||||
mut publisher := eb.publisher
|
||||
publisher.clear_all()
|
||||
@ -66,9 +66,22 @@ pub fn (eb &EventBus[T]) has_subscriber(name T) bool {
|
||||
|
||||
// publish publish an event with provided Params & name.
|
||||
fn (mut pb Publisher[T]) publish(name T, sender voidptr, args voidptr) {
|
||||
for event in pb.registry.events {
|
||||
// println('Publisher.publish(name=${name} sender=${sender} args=${args})')
|
||||
mut handled_receivers := [20]voidptr{} // handle duplicate bugs TODO fix properly + perf
|
||||
// is_key_down := name == 'on_key_down'
|
||||
mut j := 0
|
||||
for i, event in pb.registry.events {
|
||||
if event.name == name {
|
||||
// if is_key_down {
|
||||
if event.receiver in handled_receivers {
|
||||
continue
|
||||
}
|
||||
//}
|
||||
// println('got ${i + 1} name=${name} event.receiver=${event.receiver}')
|
||||
event.handler(event.receiver, args, sender)
|
||||
// handled_receivers << event.receiver
|
||||
handled_receivers[j] = event.receiver
|
||||
j++
|
||||
}
|
||||
}
|
||||
pb.registry.events = pb.registry.events.filter(!(it.name == name && it.once))
|
||||
|
Loading…
x
Reference in New Issue
Block a user