Skip to content

Commit d86d718

Browse files
authored
Merge pull request Lightricks#37 from Lightricks/feature/racreplaysubject-trim-objects
RACReplaySubject: trim objects before -sendNext:.
2 parents 0ed36cb + 2506a1d commit d86d718

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

ReactiveObjC/RACReplaySubject.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ - (nullable RACDisposable *)subscribe:(id<RACSubscriber>)subscriber {
8585
- (void)sendNext:(id)value {
8686
@synchronized (self) {
8787
[self.valuesReceived addObject:value ?: RACTupleNil.tupleNil];
88-
[super sendNext:value];
89-
88+
9089
if (self.capacity != RACReplaySubjectUnlimitedCapacity && self.valuesReceived.count > self.capacity) {
9190
[self.valuesReceived removeObjectsInRange:NSMakeRange(0, self.valuesReceived.count - self.capacity)];
9291
}
92+
93+
[super sendNext:value];
9394
}
9495
}
9596

ReactiveObjCTests/RACSubjectSpec.m

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,27 @@ - (void)didSubscribeWithDisposable:(RACCompoundDisposable *)disposable {
186186

187187
expect(@(errorSent)).to(beTruthy());
188188
});
189+
190+
qck_it(@"should receive first values when using take: while in subscribeNext:", ^{
191+
id firstValue = @"blah";
192+
id secondValue = @"more blah";
193+
194+
NSMutableArray *outerValues = [NSMutableArray array];
195+
NSMutableArray *innerValues = [NSMutableArray array];
196+
197+
[subject subscribeNext:^(id outerValue) {
198+
[outerValues addObject:outerValue];
199+
[[subject take:1] subscribeNext:^(id innerValue) {
200+
[innerValues addObject:innerValue];
201+
}];
202+
}];
203+
204+
[subject sendNext:firstValue];
205+
[subject sendNext:secondValue];
206+
207+
expect(outerValues).to(equal(@[firstValue, secondValue]));
208+
expect(innerValues).to(equal(@[firstValue, secondValue]));
209+
});
189210
});
190211

191212
qck_describe(@"with an unlimited capacity", ^{
@@ -319,7 +340,7 @@ - (void)didSubscribeWithDisposable:(RACCompoundDisposable *)disposable {
319340
[subject sendNext:@1];
320341

321342
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
322-
__block RACDisposable *disposable = [subject subscribeNext:^(id x) {
343+
__block RACDisposable * _Nullable disposable = [subject subscribeNext:^(id x) {
323344
expect(disposable).notTo(beNil());
324345

325346
[values addObject:x];

0 commit comments

Comments
 (0)