Authored by 于良

更新注释

... ... @@ -35,10 +35,11 @@ extern NSString * const YH_CallServiceObserverKey;
@protocol YH_BridgeModule <NSObject>
/**
* Place this macro in your class implementation to automatically register
* your module with the bridge when it loads. The optional js_name argument
* will be used as the JS module name. If omitted, the JS module name will
* match the Objective-C class name.
*
* 用于将module自动注册到bridge
* 注册的动作发生在module class被load的时
* export_name 注册的module名称,若不指定则使用module class名称的字符串表示
*
*/
#define YH_EXPORT_MODULE(export_name) \
extern void YH_RegisterModule(Class); \
... ... @@ -51,38 +52,38 @@ extern void YH_RegisterModule(Class); \
@optional
/**
* A reference to the YH_WatchDog. Useful for modules that require access
* to bridge features, such as sending events or making service calls. This
* will be set automatically by the bridge when it initializes the module.
* To implement this in your module, just add `@synthesize bridge = _bridge;`
*
* 指向YH_WatchDog的引用
* 用于发起module提供的service调用
* module初始化时自动设置
* 如果需要在创建的module中使用,在module实现中加上`@synthesize bridge = _bridge;`即可
*
*/
@property (nonatomic, weak, readonly) YH_WatchDog *bridge;
/**
* The queue that will be used to call all exported methods. If omitted, this
* will call on a default background queue, which is avoids blocking the main
* thread.
*
* If the methods in your module need to interact with UIKit methods, they will
* probably need to call those on the main thread, as most of UIKit is main-
* thread-only. You can tell React Native to call your module methods on the
* main thread by returning a reference to the main queue, like this:
* 调用service时使用的队列。若不指定则在默认的后台队列调用,这样不会阻塞主线程
* 如果需要指定module服务调用所在队列,可以如下实现:
*
* - (dispatch_queue_t)methodQueue
* {
* return dispatch_get_main_queue();
* }
*
* If you don't want to specify the queue yourself, but you need to use it
* inside your class (e.g. if you have internal methods that need to dispatch
* onto that queue), you can just add `@synthesize methodQueue = _methodQueue;`
* and the bridge will populate the methodQueue property for you automatically
* when it initializes the module.
* 如果不想指定队列,但又需要在module中使用,在module实现中添加 `@synthesize methodQueue = _methodQueue;`
* methodQueue property会在module初始化时自动设置
*
*/
@property (nonatomic, strong, readonly) dispatch_queue_t serviceQueue;
/**
* Export service without operation queue
* 注册没有operation queue支持的service
* 此时调用service时步骤:
* 1.调用service
* 2.封装生成NSInvocation调用
* 3.调用NSInvocation
*
* eg:
* YH_EXPORT_SERVICE(login) {...}
* |
... ... @@ -101,7 +102,7 @@ extern void YH_RegisterModule(Class); \
YH_REMAP_SERVICE(service, YH_CONCAT_SERVICE_NAME(service))
/**
* Translate service method name from service name
* 根据service名称拼接出service方法的名称
*
* eg:
* YH_CONCAT_SERVICE_NAME(login)
... ... @@ -115,10 +116,12 @@ YH_CONCAT(service, Service:(NSDictionary *)parameters)
/**
* Similar to YH_EXPORT_SERVICE but lets you set the name of the exported
* service. Example usage:
* export_name service名称
* service service方法名称
*
* YH_REMAP_SERVICE(login)
* Example usage:
*
* YH_REMAP_SERVICE(login, loginService:(NSDictionary *)parameters)
* { ... }
*/
#define YH_REMAP_SERVICE(export_name, service) \
... ... @@ -134,6 +137,13 @@ return @[@#export_name, @#service]; \
/**
* Export service with operation queue
* 注册有operation queue支持的service
* 此时调用service时步骤:
* 1.调用service
* 2.service调用放入队列
* 3.封装生成NSInvocation调用
* 4.调用NSInvocation
*
* eg:
* YH_EXPORT_SERVICE_WITH_QUEUE(login) {...}
* |
... ... @@ -164,7 +174,8 @@ YH_REMAP_SERVICE(service, YH_CONCAT_SERVICE_NAME(service))
/**
* Service queue getter and setter
* 生成Service调用所用queue的getter和setter
*
* eg:
* YH_EXTERN_SERVICE_QUEUE(login)
* |
... ... @@ -190,7 +201,8 @@ static char YH_SERVICE_QUEUE_KEY(service); \
/**
* Declare service callback signal
* 声明用于回调service结果的signal
*
* eg:
* YH_DECLARE_SIGNAL_PROPERTY(login, Dictionary)
* |
... ... @@ -203,7 +215,8 @@ static char YH_SERVICE_QUEUE_KEY(service); \
/**
* Init service callback signal
* 初始化用于回调service结果的signal
*
* eg:
* YH_INIT_SIGNAL_PROPERTY(login, type)
* |
... ...
... ... @@ -22,16 +22,14 @@
- (instancetype)initWithModuleInstance:(id<YH_BridgeModule>)instance bridge:(YH_WatchDog *)bridge;
/**
* Sets the bridge for the module instance. This is only needed when using the
* `initWithModuleInstance:bridge:` constructor. Otherwise, the bridge will be set
* automatically when the module is first accessed.
* 设置module的bridge实例
* 此方法只会在使用`initWithModuleInstance:bridge:`时调用,否则bridge会在module第一次访问时调用。
*/
- (void)setBridgeForInstance;
/**
* Sets the methodQueue and performs the remaining setup for the module. This is
* only needed when using the `initWithModuleInstance:bridge:` constructor.
* Otherwise it will be done automatically when the module is first accessed.
* 设置module的methodQueue实例,并执行未完成的初始化工作
* 此方法只会在使用`initWithModuleInstance:bridge:`时调用,否则bridge会在module第一次访问时调用。
*/
- (void)finishSetupForInstance;
... ... @@ -39,26 +37,27 @@
@property (nonatomic, copy, readonly) NSString *name;
/**
* Returns the module services. Note that this will gather the services the first
* time it is called and then memoize the results.
* 返回module所有的service
* 采用懒加载方式,第一次调用getter时获取module所有的service
*/
@property (nonatomic, copy, readonly) NSDictionary<NSString *, id<YH_BridgeService>> *services;
/**
* Returns YES if module instance has already been initialized; NO otherwise.
* 如果module实例已经初始化好了,返回YES;否则返回NO
*/
@property (nonatomic, assign, readonly) BOOL hasInstance;
/**
* Returns the current module instance. Note that this will init the instance
* if it has not already been created. To check if the module instance exists
* without causing it to be created, use `hasInstance` instead.
* 返回当前的module实例
* 采用懒加载的方式,第一次调用getter时创建引用
* 如果要在不触发module实例创建时,检查module实例是否已创建,使用`hasInstance`方法
*/
@property (nonatomic, strong, readonly) id<YH_BridgeModule> instance;
/**
* Returns the module method dispatch queue. Note that this will init both the
* queue and the module itself if they have not already been created.
* 返回module method dispatch queue
* 采用懒加载的方式,第一次调用getter时创建引用
* 注意创建serviceQueue引用时会同时创建module自身的引用
*/
@property (nonatomic, strong, readonly) dispatch_queue_t serviceQueue;
... ...