/* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #include "EventQueue.h" #include "EventEmitter.h" #include "ShadowNodeFamily.h" namespace facebook { namespace react { EventQueueProcessor::EventQueueProcessor( EventPipe eventPipe, StatePipe statePipe) : eventPipe_(std::move(eventPipe)), statePipe_(std::move(statePipe)) {} void EventQueueProcessor::flushEvents( jsi::Runtime &runtime, std::vector &&events) const { { std::lock_guard lock(EventEmitter::DispatchMutex()); for (const auto &event : events) { if (event.eventTarget) { event.eventTarget->retain(runtime); } } } for (const auto &event : events) { eventPipe_( runtime, event.eventTarget.get(), event.type, event.payloadFactory); } // No need to lock `EventEmitter::DispatchMutex()` here. // The mutex protects from a situation when the `instanceHandle` can be // deallocated during accessing, but that's impossible at this point because // we have a strong pointer to it. for (const auto &event : events) { if (event.eventTarget) { event.eventTarget->release(runtime); } } } void EventQueueProcessor::flushStateUpdates( std::vector &&states) const { for (const auto &stateUpdate : states) { statePipe_(stateUpdate); } } } // namespace react } // namespace facebook