Skip to content

Commit fd8cd25

Browse files
authored
Merge pull request #154 from button/pr132
Continue Looking for Route Handler until match handles it (#131)
2 parents c5e737b + 2fbb889 commit fd8cd25

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

DeepLinkKit.xcodeproj/project.pbxproj

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
62EE96F71B570B13003D7564 /* DPLProduct.m in Sources */ = {isa = PBXBuildFile; fileRef = DE87B1F01A5DF49F00204A35 /* DPLProduct.m */; };
3131
62EE96F81B570B16003D7564 /* DPLProductTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DEAD327A19E079D3003C8D65 /* DPLProductTableViewController.m */; };
3232
BFDB96F71F3C0011001AE303 /* NSString+DPLTrim.m in Sources */ = {isa = PBXBuildFile; fileRef = DE16E91B1A42720D00077E18 /* NSString+DPLTrim.m */; };
33+
69E6850D1F1015F900D6D8CC /* DPLWontHandleRouteHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 69E6850C1F1015F900D6D8CC /* DPLWontHandleRouteHandler.m */; };
3334
BFDB96F81F3C0011001AE303 /* NSString+DPLQuery.m in Sources */ = {isa = PBXBuildFile; fileRef = DE058E081A3B46F500147C04 /* NSString+DPLQuery.m */; };
3435
BFDB96F91F3C0011001AE303 /* NSString+DPLJSON.m in Sources */ = {isa = PBXBuildFile; fileRef = DE3E61091A3B4485008D6DFC /* NSString+DPLJSON.m */; };
3536
BFDB96FA1F3C0011001AE303 /* NSObject+DPLJSONObject.m in Sources */ = {isa = PBXBuildFile; fileRef = DECB32511A87E94B0071C76E /* NSObject+DPLJSONObject.m */; };
@@ -119,6 +120,8 @@
119120
62891E8A1B57FE5A00C2AF4F /* DPLMessageRouteHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DPLMessageRouteHandler.swift; sourceTree = "<group>"; };
120121
62EE96F11B57011D003D7564 /* ReceiverDemoSwift-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ReceiverDemoSwift-Bridging-Header.h"; sourceTree = "<group>"; };
121122
62EE96F31B570891003D7564 /* DPLProductRouteHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DPLProductRouteHandler.swift; sourceTree = "<group>"; };
123+
69E6850B1F1015F900D6D8CC /* DPLWontHandleRouteHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DPLWontHandleRouteHandler.h; sourceTree = "<group>"; };
124+
69E6850C1F1015F900D6D8CC /* DPLWontHandleRouteHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DPLWontHandleRouteHandler.m; sourceTree = "<group>"; };
122125
83D34C3B1B03ECAD00BA6EF1 /* DPLMatchResult.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DPLMatchResult.h; sourceTree = "<group>"; };
123126
83D34C3C1B03ECAD00BA6EF1 /* DPLMatchResult.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DPLMatchResult.m; sourceTree = "<group>"; };
124127
83D34C3D1B03ECAD00BA6EF1 /* DPLRegularExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DPLRegularExpression.h; sourceTree = "<group>"; };
@@ -474,6 +477,8 @@
474477
isa = PBXGroup;
475478
children = (
476479
DE16E9271A42883B00077E18 /* DPLDeepLinkRouter_Private.h */,
480+
69E6850B1F1015F900D6D8CC /* DPLWontHandleRouteHandler.h */,
481+
69E6850C1F1015F900D6D8CC /* DPLWontHandleRouteHandler.m */,
477482
);
478483
path = Helpers;
479484
sourceTree = "<group>";
@@ -1163,6 +1168,7 @@
11631168
4D4F412B1B02A96400B710DB /* DPLRegularExpressionSpec.m in Sources */,
11641169
DECB32531A881CA10071C76E /* NSObject_DPLJSONObjectSpec.m in Sources */,
11651170
DEEBD4A91AAB7946000BCA84 /* DPLSerializableObject.m in Sources */,
1171+
69E6850D1F1015F900D6D8CC /* DPLWontHandleRouteHandler.m in Sources */,
11661172
DE058E101A3B485500147C04 /* DPLDeepLinkSpec.m in Sources */,
11671173
DECB32551A882D1A0071C76E /* DPLMutableDeepLinkSpec.m in Sources */,
11681174
DE058E0A1A3B46FD00147C04 /* NSString_DPLQuerySpec.m in Sources */,

