gocanto/vuemit

[feature] use a wildcard for events name

Closed this issue ยท 8 comments

ctf0 commented

i found vuejs/vue#230 (comment), but not sure how to implement it with the vuemeit, however maybe we can have an internal check for something like

EventHub.listen('*', (data)=>{
    // do something
})

which essentially use regex to catch events name.

ctf0 commented

am sorry for not correctly explaining what am after, ex.

EventHub.fire('pub-foo', data)
EventHub.fire('pub-bar', data)

// now we want one listener for all events name of "pub-*"
EventHub.listen('pub-*', callback)
{
     // do something
}

however atm the listen method wont work because it needs an absolute name of the event not a pattern, so maybe

listen(event, callback)
{
    if (event.indexOf('*')) {
        // this is a pattern
    }

    this.vue.$on(event, callback);
}

Can you point me out to this option in the Vue js doc? I haven't been able to play with Vue for a while now. Been really busy!

I might be able to pull this off :)

ctf0 commented

actually its not in the docs, only where i could find this were vuejs/vue#230 (comment)

Ok, let me take a look at it and see what I can do.

Have you checked if this work properly?

I am kinda busy at the moment and have not had time to check on this.

If you find it useful and wanna PR for it, I will merge it.

ctf0 commented

its okay np, will see what i can do ๐Ÿ‘

ctf0 commented

i think with the events name array, we dont need this one, as it will make it harder to test it and/or to reason about.