mirror of
https://github.com/gelldur/EventBus.git
synced 2025-01-14 01:07:59 +08:00
Improve Event::Collector::getBus
Some of people make such thing: listener.getBus().listen<T>()... And they thought that listening with our listener. So need to fix bad conceptual mistake.
This commit is contained in:
parent
951d3f1e42
commit
3ddb5ac7c5
@ -11,6 +11,29 @@
|
||||
namespace Dexode
|
||||
{
|
||||
|
||||
class BusAttorney
|
||||
{
|
||||
public:
|
||||
BusAttorney(std::shared_ptr<EventBus> bus)
|
||||
: _bus(std::move(bus))
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify all listeners for event
|
||||
*
|
||||
* @param event your event struct
|
||||
*/
|
||||
template<typename Event>
|
||||
void notify(const Event& event)
|
||||
{
|
||||
_bus->notify(event);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<EventBus> _bus;
|
||||
};
|
||||
|
||||
class EventCollector
|
||||
{
|
||||
public:
|
||||
@ -61,7 +84,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
const std::shared_ptr<EventBus>& getBus() const;
|
||||
bool isUsing(const std::shared_ptr<EventBus>& bus) const;
|
||||
|
||||
///I wan't explicitly say getBus. Ok we could add method for notify but this is more explicit
|
||||
BusAttorney getBus() const;
|
||||
|
||||
private:
|
||||
int _token = 0;
|
||||
|
@ -86,9 +86,14 @@ void EventCollector::unlistenAll()
|
||||
}
|
||||
}
|
||||
|
||||
const std::shared_ptr<EventBus>& EventCollector::getBus() const
|
||||
BusAttorney EventCollector::getBus() const
|
||||
{
|
||||
return _bus;
|
||||
return BusAttorney{_bus};
|
||||
}
|
||||
|
||||
bool EventCollector::isUsing(const std::shared_ptr<EventBus>& bus) const
|
||||
{
|
||||
return _bus == bus;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user