YH_ModuleData.h 2.07 KB
//
//  YH_ModuleData.h
//  YH_WatchDog
//
//  Created by redding on 16/3/7.
//  Copyright © 2016年 YOHO. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol YH_BridgeModule;
@protocol YH_BridgeService;

@class YH_WatchDog;

@interface YH_ModuleData : NSObject

- (instancetype)init NS_UNAVAILABLE;

- (instancetype)initWithModuleClass:(Class)moduleClass bridge:(YH_WatchDog *)bridge NS_DESIGNATED_INITIALIZER;

- (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.
 */
- (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.
 */
- (void)finishSetupForInstance;

@property (nonatomic, strong, readonly) Class moduleClass;
@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.
 */
@property (nonatomic, copy, readonly) NSDictionary<NSString *, id<YH_BridgeService>> *services;

/**
 * Returns YES if module instance has already been initialized; NO otherwise.
 */
@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.
 */
@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.
 */
@property (nonatomic, strong, readonly) dispatch_queue_t serviceQueue;

- (NSString *)debugDescription;

@end