Skip to content

Commit 37e8192

Browse files
committed
Initial commit
0 parents  commit 37e8192

19 files changed

+867
-0
lines changed

LICENSE

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright (c) 2012-2014, Kyle Fuller
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
13+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23+

README.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
ReactiveQueryKit
2+
================
3+
4+
ReactiveCocoa extensions for QueryKit. Currently it only supports the
5+
Objective-C variant of QueryKit and ReactiveCocoa. Once ReactiveCocoa 3.0 comes
6+
out we will implement a native Swift version using ReactiveCocoa 3.0.
7+
8+
## Usage
9+
10+
### Query Set
11+
12+
ReactiveQueryKit extends QueryKit and provides methods to evaluate and execute
13+
operations as Signals.
14+
15+
#### Count
16+
17+
```objective-c
18+
[[queryset count] subscribeNext:^(NSNumber *count) {
19+
NSLog(@"QuerySet count has been updated %@", count);
20+
}];
21+
```
22+
23+
#### Objects
24+
25+
```objective-c
26+
[[queryset objects] subscribeNext:^(NSArray *objects) {
27+
NSLog(@"QuerySet objects has been updated %@", objects);
28+
}];
29+
```
30+
31+
### NSManagedObjectContext
32+
33+
We have also extended NSManagedObjectContext providing a bunch of signals.
34+
35+
```objective-c
36+
@interface NSManagedObjectContext (ReactiveQueryKit)
37+
38+
/// Returns a signal that sends the NSNotification for
39+
NSManagedObjectContextObjectsDidChangeNotification in the current context
40+
- (RACSignal *)rqk_objectsDidChangeSignal;
41+
42+
/// Returns a signal that sends the NSNotification for
43+
NSManagedObjectContextWillSaveNotification in the current context
44+
- (RACSignal *)rqk_willSaveSignal;
45+
46+
/// Returns a signal that sends the NSNotification for
47+
NSManagedObjectContextDidSaveNotification in the current context
48+
- (RACSignal *)rqk_didSaveSignal;
49+
50+
@end
51+
```
52+
53+
## Installation
54+
55+
[CocoaPods](http://cocoapods.org) is the recommended way to add
56+
ReactiveQueryKit to your project.
57+
58+
```ruby
59+
pod 'ReactiveQueryKit', :git => 'https://github.com/QueryKit/ReactiveQueryKit'
60+
```
61+
62+
## License
63+
64+
QueryKit is released under the BSD license. See [LICENSE](LICENSE).
65+

ReactiveQueryKit.podspec

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Pod::Spec.new do |spec|
2+
spec.name = 'ReactiveQueryKit'
3+
spec.version = '0.1.0'
4+
spec.summary = 'ReactiveCocoa extensions for QueryKit.'
5+
spec.homepage = 'http://querykit.org/'
6+
spec.license = { :type => 'BSD', :file => 'LICENSE' }
7+
spec.author = { 'Kyle Fuller' => '[email protected]' }
8+
spec.social_media_url = 'http://twitter.com/QueryKit'
9+
spec.source = { :git => 'https://github.com/QueryKit/ReactiveQueryKit.git', :tag => "#{spec.version}" }
10+
spec.source_files = 'ReactiveQueryKit/*.{h}', 'ReactiveQueryKit/ObjectiveC/*.{h,m}'
11+
spec.requires_arc = true
12+
spec.dependency 'ReactiveCocoa', '~> 2.0'
13+
spec.dependency 'QueryKit'
14+
end
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// NSManagedObjectContext+RAC.h
3+
// QueryKit
4+
//
5+
// Created by Kyle Fuller on 09/09/2014.
6+
//
7+
//
8+
9+
#import <CoreData/CoreData.h>
10+
#import <ReactiveCocoa/ReactiveCocoa.h>
11+
12+
/// Extensions to QKQuerySet providing ReactiveCocoa signals
13+
@interface NSManagedObjectContext (ReactiveQueryKit)
14+
15+
/// Returns a signal that sends the NSNotification for NSManagedObjectContextObjectsDidChangeNotification in the current context
16+
- (RACSignal *)rqk_objectsDidChangeSignal;
17+
18+
/// Returns a signal that sends the NSNotification for NSManagedObjectContextWillSaveNotification in the current context
19+
- (RACSignal *)rqk_willSaveSignal;
20+
21+
/// Returns a signal that sends the NSNotification for NSManagedObjectContextDidSaveNotification in the current context
22+
- (RACSignal *)rqk_didSaveSignal;
23+
24+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// NSManagedObjectContext+RAC.m
3+
// QueryKit
4+
//
5+
// Created by Kyle Fuller on 09/09/2014.
6+
//
7+
//
8+
9+
#import "NSManagedObjectContext+RAC.h"
10+
11+
@implementation NSManagedObjectContext (ReactiveQueryKit)
12+
13+
- (RACSignal *)rqk_objectsDidChangeSignal {
14+
return [[[NSNotificationCenter defaultCenter] rac_addObserverForName:NSManagedObjectContextObjectsDidChangeNotification object:self] takeUntil:self.rac_willDeallocSignal];
15+
}
16+
17+
- (RACSignal *)rqk_willSaveSignal {
18+
return [[[NSNotificationCenter defaultCenter] rac_addObserverForName:NSManagedObjectContextWillSaveNotification object:self] takeUntil:self.rac_willDeallocSignal];
19+
}
20+
21+
- (RACSignal *)rqk_didSaveSignal {
22+
return [[[NSNotificationCenter defaultCenter] rac_addObserverForName:NSManagedObjectContextDidSaveNotification object:self] takeUntil:self.rac_willDeallocSignal];
23+
}
24+
25+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// QKQuerySet+RAC.h
3+
// QueryKit
4+
//
5+
// Created by Kyle Fuller on 09/09/2014.
6+
//
7+
//
8+
9+
#import <QueryKit/QueryKit.h>
10+
#import <ReactiveCocoa/ReactiveCocoa.h>
11+
12+
/// Extensions to QKQuerySet providing ReactiveCocoa signals
13+
@interface QKQuerySet (RAC)
14+
15+
/** Performs a query for all objects matching the set predicate ordered by any set sort descriptors.
16+
Emits a value include an array of all objects when the managed object context is changed.
17+
*/
18+
- (RACSignal /* NSArray */ *)objects;
19+
20+
/** Performs a query for the count of all objects matching the set predicate.
21+
Emits an NSNumber containing the amount of objects matching the predicate and updates when the managed object context is changed.
22+
*/
23+
- (RACSignal /* NSNumber */ *)count;
24+
25+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//
2+
// QKQuerySet+RAC.m
3+
// QueryKit
4+
//
5+
// Created by Kyle Fuller on 09/09/2014.
6+
//
7+
//
8+
9+
#import "QKQuerySet+RAC.h"
10+
#import "NSManagedObjectContext+RAC.h"
11+
12+
@implementation RACSignal (QKRInitialValue)
13+
14+
- (RACSignal *)initialValue:(id (^)(void))initialValue {
15+
return [RACSignal createSignal:^(id<RACSubscriber> subscriber) {
16+
[subscriber sendNext:initialValue()];
17+
18+
return [self subscribeNext:^(id x) {
19+
[subscriber sendNext:x];
20+
} error:^(NSError *error) {
21+
[subscriber sendError:error];
22+
} completed:^{
23+
[subscriber sendCompleted];
24+
}];
25+
}];
26+
}
27+
28+
@end
29+
30+
@implementation QKQuerySet (RAC)
31+
32+
- (RACSignal *)objects {
33+
return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
34+
{
35+
NSError *error;
36+
NSArray *objects = [self array:&error];
37+
38+
if (error) {
39+
[subscriber sendError:error];
40+
return nil;
41+
}
42+
43+
[subscriber sendNext:objects];
44+
}
45+
46+
__block RACDisposable *disposable = [[self.managedObjectContext rqk_objectsDidChangeSignal] subscribeNext:^(id x) {
47+
NSError *error;
48+
NSArray *objects = [[self copy] array:&error];
49+
50+
if (error) {
51+
[subscriber sendError:error];
52+
[disposable dispose];
53+
} else {
54+
[subscriber sendNext:objects];
55+
}
56+
} error:^(NSError *error) {
57+
[subscriber sendError:error];
58+
} completed:^{
59+
[subscriber sendCompleted];
60+
}];
61+
62+
return disposable;
63+
}];
64+
}
65+
66+
- (RACSignal *)count {
67+
return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
68+
{
69+
NSError *error;
70+
NSUInteger count = [self count:&error];
71+
72+
if (error) {
73+
[subscriber sendError:error];
74+
return nil;
75+
}
76+
77+
[subscriber sendNext:@(count)];
78+
}
79+
80+
__block RACDisposable *disposable = [[self.managedObjectContext rqk_objectsDidChangeSignal] subscribeNext:^(id x) {
81+
NSError *error;
82+
NSUInteger count = [self count:&error];
83+
84+
if (error) {
85+
[subscriber sendError:error];
86+
[disposable dispose];
87+
} else {
88+
[subscriber sendNext:@(count)];
89+
}
90+
} error:^(NSError *error) {
91+
[subscriber sendError:error];
92+
} completed:^{
93+
[subscriber sendCompleted];
94+
}];
95+
96+
return disposable;
97+
}];
98+
}
99+
100+
@end

