Skip to content

Commit aa5b58b

Browse files
committed
modified chapter5's content
1 parent 478ad44 commit aa5b58b

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

chapter5/conclusion.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
- 函数式编程可在任何地方起作用
66
- 数据导入的代码,即使没有反应式代码,我们也能够使用`map:`和`filter:`来帮忙。在抽象方面,总觉得从未被实际实现。
77

8-
9-
- 为函数的副作用使用`subscribeNext:`
8+
9+
- 为函数的副作用使用`subscribeNext:`
1010
- `subscribeNext:`和其他类似的方法订阅信号的副作用,返回`RACDisposable`实例(这种实例将被传阅,直到信号完成被回收为止)
1111
为副作用使用这些方法---使得事物看起来像主动跟外界(一个没有反应式的世界)交互似的。
1212

@@ -21,4 +21,4 @@
2121

2222

2323
> BTY:函数副作用:指当调用函数时,除了返回函数值之外,还对主调用函数产生附加影响。例如修改全局变量或修改参数,一般而言函数副作用会给程序设计带来不必要的麻烦,使程序难以查找错误,并降低程序的可读性。严格的函数式语言要求函数必须无副作用。
24-
> 有一种特殊的情况,就是我们这里的函数。它的参数是一种In/Out作用的参数,即函数可能改变参数里面的内容,把一些信息通过输入参数,夹带到外界。这种情况,严格来说,也是副作用,是非纯函数。即我们所讨论的函数反应型编程中的函数式编程属于非纯函数,它是具有副作用的。
24+
> 有一种特殊的情况,就是我们这里的函数。它的参数是一种In/Out作用的参数,即函数可能改变参数里面的内容,把一些信息通过输入参数,夹带到外界。这种情况,严格来说,也是副作用,是非纯函数。即我们所讨论的函数反应型编程中的函数式编程属于非纯函数,它是具有副作用的。

