-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,074 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,51 @@ | |||
// | |||
// MasterDetail.h | |||
// Miruken | |||
// | |||
// Created by Venkat Palivela on 3/27/13. | |||
// Copyright (c) 2013 Craig Neuwirt. All rights reserved. | |||
// | |||
|
|||
#import <Foundation/Foundation.h> | |||
|
|||
@protocol MKMasterDetail <NSObject> | |||
|
|||
@optional | |||
- (id<Promise>)selectedDetail:(Class)detailClass; | |||
|
|||
- (id<Promise>)selectedDetails:(Class)detailClass; | |||
|
|||
- (void)selectDetail:(id)selectedDetail; | |||
|
|||
- (void)deselectDetail:(id)selectedDetail; | |||
|
|||
- (BOOL)hasPreviousDetail:(Class)detailClass; | |||
|
|||
- (BOOL)hasNextDetail:(Class)detailClass; | |||
|
|||
- (id<Promise>)previousDetail:(Class)detailClass; | |||
|
|||
- (id<Promise>)nextDetail:(Class)detailClass; | |||
|
|||
- (id<Promise>)addDetail:(id)detail; | |||
|
|||
- (id<Promise>)removeDetail:(id)detail delete:(BOOL)delete; | |||
|
|||
@end | |||
|
|||
#define MKMasterDetail(handler) ((id<MKMasterDetail>)(handler)) | |||
|
|||
@protocol MKMasterDetailAware <NSObject> | |||
|
|||
@optional | |||
- (void)masterChanged; | |||
|
|||
- (void)didSelectDetail:(id)detail; | |||
|
|||
- (void)didDeselectDetail:(id)detail; | |||
|
|||
- (void)didRemoveDetail:(id)detail; | |||
|
|||
@end | |||
|
|||
#define MKMasterDetailAware(handler) ((id<MKMasterDetailAware>)(handler)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,26 @@ | |||
// | |||
// ViewRegion.h | |||
// Miruken | |||
// | |||
// Created by Craig Neuwirt on 2/27/13. | |||
// Copyright (c) 2013 Craig Neuwirt. All rights reserved. | |||
// | |||
|
|||
#import <UIKit/UIKit.h> | |||
|
|||
/** | |||
This protocol represents a region on the screen where a view controller can | |||
be rendered. It enables compositional view controllers. | |||
*/ | |||
|
|||
@protocol MKViewRegion <NSObject> | |||
|
|||
@optional | |||
- (void)presentViewController:(UIViewController *)viewControllerToPresent; | |||
|
|||
- (void)presentNextViewController:(UIViewController *)viewControllerToPresent; | |||
|
|||
@end | |||
|
|||
#define MKViewRegion(handler) ((id<MKViewRegion>)(handler)) | |||
#define MKViewRegionHint(region,handler) (region ? region : MKViewRegion(handler)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
// | |||
// UIAlertView+Action.h | |||
// Miruken | |||
// | |||
// Created by Craig Neuwirt on 2/11/13. | |||
// Copyright (c) 2013 Craig Neuwirt. All rights reserved. | |||
// | |||
|
|||
#import <UIKit/UIKit.h> | |||
|
|||
typedef void (^MKAlertViewBlock)(NSInteger buttonIndex); | |||
|
|||
@interface UIAlertView (UIAlertView_Block) | |||
|
|||
- (void)showUsingBlock:(MKAlertViewBlock)block; | |||
|
|||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,55 @@ | |||
// | |||
// UIAlertView+Block.m | |||
// Miruken | |||
// | |||
// Created by Craig Neuwirt on 2/11/13. | |||
// Copyright (c) 2013 Craig Neuwirt. All rights reserved. | |||
// | |||
|
|||
#import "UIAlertView+Block.h" | |||
|
|||
@interface MKAlertViewDelegate : NSObject<UIAlertViewDelegate> | |||
|
|||
@property (strong, atomic) MKAlertViewBlock block; | |||
|
|||
+ (void)show:(UIAlertView *)alertView withBlock:(MKAlertViewBlock)block; | |||
|
|||
@end | |||
|
|||
|
|||
@implementation UIAlertView (UIAlertView_Block) | |||
|
|||
- (void)showUsingBlock:(MKAlertViewBlock)block | |||
{ | |||
[MKAlertViewDelegate show:self withBlock:block]; | |||
} | |||
|
|||
@end | |||
|
|||
|
|||
@implementation MKAlertViewDelegate | |||
|
|||
+ (void)show:(UIAlertView *)alertView withBlock:(MKAlertViewBlock)block | |||
{ | |||
__block MKAlertViewDelegate *delegate = [MKAlertViewDelegate new]; | |||
|
|||
alertView.delegate = delegate; | |||
delegate.block = ^(NSInteger buttonIndex) { | |||
alertView.delegate = nil; | |||
|
|||
#pragma clang diagnostic push | |||
#pragma clang diagnostic ignored "-Warc-retain-cycles" | |||
delegate = nil; | |||
#pragma clang diagnostic pop | |||
}; | |||
|
|||
[alertView show]; | |||
} | |||
|
|||
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex | |||
{ | |||
if (_block) | |||
_block(buttonIndex); | |||
} | |||
|
|||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
// | |||
// MKCallbackHandler+Recoverable.h | |||
// Miruken | |||
// | |||
// Created by Craig Neuwirt on 11/30/12. | |||
// Copyright (c) 2012 Craig Neuwirt. All rights reserved. | |||
// | |||
|
|||
#import "MKCallbackHandler.h" | |||
|
|||
@interface MKCallbackHandler (MKCallbackHandler_Recoverable) | |||
|
|||
- (instancetype)recoverable; | |||
|
|||
- (instancetype)recoverableInContext:(void *)context; | |||
|
|||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,50 @@ | |||
// | |||
// MKCallbackHandler+Recoverable.m | |||
// Miruken | |||
// | |||
// Created by Craig Neuwirt on 11/30/12. | |||
// Copyright (c) 2012 Craig Neuwirt. All rights reserved. | |||
// | |||
|
|||
#import "MKCallbackHandler+Recoverable.h" | |||
#import "MKCallbackHandlerFilter.h" | |||
#import "NSObject+ResolvePromise.h" | |||
#import "MKErrors.h" | |||
|
|||
@implementation MKCallbackHandler (MKCallbackHandler_Recoverable) | |||
|
|||
- (instancetype)recoverable | |||
{ | |||
return [self recoverableInContext:NULL]; | |||
} | |||
|
|||
- (instancetype)recoverableInContext:(void *)context | |||
{ | |||
return [MKCallbackHandlerFilter for:self | |||
filter:^(id callback, id<MKCallbackHandler> composer, BOOL(^proceed)()) { | |||
id<MKPromise> promise = nil; | |||
@try { | |||
BOOL handled = proceed(); | |||
if (handled && (promise = [callback effectivePromise])) | |||
{ | |||
__block id failureReason = nil; | |||
__block BOOL *failureHandled = nil; | |||
[[promise fail:^(id reason, BOOL *handled) { | |||
failureReason = reason; | |||
failureHandled = handled; | |||
}] | |||
always:^{ | |||
if (failureHandled != nil && *failureHandled == NO) | |||
[MKErrors(composer) handleFailure:failureReason context:context]; | |||
failureReason = nil; | |||
}]; | |||
} | |||
return handled; | |||
} | |||
@catch (id exception) { | |||
[MKErrors(composer) handleFailure:exception context:context]; | |||
} | |||
}]; | |||
} | |||
|
|||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,19 @@ | |||
// | |||
// MKEndContextOnError.h | |||
// Miruken | |||
// | |||
// Created by Craig Neuwirt on 9/3/13. | |||
// Copyright (c) 2013 Craig Neuwirt. All rights reserved. | |||
// | |||
|
|||
#import "MKErrors.h" | |||
#import "MKContextual.h" | |||
|
|||
@interface MKEndContextOnError : NSObject <MKErrors, MKContextual> | |||
@end | |||
|
|||
@interface MKContext (MKContext_EndContextOnError) | |||
|
|||
- (MKContext *)endContextOnError; | |||
|
|||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,53 @@ | |||
// | |||
// MKEndContextOnError.m | |||
// Miruken | |||
// | |||
// Created by Craig Neuwirt on 9/3/13. | |||
// Copyright (c) 2013 Craig Neuwirt. All rights reserved. | |||
// | |||
|
|||
#import "MKEndContextOnError.h" | |||
#import "MKContext+Subscribe.h" | |||
#import "UIAlertView+Block.h" | |||
#import "MKDeferred.h" | |||
#import "MKMixin.h" | |||
|
|||
@implementation MKEndContextOnError | |||
|
|||
+ (void)initialize | |||
{ | |||
if (self == MKEndContextOnError.class) | |||
[MKEndContextOnError mixinFrom:MKContextualMixin.class]; | |||
} | |||
|
|||
- (id<MKPromise>)reportError:(NSError *)error message:(NSString *)message | |||
title:(NSString *)title context:(void *)context | |||
{ | |||
MKDeferred *deferred = [MKDeferred new]; | |||
|
|||
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message | |||
delegate:self cancelButtonTitle:@"Continue" | |||
otherButtonTitles:nil]; | |||
|
|||
[alert showUsingBlock:^(NSInteger buttonIndex) { | |||
[self endContext]; | |||
[deferred resolve:nil]; | |||
}]; | |||
|
|||
return [deferred promise]; | |||
} | |||
|
|||
@end | |||
|
|||
@implementation MKContext (MKCallbackHandler_EndContextOnError) | |||
|
|||
- (MKContext *)endContextOnError | |||
{ | |||
__block MKEndContextOnError *end = [[MKEndContextOnError allocInContext:self] init]; | |||
[end.context subscribeDidEnd:^(id<MKContext> context) { | |||
end = nil; // keeps refresh alive until context ends | |||
}]; | |||
return end.context; | |||
} | |||
|
|||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
// | |||
// MKError.h | |||
// Miruken | |||
// | |||
// Created by Craig Neuwirt on 2/23/14. | |||
// Copyright (c) 2014 Craig Neuwirt. All rights reserved. | |||
// | |||
|
|||
#import "MKErrors.h" | |||
#import "MKCallbackHandler+Recoverable.h" | |||
#import "MKEndContextOnError.h" | |||
#import "MKWellKnownErrorResults.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
// | |||
// ErrorCallbackHandler.h | |||
// Miruken | |||
// | |||
// Created by Craig Neuwirt on 11/16/12. | |||
// Copyright (c) 2012 Craig Neuwirt. All rights reserved. | |||
// | |||
|
|||
#import "MKErrors.h" | |||
#import "MKDynamicCallbackHandler.h" | |||
|
|||
@interface MKErrorCallbackHandler : MKDynamicCallbackHandler <MKErrors> | |||
|
|||
@end |
Oops, something went wrong.