Skip to content

Instantly share code, notes, and snippets.

@mbaranowski
Created August 24, 2016 12:33
Show Gist options
  • Save mbaranowski/f114a9a4001b365af4593b4c5313d006 to your computer and use it in GitHub Desktop.
Save mbaranowski/f114a9a4001b365af4593b4c5313d006 to your computer and use it in GitHub Desktop.
ReObjectiveC.h
#import <Foundation/Foundation.h>
@protocol Action <NSObject>
@end
@interface ActionStateInit : NSObject <Action>
@end
@protocol StateType <NSObject>
@end
@protocol AnyReducer
-(id<StateType> _Nonnull)handleAction:(id<Action> _Nonnull)action state:(id<StateType> _Nullable)state;
@end
@protocol AnyStoreSubscriber
-(void)newState:(id<StateType> _Nonnull)state;
@end
typedef id<StateType> _Nonnull (^StateSelector)(id<StateType> _Nonnull);
@interface Subscription : NSObject
@property (weak, nonatomic) id<AnyStoreSubscriber> _Nullable subscriber;
@property (nonatomic) StateSelector _Nullable selector;
@end
typedef id _Nullable (^DispatchFunction)(id<Action> _Nonnull action);
typedef id<StateType> _Nullable (^GetState)();
typedef DispatchFunction _Nonnull (^DispatchFunctionTransform)(DispatchFunction _Nonnull);
typedef DispatchFunctionTransform _Nonnull (^Middleware)(DispatchFunction _Nullable, GetState _Nonnull);
@interface Store : NSObject
-(instancetype _Nonnull)initWithReducer:(id<AnyReducer> _Nonnull)reducer
state:(id<StateType> _Nullable)state
middleware:(NSArray<Middleware>* _Nullable)middleware;
-(id _Nullable)dispatch:(id<Action> _Nonnull)action;
-(void)subscribe:(id<AnyStoreSubscriber> _Nonnull)subscriber selector:(StateSelector _Nullable)selector;
-(void)unscubscribe:(id<AnyStoreSubscriber> _Nonnull)subscriber;
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment