15 #ifndef SHAKA_EMBEDDED_JS_EVENTS_EVENT_TARGET_H_ 16 #define SHAKA_EMBEDDED_JS_EVENTS_EVENT_TARGET_H_ 21 #include <unordered_map> 98 bool* did_listeners_throw);
107 template <
typename EventType,
typename... Args>
115 if (holds_alternative<bool>(val)) {
116 return get<bool>(val);
118 LocalVar<JsValue> except = get<js::JsError>(val).error();
119 LOG(INFO) <<
"Exception thrown while raising event: " 130 template <
typename EventType,
typename... Args>
139 on_listeners_[
to_string(type)] = on_field;
143 struct ListenerInfo {
144 ListenerInfo(
Listener listener,
const std::string& type);
153 void InvokeListeners(
RefPtr<Event> event,
bool* did_listeners_throw);
156 std::list<ListenerInfo>::iterator FindListener(
const Listener& callback,
157 const std::string& type);
159 std::unordered_map<std::string, std::function<void()>> cpp_listeners_;
164 std::list<ListenerInfo> listeners_;
166 std::unordered_map<std::string, Listener*> on_listeners_;
167 bool is_dispatching_;
179 #endif // SHAKA_EMBEDDED_JS_EVENTS_EVENT_TARGET_H_
ExceptionOr< bool > DispatchEventInternal(RefPtr< Event > event, bool *did_listeners_throw)
ExceptionOr< bool > RaiseEvent(Args... args)
void RemoveEventListener(const std::string &type, Listener callback)
void UnsetCppEventListener(EventType type)
static JsManagerImpl * Instance()
void Trace(memory::HeapTracer *tracer) const override
std::shared_ptr< ThreadEvent< impl::RetOf< Func > > > AddInternalTask(TaskPriority priority, const std::string &name, Func &&callback)
ExceptionOr< bool > DispatchEvent(RefPtr< Event > event)
void AddEventListener(const std::string &type, Listener callback)
std::string ConvertToString(Handle< JsValue > value)
void SetCppEventListener(EventType type, std::function< void()> callback)
std::shared_ptr< ThreadEvent< bool > > ScheduleEvent(Args &&... args)
void AddListenerField(EventType type, Listener *on_field)
TaskRunner * MainThread()