Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #10 from gavrix/flush_signal
Browse files Browse the repository at this point in the history
Flush signal property implementation
  • Loading branch information
gavrix committed Mar 12, 2015
2 parents 71d02ab + fa656f9 commit 00da1fb
Show file tree
Hide file tree
Showing 7 changed files with 585 additions and 1,201 deletions.
3 changes: 1 addition & 2 deletions TableViewReactiveAdapter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ Pod::Spec.new do |s|
s.license = { :type => 'MIT' }
s.author = { "Sergey Gavrilyuk" => "[email protected]" }
s.platform = :ios, "6.0"
s.source = { :git => "https://github.com/gavrix/TableViewReactiveAdapter.git", :tag => "0.0.1" }
s.source = { :git => "https://github.com/gavrix/TableViewReactiveAdapter.git", :tag => "0.0.2" }
s.source_files = 'TableViewReactiveAdapter/TableViewReactiveAdapter/*.{h,m}'
s.requires_arc = true

s.dependency 'ReactiveCocoa', '~> 2'
s.dependency 'libextobjc', '0.3'

end
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
- (instancetype)initWithTableView:(UITableView *)tableView
withInitialState:(NSArray *)array;


/// Subscriber for UITableView source events. Can be used for RACSignal to subscribe to.
- (id<RACSubscriber>)sourceEventsSubscriber;

Expand Down Expand Up @@ -100,4 +101,10 @@
/// Upon initialization, this property is automatically set to whatever UITableView instance had before.
@property (nonatomic, weak) id<UITableViewDataSource> dataSource;

/// TableViewReactiveAdapter flush signal
///
/// @discussion sends this SRGTableViewReactiveAdapter instance everytime update events get flushed
/// into managed UITableView
@property (nonatomic, readonly) RACSignal *flushSignal;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

#import "SRGTableViewReactiveAdapter.h"
#import <libextobjc/extobjc.h>
#import <objc/runtime.h>

typedef NS_ENUM(NSUInteger, SRGContentModificationEventType) {
SRGInsertRows,
Expand Down Expand Up @@ -182,7 +182,6 @@ - (instancetype)initWithInitialState:(NSArray *)tableViewSource {
[self initInitialState:tableViewSource];
_deleteIndexPaths = [NSMutableArray array];
_deletedSections = [NSMutableIndexSet indexSet];

}
return self;
}
Expand Down Expand Up @@ -259,28 +258,32 @@ @interface SRGTableViewReactiveAdapter ()
@property (nonatomic) SRGTableViewIntermediateState *intermediateState;
@end

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wprotocol"

@implementation SRGTableViewReactiveAdapter

- (instancetype)initWithTableView:(UITableView *)tableView
withInitialState:(NSArray *)array {
self = [super init];
if (self) {
self.tableView = tableView;

self.dataSource = self.tableView.dataSource;
self.tableView.dataSource = self;
[self _setTableView:tableView];

@weakify(self)
self.flushCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
@strongify(self)
[self processTableViewFlush];
// since flushCommand has concurrentExecution turned off, this delay will
// ensure flush is performed not more frequent than this delay. (so tableView can finish it's animations safely)
[[RACScheduler mainThreadScheduler] afterDelay:.33 schedule:^{
RACDisposable *disposable = [[RACScheduler mainThreadScheduler] afterDelay:1.33 schedule:^{
[subscriber sendCompleted];
}];
return nil;
return disposable;
}];
}];

self.sourceEventsSignal = [RACSubject subject];

NSMutableArray *arr = [NSMutableArray array];
Expand All @@ -294,6 +297,13 @@ - (instancetype)initWithTableView:(UITableView *)tableView
return self;
}

- (void)_setTableView:(UITableView *)tableView {
self.tableView = tableView;

self.dataSource = self.tableView.dataSource;
self.tableView.dataSource = self;
}

- (void)initRelations {

RACSignal *allEventsSignal = [self.sourceEventsSignal filter:^BOOL(SRGTableViewContentModificationEvent *value) {
Expand Down Expand Up @@ -327,8 +337,12 @@ - (void)initRelations {
return event.eventType == SRGDeleteRows;
}], nil];


[self.flushCommand rac_liftSelector:@selector(execute:) withSignals:[allEventsSignal logNext], nil];
RACSignal *executing = self.flushCommand.executing;

[self.flushCommand rac_liftSelector:@selector(execute:) withSignals:
[allEventsSignal map: ^id (id event) {
return [[[executing ignore:@YES] take:1] mapReplace:event];
}].switchToLatest, nil];
}


Expand Down Expand Up @@ -383,6 +397,14 @@ - (void)processTableViewFlush {
return self.sourceEventsSignal;
}