ReactiveQueryKit/ReactiveQueryKit.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// ReactiveQueryKit.h
3+
// ReactiveQueryKit
4+
//
5+
// Created by Kyle Fuller on 09/09/2014.
6+
// Copyright (c) 2014 Cocode. All rights reserved.
7+
//
8+
9+
#import <Cocoa/Cocoa.h>
10+
11+
//! Project version number for ReactiveQueryKit.
12+
FOUNDATION_EXPORT double ReactiveQueryKitVersionNumber;
13+
14+
//! Project version string for ReactiveQueryKit.
15+
FOUNDATION_EXPORT const unsigned char ReactiveQueryKitVersionString[];
16+
17+
#import <ReactiveQueryKit/QKQuerySet+RAC.h>

ReactiveQueryKitTests/Podfile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
platform :osx, '10.10'
2+
3+
target 'ReactiveQueryKitTests' do
4+
pod 'ReactiveQueryKit', :path => '../'
5+
6+
pod 'Expecta'
7+
pod 'Expecta+ReactiveCocoa'
8+
end
9+

ReactiveQueryKitTests/Podfile.lock

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
PODS:
2+
- Expecta (0.3.1)
3+
- Expecta+ReactiveCocoa (0.2.0):
4+
- Expecta
5+
- ReactiveCocoa
6+
- QueryKit (0.8.3)
7+
- ReactiveCocoa (2.3.1):
8+
- ReactiveCocoa/UI
9+
- ReactiveCocoa/Core (2.3.1):
10+
- ReactiveCocoa/no-arc
11+
- ReactiveCocoa/no-arc (2.3.1)
12+
- ReactiveCocoa/UI (2.3.1):
13+
- ReactiveCocoa/Core
14+
- ReactiveQueryKit (0.1.0):
15+
- QueryKit
16+
- ReactiveCocoa
17+
18+
DEPENDENCIES:
19+
- Expecta
20+
- Expecta+ReactiveCocoa
21+
- ReactiveQueryKit (from `../`)
22+
23+
EXTERNAL SOURCES:
24+
ReactiveQueryKit:
25+
:path: ../
26+
27+
SPEC CHECKSUMS:
28+
Expecta: 03aabd0a89d8dea843baecb19a7fd7466a69a31d
29+
Expecta+ReactiveCocoa: 92bc1812054c8270c7cea94fa75c6ca2fc5a402e
30+
QueryKit: d3f7cccef598433cdd1b8b2cc63d47ddfeb117c4
31+
ReactiveCocoa: dca75777b9d18990c8714a3a6f2149f29b4d1462
32+
ReactiveQueryKit: 0c64716f1abaed7b2c9eb7f21848408a7e1e1aa4
33+
34+
COCOAPODS: 0.33.1

0 commit comments

Comments
 (0)