UNPKG

1.91 kBtext/x-cView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#include "EventDispatcher.h"
9
10#include "BatchedEventQueue.h"
11#include "UnbatchedEventQueue.h"
12
13#define REACT_FABRIC_SYNC_EVENT_DISPATCHING_DISABLED
14
15namespace facebook {
16namespace react {
17
18EventDispatcher::EventDispatcher(
19 const EventPipe &eventPipe,
20 const EventBeatFactory &synchonousEventBeatFactory,
21 const EventBeatFactory &asynchonousEventBeatFactory) {
22 // Synchronous/Unbatched
23 eventQueues_[(int)EventPriority::SynchronousUnbatched] =
24 std::make_unique<UnbatchedEventQueue>(
25 eventPipe, synchonousEventBeatFactory());
26
27 // Synchronous/Batched
28 eventQueues_[(int)EventPriority::SynchronousBatched] =
29 std::make_unique<BatchedEventQueue>(
30 eventPipe, synchonousEventBeatFactory());
31
32 // Asynchronous/Unbatched
33 eventQueues_[(int)EventPriority::AsynchronousUnbatched] =
34 std::make_unique<UnbatchedEventQueue>(
35 eventPipe, asynchonousEventBeatFactory());
36
37 // Asynchronous/Batched
38 eventQueues_[(int)EventPriority::AsynchronousBatched] =
39 std::make_unique<BatchedEventQueue>(
40 eventPipe, asynchonousEventBeatFactory());
41}
42
43void EventDispatcher::dispatchEvent(
44 const RawEvent &rawEvent,
45 EventPriority priority) const {
46#ifdef REACT_FABRIC_SYNC_EVENT_DISPATCHING_DISABLED
47 // Synchronous dispatch works, but JavaScript interop layer does not have
48 // proper synchonization yet and it crashes.
49 if (priority == EventPriority::SynchronousUnbatched) {
50 priority = EventPriority::AsynchronousUnbatched;
51 }
52
53 if (priority == EventPriority::SynchronousBatched) {
54 priority = EventPriority::AsynchronousBatched;
55 }
56#endif
57
58 eventQueues_[(int)priority]->enqueueEvent(rawEvent);
59}
60
61} // namespace react
62} // namespace facebook