GLD_ListViewModel.m
1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// GLD_ListViewModel.m
// YX_BaseProject
//
// Created by yiyangkeji on 2018/4/16.
// Copyright © 2018年 com.yxvzb. All rights reserved.
//
#import "GLD_ListViewModel.h"
#import "GLD_ListViewModelProtocol.h"
@interface GLD_ListViewModel ()
@property (nonatomic, assign)int page;
@property (nonatomic, strong)NSMutableArray *allData;
@property (nonatomic, strong)RACCommand *refreshCommand;
@property (nonatomic, strong)RACCommand *loadMoreCommand;
@end
@implementation GLD_ListViewModel
- (RACCommand *)refreshCommand{
if (!_refreshCommand) {
@weakify(self);
_refreshCommand = [[RACCommand alloc]initWithSignalBlock:^RACSignal *(id input) {
@strongify(self);
return [[self fetchDataWithPage:self.page] doNext:^(id x) {
self.page = 2;
[self.allData removeAllObjects];
[self.allData addObjectsFromArray:x];
}];
}];
}
return _refreshCommand;
}
- (RACCommand *)loadMoreCommand{
if (!_loadMoreCommand) {
@weakify(self);
_loadMoreCommand = [[RACCommand alloc]initWithSignalBlock:^RACSignal *(id input) {
@strongify(self);
return [[self fetchDataWithPage:self.page] doNext:^(id x) {
self.page += 1;
[self.allData addObjectsFromArray:x];
}];
}];
}
return _loadMoreCommand;
}
- (NSMutableArray *)allData{
if (_allData == nil) {
_allData = [NSMutableArray array];
}
return _allData;
}
- (RACSignal *)fetchDataWithPage:(int)page{
return [RACSignal empty];
}
@end