MVVM与网络请求

2020-10-21  本文已影响0人  凌云01

MVVM

MVVM.png

- (void)addObservers {
    @weakify(self);
    [IGCObserve(self.pipeline, ###) handle:^(id newValue) {
        @strongify(self);
        if ([newValue boolValue]) {
            self.pipeline.pageIndex = 1;
            [self fetchDataWithLoadMore:NO];
        }
    }];
}

addObservers

设置路由

#define COMPONENT_NAME @"igetcool://juvenile.dedao.live/chineseclass/liveclass/preview"

#pragma mark - IGCComponentRegisterProtocol
- (NSString *)componentName {
    return COMPONENT_NAME;
}

+ (NSDictionary<NSString *, IGCComponentConfig *> *)createComNameKeyAndComConfigObj {
    return @{COMPONENT_NAME: [IGCComponentConfig quickInitComponentWithViewModelClassName:NSStringFromClass([IGCPreviewViewModel class]) viewClassName:NSStringFromClass([IGCPreviewView class]) componentName:@"语文课学习资料预览列表页"]};
}

网络请求 IGCNetworking

[IGCNetworking sendRequest:^(XMRequest * _Nonnull request) {

}plugin:^(IGCNetworkingPlugin * _Nonnull plugin) {
    
} onSuccess:^(id  _Nullable responseObject, id  _Nullable model) {
   
 } onFailure:^(NSError * _Nullable error) {
    
} onFinished:^(id  _Nullable responseObject, NSError * _Nullable error) {
   
 }];

一、发起一个网络请求,采用默认插件

+ (NSString *)sendRequest:(XMRequestConfigBlock)configBlock
                onSuccess:(nullable IGCNetworkingSuccessBlock)successBlock
                onFailure:(nullable XMFailureBlock)failureBlock;

二、发起一个网络请求,采用默认插件

+ (NSString *)sendRequest:(XMRequestConfigBlock)configBlock
                onSuccess:(nullable IGCNetworkingSuccessBlock)successBlock
                onFailure:(nullable XMFailureBlock)failureBlock
               onFinished:(nullable XMFinishedBlock)finishedBlock;

三、发起一个网络请求,可定义插件

+ (NSString *)sendRequest:(XMRequestConfigBlock)configBlock
                   plugin:(nullable IGCNetworkingPluginBlock)pluginBlock
                onSuccess:(nullable IGCNetworkingSuccessBlock)successBlock
                onFailure:(nullable XMFailureBlock)failureBlock;

四、发起一个网络请求,可定义插件

+ (NSString *)sendRequest:(XMRequestConfigBlock)configBlock
                   plugin:(nullable IGCNetworkingPluginBlock)pluginBlock
                onSuccess:(nullable IGCNetworkingSuccessBlock)successBlock
                onFailure:(nullable XMFailureBlock)failureBlock
               onFinished:(nullable XMFinishedBlock)finishedBlock;

五、发起批量网络请求,可定义插件。

含有 成功,失败,完成的回调。
request:
完全由外部进行制定
plugin:
完全由外部制定

+ (nullable NSString *)sendBatchRequest:(XMBatchRequestConfigBlock)configBlock
                                plugins:(IGCNetworkingBatchPluginsBlock)pluginsBlock
                              onSuccess:(nullable IGCNetworkingBatchSuccessPluginsBlock)successBlock
                              onFailure:(nullable XMBCFailureBlock)failureBlock
                             onFinished:(nullable XMBCFinishedBlock)finishedBlock;

上一篇 下一篇

猜你喜欢

热点阅读