Skip to content

Commit

Permalink
eventbus: V ui on_key_down fix
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Sep 18, 2023
1 parent ff452cc commit 551a065
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions vlib/eventbus/eventbus.v
Expand Up @@ -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()
Expand 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))
Expand Down

0 comments on commit 551a065

Please sign in to comment.