DeepLinkKit/Router/DPLDeepLinkRouter.m

+3-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ - (BOOL)handleURL:(NSURL *)url withCompletion:(DPLRouteCompletionBlock)completio
127127
deepLink = [matcher deepLinkWithURL:url];
128128
if (deepLink) {
129129
isHandled = [self handleRoute:route withDeepLink:deepLink error:&error];
130-
break;
130+
if (isHandled) {
131+
break;
132+
}
131133
}
132134
}
133135

Tests/Router/DPLDeepLinkRouterSpec.m

+24-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#import "DPLRouteHandler.h"
44
#import "DPLDeepLink.h"
55
#import "DPLErrors.h"
6+
#import "DPLWontHandleRouteHandler.h"
67

78
SpecBegin(DPLDeepLinkRouter)
89

@@ -139,6 +140,25 @@
139140
});
140141
});
141142

143+
it(@"continues looking for a match which will handle the route, even if the first match chooses not to handle it", ^{
144+
waitUntil(^(DoneCallback done) {
145+
[router registerHandlerClass:[DPLWontHandleRouteHandler class] forRoute:@"/say/hello"];
146+
147+
__block BOOL didMatchOnSecondRegistration = NO;
148+
router[@"/say/:word"] = ^{
149+
didMatchOnSecondRegistration = YES;
150+
};
151+
152+
BOOL isHandled = [router handleURL:url withCompletion:^(BOOL handled, NSError *error) {
153+
expect(handled).to.beTruthy();
154+
expect(error).to.beNil();
155+
done();
156+
}];
157+
expect(didMatchOnSecondRegistration).to.beTruthy();
158+
expect(isHandled).to.beTruthy();
159+
});
160+
});
161+
142162
it(@"matches less specfic routes first when they are registered first", ^{
143163
waitUntil(^(DoneCallback done) {
144164
router[@"/say/:word"] = ^(DPLDeepLink *deepLink) {
@@ -157,7 +177,7 @@
157177
expect(isHandled).to.beTruthy();
158178
});
159179
});
160-
180+
161181
it(@"produces an error when a URL has no matching route", ^{
162182
waitUntil(^(DoneCallback done) {
163183
BOOL isHandled = [router handleURL:url withCompletion:^(BOOL handled, NSError *error) {
@@ -168,12 +188,12 @@
168188
expect(isHandled).to.beFalsy();
169189
});
170190
});
171-
191+
172192
it(@"produces an error when a route handler does not specify a target view controller", ^{
173193
waitUntil(^(DoneCallback done) {
174-
194+
175195
router[@"/say/:word"] = [DPLRouteHandler class];
176-
196+
177197
BOOL isHandled = [router handleURL:url withCompletion:^(BOOL handled, NSError *error) {
178198
expect(handled).to.beFalsy();
179199
expect(error.code).to.equal(DPLRouteHandlerTargetNotSpecifiedError);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import "DPLRouteHandler.h"
2+
3+
@interface DPLWontHandleRouteHandler : DPLRouteHandler
4+
5+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#import "DPLWontHandleRouteHandler.h"
2+
3+
@implementation DPLWontHandleRouteHandler
4+
5+
- (BOOL)shouldHandleDeepLink:(DPLDeepLink *)deepLink {
6+
return NO;
7+
}
8+
9+
@end

0 commit comments

Comments
 (0)