- (RACSignal *)flushSignal {
@weakify(self)
return [self.flushCommand.executionSignals map:^id(RACSignal *flushSignal) {
@strongify(self)
return [flushSignal.ignoreValues concat:[RACSignal return:self]];
}].switchToLatest;
}


#pragma mark - UITableViewDataSource

Expand Down Expand Up @@ -432,3 +454,4 @@ - (id)forwardingTargetForSelector:(SEL)aSelector {
}

@end
#pragma clang diagnostic pop
2 changes: 1 addition & 1 deletion TableViewReactiveAdapterDemo/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
platform :ios, '7.0'
inhibit_all_warnings!

pod 'TableViewReactiveAdapter', :path=> '../TableViewReactiveAdapter'
pod 'TableViewReactiveAdapter', :path=> '../'

113 changes: 13 additions & 100 deletions TableViewReactiveAdapterDemo/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,110 +1,23 @@
PODS:
- libextobjc (0.3):
- libextobjc/EXTADT
- libextobjc/EXTAnnotation
- libextobjc/EXTAspect
- libextobjc/EXTBlockMethod
- libextobjc/EXTBlockTarget
- libextobjc/EXTConcreteProtocol
- libextobjc/EXTDispatchObject
- libextobjc/EXTFinalMethod
- libextobjc/EXTKeyPathCoding
- libextobjc/EXTMaybe
- libextobjc/EXTMixin
- libextobjc/EXTMultimethod
- libextobjc/EXTMultiObject
- libextobjc/EXTNil
- libextobjc/EXTPassthrough
- libextobjc/EXTPrivateMethod
- libextobjc/EXTProtocolCategory
- libextobjc/EXTSafeCategory
- libextobjc/EXTScope
- libextobjc/EXTSelectorChecking
- libextobjc/EXTSwizzle
- libextobjc/EXTSynthesize
- libextobjc/EXTTuple
- libextobjc/EXTVarargs
- libextobjc/NSInvocation+EXT
- libextobjc/NSMethodSignature+EXT
- libextobjc/RuntimeExtensions
- libextobjc/UmbrellaHeader
- libextobjc/EXTADT (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTAnnotation (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTAspect (0.3):
- libextobjc/RuntimeExtensions
- libffi
- libextobjc/EXTBlockMethod (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTBlockTarget (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTConcreteProtocol (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTDispatchObject (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTFinalMethod (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTKeyPathCoding (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTMaybe (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTMixin (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTMultimethod (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTMultiObject (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTNil (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTPassthrough (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTPrivateMethod (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTProtocolCategory (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTSafeCategory (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTScope (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTSelectorChecking (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTSwizzle (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTSynthesize (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTTuple (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/EXTVarargs (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/NSInvocation+EXT (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/NSMethodSignature+EXT (0.3):
- libextobjc/RuntimeExtensions
- libextobjc/RuntimeExtensions (0.3)
- libextobjc/UmbrellaHeader (0.3)
- libffi (3.0.13)
- ReactiveCocoa (2.1.8):
- ReactiveCocoa/Core
- ReactiveCocoa/no-arc
- ReactiveCocoa/Core (2.1.8):
- ReactiveCocoa (2.4.7):
- ReactiveCocoa/UI (= 2.4.7)
- ReactiveCocoa/Core (2.4.7):
- ReactiveCocoa/no-arc
- ReactiveCocoa/no-arc (2.1.8)
- TableViewReactiveAdapter (0.0.1):
- libextobjc (= 0.3)
- ReactiveCocoa (~> 2.1.8)
- ReactiveCocoa/no-arc (2.4.7)
- ReactiveCocoa/UI (2.4.7):
- ReactiveCocoa/Core
- TableViewReactiveAdapter (0.0.2):
- ReactiveCocoa (~> 2)

DEPENDENCIES:
- TableViewReactiveAdapter (from `../TableViewReactiveAdapter`)
- TableViewReactiveAdapter (from `../`)

EXTERNAL SOURCES:
TableViewReactiveAdapter:
:path: ../TableViewReactiveAdapter
:path: ../

SPEC CHECKSUMS:
libextobjc: 820a79dbbbc498611e04fffd07d2d52a5588e7ac
libffi: 64ef39353e747bb2b25e1026afd96a157bf9231c
ReactiveCocoa: 0db710a0afa1c627a64470e5c912a3870d4854ae
TableViewReactiveAdapter: 80fbcc34521fef2e5df7a7d73aee958b587d9686
ReactiveCocoa: 313fc53cc9aeb2bbbc3f5f13c7eac16478d9af8f
TableViewReactiveAdapter: 5ba380334fdb2125bfb478c8ccf4afe9a585a037

COCOAPODS: 0.28.0
COCOAPODS: 0.35.0
Loading

0 comments on commit 00da1fb

Please sign in to comment.