chapter5/networking_layer_revisited.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
1818
+ (void)download:(NSString *)urlString withCompletion:(void (^)(NSData *data))completion {
1919
NSAssert(urlString, @"URL must not be nil");
20-
20+
2121
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
22-
[NSURLConnection sendAsynchronousRequest:request
23-
queue:[NSOperationQueue mainQueue]
22+
[NSURLConnection sendAsynchronousRequest:request
23+
queue:[NSOperationQueue mainQueue]
2424
completionHandler:
2525
^(NSURLResponse *response, NSData *data, NSError *connectionError) {
2626
if(completion) {
2727
completion(data);
28-
}
28+
}
2929
}];
3030
}
3131
@@ -43,10 +43,10 @@ Completion blocks?这是另外一个使用Signals的机会。更深入一点来
4343
4444
+ (RACSignal *)download:(NSString *)urlString {
4545
NSAssert(urlString , @"URL must not be nil");
46-
46+
4747
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString: urlString]];
48-
49-
return [[[NSURLConnection rac_sendAsynchronousRequest:request]
48+
49+
return [[[NSURLConnection rac_sendAsynchronousRequest:request]
5050
map:^id (RACTuple *value) {
5151
return [value second];
5252
}] deliverOn:[RACScheduler mainThreadScheduler]];
@@ -76,10 +76,10 @@ RAC(photoModel, thumbnailData) = [self download:photoModel.thumbnailURL];
7676
```
7777
+ (RACReplaySubject *)fetchPhotoDetails:(FRPPhotoModel *)photoModel {
7878
RACReplaySubject *subject = [RACReplaySubject subject];
79-
79+
8080
NSURLRequest *request = [self photoURLRequest:photoModel];
81-
[NSURLConnection sendAsynchronousRequest:request
82-
queue:[NSOperationQueue mainQueue]
81+
[NSURLConnection sendAsynchronousRequest:request
82+
queue:[NSOperationQueue mainQueue]
8383
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
8484
if(data) {
8585
id results = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil][@"photo"];
@@ -90,12 +90,12 @@ RAC(photoModel, thumbnailData) = [self download:photoModel.thumbnailURL];
9090
}
9191
else {
9292
[subject sendError:connectionError];
93-
}
93+
}
9494
}];
95-
96-
95+
96+
9797
return subject;
98-
98+
9999
}
100100
```
101101
@@ -105,13 +105,13 @@ RAC(photoModel, thumbnailData) = [self download:photoModel.thumbnailURL];
105105
```Objective-C
106106
+ (RACSignal *)fetchPhotoDetails:(FRPPhotoModel *)photoModel {
107107
NSURLRequest *request = [self photoURLRequest:photoModel];
108-
return [[[[[[NSURLConnection rac_sendAsynchronousRequest:request]
108+
return [[[[[[NSURLConnection rac_sendAsynchronousRequest:request]
109109
map:^id(RACTuple *value){
110110
return [value second];
111111
}]
112112
deliverOn:[RACScheduler mainThreadScheduler]]
113113
map:^id (NSData *data) {
114-
id results = [NSJSONSerialization JSONObjectWithData:data
114+
id results = [NSJSONSerialization JSONObjectWithData:data
115115
options:0 error:nil][@"photo"];
116116
[self configurePhotoModel:photoModel withDictionary:results];
117117
[self downloadFullsizedImageForPhotoModel:photoModel];
@@ -127,7 +127,7 @@ RAC(photoModel, thumbnailData) = [self download:photoModel.thumbnailURL];
127127

128128
我们已经知道`deliverOn:`是怎样工作的,所以让我们来关注信号链条最末端的信号操作`publish`. `publish`返回一个`RACMulitcastConnection`,当信号连接上时,他将订阅该接收信号。`autoconnect`为我们做的是:当它返回的信号被订阅,连接到
129129
该(订阅背后的)信号(underly signal)。
130-
130+
131131
执行获取每一个订阅,在订阅的时候,我们返回的信号将会变“冷”。那是因为我们对底层信号进行多播,网络请求只会执行一次,但是它的结果被多播。这会导致:网络信号将只会被执行一次(当它被订阅时执行),是冷的(直到订阅为止,它不会被执行),甚至可删除的(如果一次性处理订阅的生成)。
132132

133133
基本上,我们能保证信号只会被订阅一次,我们不需要回滚(replay).
@@ -145,15 +145,15 @@ reduceEach:^id(NSURLResponse *response, NSData *data) {
145145
```
146146
+ (RACSignal *)importPhotos {
147147
NSURLRequest *request = [self popularURLRequest];
148-
149-
return [[[[[[NSURLConnection rac_sendAsynchronousRequest:request]
148+
149+
return [[[[[[NSURLConnection rac_sendAsynchronousRequest:request]
150150
reduceEach:^id(NSURLResponse *response , NSData *data){
151151
return data;
152-
}]
153-
deliverOn:[RACScheduler mainThreadScheduler]]
152+
}]
153+
deliverOn:[RACScheduler mainThreadScheduler]]
154154
map:^id (NSData *data) {
155155
id results = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
156-
return [[[results[@"photo"] rac_sequence]
156+
return [[[results[@"photo"] rac_sequence]
157157
map:^id (NSDictionary *photoDictionary) {
158158
FRPPhotoModel *model = [FRPPhotoModel new];
159159
[self configurePhotoModel:model withDictionary:photoDictionary];

chapter5/revisiting_functionalReactivePixels.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ RAC(self, photosArray) = [[[[FRPPhotoImporter importPhotos]
9898
9999
- (void)perpareForReuse {
100100
[super perpareForReuse];
101-
101+
102102
[self.subscription dispose], self.subscription = nil;
103103
}
104104
@@ -131,7 +131,7 @@ RAC(self, photosArray) = [[[[FRPPhotoImporter importPhotos]
131131

132132
```Objective-C
133133

134-
RAC(self.imageView, image) = [[RACObserve(self, photoModel.thumbnailData) ignore:nil]
134+
RAC(self.imageView, image) = [[RACObserve(self, photoModel.thumbnailData) ignore:nil]
135135
map:^(NSData *data){
136136
return [UIImage imageWithData:data];
137137
}];

0 commit comments

Comments
 (0)