ryardley / ts-bus

A lightweight JavaScript/TypeScript event bus to help manage your application architecture.
MIT License
136 stars 8 forks source link

Roadmap: Remove EventEmitter2 #12

Open ryardley opened 5 years ago

ryardley commented 5 years ago

Why?

dmicic commented 5 years ago

The subscription filtering syntax should be abstracted. At the moment, the bus is exposing the syntax of eventemitter2 lib directly to the developer. Replacing eventemitter2 would lead to breaking chances

ryardley commented 5 years ago

We don’t have to do this but what do you think about providing a predicate function as the main subscription filtering method and then writing a helper lib that uses a template literal tag function to process the wildcard syntax?

bus.subscribe(t`todos.**`, handler);
dmicic commented 5 years ago

Yes, that's what I meant by abstracting. E.g. turning the string into something that can be understood by eventemitter2 or in future extending/adapting to any other other pub/sub component.

But what would be nice actually is to have a type-safer way defining the subscriptions. E.g. I can provide a list of list of events that I am listening to etc. The nice thing about that is that I can easily follow references during code/design time and see where certain events are been "used". Maybe there is a nice way combining this with the string-based approach using string interpolation. Just thinking out loud.

ryardley commented 5 years ago

@dmicic Care to throw down a syntax proposal?