This repository has been archived by the owner on Oct 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TTRule.h
215 lines (180 loc) · 7.66 KB
/
TTRule.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
//
// TTRule.h
// Tabletops
//
// Created by Jacob Hauberg Hansen on 07/05/15.
// Copyright (c) 2015 Jacob Hauberg Hansen. All rights reserved.
//
#import <Foundation/Foundation.h>
@class TTRule;
typedef BOOL (^TTRuleResolutionBlock)(id __nullable state);
typedef BOOL (^TTRuleResolutionConditionBlock)(id __nullable state);
typedef BOOL (^TTRuleResolutionConditionResponseBlock)(id __nullable state, TTRule *__nullable otherRule);
typedef BOOL (^TTRuleResolutionResponseBlock)(id __nullable state, TTRule *__nullable otherRule);
/**
Represents a rule that can be resolved.
*/
@interface TTRule : NSObject
/**
Create a rule.
*/
+ (nonnull instancetype) rule;
/**
Create a rule that will always resolve.
*/
+ (nonnull instancetype) ruleWithName: (nullable NSString *) name;
/**
Create a rule that will always resolve.
*/
+ (nonnull instancetype) ruleWithName: (nullable NSString *) name
thatResolvesTo: (nullable TTRuleResolutionBlock) resolution;
/**
Create a rule that will resolve when a condition is satisfied.
*/
+ (nonnull instancetype) ruleWithName: (nullable NSString *) name
thatResolves: (nullable TTRuleResolutionConditionBlock) condition;
/**
Create a rule that will resolve when a condition is satisfied.
*/
+ (nonnull instancetype) ruleWithName: (nullable NSString *) name
thatResolves: (nullable TTRuleResolutionConditionBlock) condition
to: (nullable TTRuleResolutionBlock) resolution;
/**
Create a rule that will resolve @a before another rule, if a condition is satisfied.
*/
+ (nonnull instancetype) ruleWithName: (nullable NSString *) name
thatResolvesBefore: (nullable TTRuleResolutionConditionResponseBlock) responseCondition
to: (nullable TTRuleResolutionResponseBlock) resolution;
/**
Create a rule that will resolve either @a before or @a after another rule, if a condition is satisfied.
*/
+ (nonnull instancetype) ruleWithName: (nullable NSString *) name
thatResolvesBefore: (nullable TTRuleResolutionConditionResponseBlock) responseConditionBefore
to: (nullable TTRuleResolutionResponseBlock) resolutionBefore
orAfter: (nullable TTRuleResolutionConditionResponseBlock) responseConditionAfter
to: (nullable TTRuleResolutionResponseBlock) resolutionAfter;
/**
Create a rule that will resolve @a after another rule, if a condition is satisfied.
*/
+ (nonnull instancetype) ruleWithName: (nullable NSString *) name
thatResolvesAfter: (nullable TTRuleResolutionConditionResponseBlock) responseCondition
to: (nullable TTRuleResolutionResponseBlock) resolution;
/**
Get or set the action that should occur when the rule resolves.
The action should return YES if the rule was resolved successfully, NO otherwise.
*/
@property (nullable, strong) TTRuleResolutionBlock resolutionBlock;
/**
Get or set a condition that returns YES if the rule should be resolved given the current state.
NO otherwise.
*/
@property (nullable, strong) TTRuleResolutionConditionBlock resolutionConditionBlock;
/**
Get or set a condition that returns YES if the rule should be resolved as a response to another rule being resolved.
NO otherwise.
*/
@property (nullable, strong) TTRuleResolutionConditionResponseBlock resolutionConditionBeforeBlock;
/**
Get or set a condition that returns YES if the rule should be resolved as a response to another rule having been
resolved. NO otherwise.
*/
@property (nullable, strong) TTRuleResolutionConditionResponseBlock resolutionConditionAfterBlock;
/**
Get or set the action that should occur when the rule resolves as a response to another rule being resolved.
The action should return YES if the rule was resolved, NO otherwise.
*/
@property (nullable, strong) TTRuleResolutionResponseBlock resolutionBeforeBlock;
/**
Get or set the action that should occur when the rule is being resolved as a response to another rule having been resolved.
The action should return YES if the rule was resolved, NO otherwise.
*/
@property (nullable, strong) TTRuleResolutionResponseBlock resolutionAfterBlock;
/**
Get or set whether or not the rule should persist @a after having been resolved.
A rule that persists will stay in the rule stack after it has been resolved successfully.
*/
@property (assign) BOOL persistsWhenResolved;
/**
Get or set whether or not the rule should be removed after @a not resolving successfully.
*/
@property (assign) BOOL removedIfNotResolved;
/**
Get or set the name of the rule.
*/
@property (nullable, strong) NSString *name;
/**
Create a new rule with a name.
@returns A TTRule object.
*/
- (nonnull instancetype) initWithName: (nullable NSString *) name;
/**
Determine whether the rule can be resolved given the current state.
This will always return YES unless a subclass returns differently, or a @c resolutionConditionBlock is defined.
*/
- (BOOL) canResolve: (nullable id) state;
/**
Determine whether the rule can be resolved as a response to another rule being resolved.
*/
- (BOOL) canResolve: (nullable id) state
before: (nonnull TTRule *) rule;
/**
Determine whether the rule can be resolved as a response to another rule having been resolved.
*/
- (BOOL) canResolve: (nullable id) state
after: (nonnull TTRule *) rule;
/**
Called before the rule attempts to resolve as a response to another rule being resolved.
Override this method in a subclass to implement behavior before a resolution attempt.
The default implementation of this method does nothing.
*/
- (void) willResolveBefore: (nonnull TTRule *) rule;
/**
Called before the rule attempts to resolve.
Override this method in a subclass to implement behavior before a resolution attempt.
The default implementation of this method does nothing.
*/
- (void) willResolve;
/**
Called before the rule attempts to resolve as a response to another rule having been resolved.
Override this method in a subclass to implement behavior before a resolution attempt.
The default implementation of this method does nothing.
*/
- (void) willResolveAfter: (nonnull TTRule *) rule;
/**
Resolve the rule.
@returns YES if the rule was resolved, NO otherwise.
*/
- (BOOL) resolve: (nullable id) state;
/**
Resolve the rule before another rule.
@returns YES if the rule was resolved, NO otherwise.
*/
- (BOOL) resolve: (nullable id) state
before: (nonnull TTRule *) rule;
/**
Resolve the rule after another rule.
@returns YES if the rule was resolved, NO otherwise.
*/
- (BOOL) resolve: (nullable id) state
after: (nonnull TTRule *) rule;
/**
Called after the rule has been resolved (either successfully or not) as a response to another rule being resolved.
Override this method in a subclass to implement behavior after a resolution attempt.
The default implementation of this method does nothing.
*/
- (void) didResolve: (BOOL) successfully
before: (nonnull TTRule *) rule;
/**
Called after the rule has been resolved (either successfully or not).
Override this method in a subclass to implement behavior after a resolution attempt.
The default implementation of this method does nothing.
*/
- (void) didResolve: (BOOL) successfully;
/**
Called after the rule has been resolved (either successfully or not) as a response to another rule having been resolved.
Override this method in a subclass to implement behavior after a resolution attempt.
The default implementation of this method does nothing.
*/
- (void) didResolve: (BOOL) successfully
after: (nonnull TTRule *) rule;
@end