mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-05-26 05:54:57 +08:00
Updates to relationship connection execution system for better encapsulation and reuse.
* Reworked execution of relationship connection operations to use dependencies instead of queue suspension. * Migrates responsibility for connecting relationships from `RKManagedObjectRequestOperation` into `RKManagedObjectResponseMapperOperation`. This ensures that you get a mapped and connected object graph back from the response mapper if you are using it outside of a request operation. * Add `parentOperation` to managed object mapping data source to establish dependencies.
This commit is contained in:
@@ -28,6 +28,10 @@
|
||||
#import "RKManagedObjectCaching.h"
|
||||
#import "RKRelationshipConnectionOperation.h"
|
||||
|
||||
// Set Logging Component
|
||||
#undef RKLogComponent
|
||||
#define RKLogComponent RKlcl_cRestKitCoreData
|
||||
|
||||
extern NSString * const RKObjectMappingNestingAttributeKeyName;
|
||||
|
||||
@interface RKManagedObjectMappingOperationDataSource ()
|
||||
@@ -149,20 +153,15 @@ extern NSString * const RKObjectMappingNestingAttributeKeyName;
|
||||
RKRelationshipConnectionOperation *operation = [[RKRelationshipConnectionOperation alloc] initWithManagedObject:mappingOperation.destinationObject
|
||||
connectionMapping:connectionMapping
|
||||
managedObjectCache:self.managedObjectCache];
|
||||
// TODO: This should really be done using dependencies...
|
||||
if (self.operationQueue) {
|
||||
[self.operationQueue addOperation:operation];
|
||||
[operation setCompletionBlock:^{
|
||||
if ([mappingOperation.delegate respondsToSelector:@selector(mappingOperation:didConnectRelationship:usingMapping:)]) {
|
||||
[mappingOperation.delegate mappingOperation:mappingOperation didConnectRelationship:connectionMapping.relationship usingMapping:connectionMapping];
|
||||
}
|
||||
}];
|
||||
} else {
|
||||
[operation start];
|
||||
[operation setCompletionBlock:^{
|
||||
if ([mappingOperation.delegate respondsToSelector:@selector(mappingOperation:didConnectRelationship:usingMapping:)]) {
|
||||
[mappingOperation.delegate mappingOperation:mappingOperation didConnectRelationship:connectionMapping.relationship usingMapping:connectionMapping];
|
||||
}
|
||||
}
|
||||
}];
|
||||
if (self.parentOperation) [operation addDependency:self.parentOperation];
|
||||
NSOperationQueue *operationQueue = self.operationQueue ?: [NSOperationQueue currentQueue];
|
||||
[operationQueue addOperation:operation];
|
||||
RKLogTrace(@"Enqueued %@ dependent upon parent operation %@ to operation queue %@", operation, self.parentOperation, operationQueue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user