mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
82187bfb6b
Summary: ## Rationale For every 1 call to RCTNetworking.sendRequest, we execute 6 calls to RCTNetworking.addListener. This is followed by at least one call to RCTNetworking.removeListeners. Aside from incrementing and decrementing the `_listeners` integer, these two methods accomplish nothing else: RCTNetworking doesn't implement the `startObserving` and `stopObserving` methods. This diff makes RCTEventEmitter dispatch events without looking at the listeners integer. In the future, this will allow us to stop making these ~8 unnecessary NativeModule calls for every Network request we send. Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D24272560 fbshipit-source-id: 7996eba5abfa4669a89c43a3ffa536c0faa214a8
48 lines
1.3 KiB
Objective-C
48 lines
1.3 KiB
Objective-C
/*
|
|
* 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.
|
|
*/
|
|
|
|
#import <React/RCTBridge.h>
|
|
#import <React/RCTJSInvokerModule.h>
|
|
|
|
/**
|
|
* RCTEventEmitter is an abstract base class to be used for modules that emit
|
|
* events to be observed by JS.
|
|
*/
|
|
@interface RCTEventEmitter : NSObject <RCTBridgeModule, RCTJSInvokerModule, RCTInvalidating>
|
|
|
|
@property (nonatomic, weak) RCTBridge *bridge;
|
|
|
|
- (instancetype)initWithDisabledObservation;
|
|
|
|
/**
|
|
* Override this method to return an array of supported event names. Attempting
|
|
* to observe or send an event that isn't included in this list will result in
|
|
* an error.
|
|
*/
|
|
- (NSArray<NSString *> *)supportedEvents;
|
|
|
|
/**
|
|
* Send an event that does not relate to a specific view, e.g. a navigation
|
|
* or data update notification.
|
|
*/
|
|
- (void)sendEventWithName:(NSString *)name body:(id)body;
|
|
|
|
/**
|
|
* These methods will be called when the first observer is added and when the
|
|
* last observer is removed (or when dealloc is called), respectively. These
|
|
* should be overridden in your subclass in order to start/stop sending events.
|
|
*/
|
|
- (void)startObserving;
|
|
- (void)stopObserving;
|
|
|
|
- (void)invalidate NS_REQUIRES_SUPER;
|
|
|
|
- (void)addListener:(NSString *)eventName;
|
|
- (void)removeListeners:(double)count;
|
|
|
|
@end
|