Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Demo/AppCoordinator.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit
import FeatherweightRouter

typealias UIPresenter = Presenter<UIViewController>
typealias UIPresenter = RoutePresenter<UIViewController>

func appCoordinator() -> UIViewController {

Expand All @@ -11,7 +11,7 @@ func appCoordinator() -> UIViewController {

store.setPath("welcome")

return router.presentable
return router.getPresentable()
}

func createRouter(_ store: AppStore) -> Router<UIViewController, String> {
Expand All @@ -21,7 +21,9 @@ func createRouter(_ store: AppStore) -> Router<UIViewController, String> {
Router(navigationPresenter("Welcome")).stack([
Router(welcomePresenter(store)).route(predicate: {$0 == "welcome"}, children: [
Router(registrationPresenter(store)).route(predicate: {$0 == "welcome/register"}, children: [
Router(step2Presenter(store)).route(predicate: {$0 == "welcome/register/step2"}),
Router(step2Presenter(store)).route(predicate: {$0.matches("welcome/register/step(?<step>\\d+)")}, arguments: { (path) -> RouteArguments in
return path.capturedGroups(withRegex: "welcome/register/step(?<step>\\d+)")
}),
]),
Router(loginPresenter(store)).route(predicate: {$0 == "welcome/login"}),
])
Expand Down
2 changes: 1 addition & 1 deletion Demo/Presenters/AboutPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ func aboutPresenter(_ store: AppStore) -> UIPresenter {
callToActionTitle: "Go to '/welcome/login/'",
callToActionRoute: "welcome/login"))

return Presenter(getPresentable: { viewController })
return RoutePresenter(getPresentable: { _ in viewController })
}
2 changes: 1 addition & 1 deletion Demo/Presenters/LoginPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ func loginPresenter(_ store: AppStore) -> UIPresenter {
callToActionTitle: "Go to '/welcome/'",
callToActionRoute: "welcome"))

return Presenter(getPresentable: { viewController })
return RoutePresenter(getPresentable: { _ in viewController })
}
4 changes: 2 additions & 2 deletions Demo/Presenters/NavigationPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ func navigationPresenter(_ title: String) -> UIPresenter {
navigationController.tabBarItem.title = title
navigationController.tabBarItem.image = UIImage(named: "placeholder-icon")

return Presenter(
getPresentable: { navigationController },
return RoutePresenter(
getPresentable: { _ in navigationController },
setChild: { _ in },
setChildren: { navigationController.setViewControllers($0, animated: true) })
}
2 changes: 1 addition & 1 deletion Demo/Presenters/RegistrationPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ func registrationPresenter(_ store: AppStore) -> UIPresenter {
callToActionTitle: "Go to '/about/'",
callToActionRoute: "about"))

return Presenter(getPresentable: { viewController })
return RoutePresenter(getPresentable: { _ in viewController })
}
10 changes: 8 additions & 2 deletions Demo/Presenters/Step2Presenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ func step2Presenter(_ store: AppStore) -> UIPresenter {
let viewController = MockViewController(MockViewModel(
store: store,
backgroundColor: (128, 255, 255),
title: "Registration + Step 2",
title: "ROUTE ARGUMENT: Step = ",
callToActionTitle: "Go to '/welcome/register/'",
callToActionRoute: "welcome/register"))

return Presenter(getPresentable: { viewController })
return RoutePresenter(getPresentable: {
arguments in
if let step = arguments.first {
viewController.setStepNumber(step)
}
return viewController
})
}
4 changes: 2 additions & 2 deletions Demo/Presenters/TabBarPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ func tabBarPresenter() -> UIPresenter {

let tabBarController = UITabBarController()

return Presenter(
getPresentable: { tabBarController },
return RoutePresenter(
getPresentable: { _ in tabBarController },
setChild: { tabBarController.selectedViewController = $0 },
setChildren: { tabBarController.setViewControllers($0, animated: true) })
}
2 changes: 1 addition & 1 deletion Demo/Presenters/WelcomePresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ func welcomePresenter(_ store: AppStore) -> UIPresenter {

let viewController = WelcomeViewController(WelcomeViewModel(store: store))

return Presenter(getPresentable: { viewController })
return RoutePresenter(getPresentable: { _ in viewController })
}
42 changes: 42 additions & 0 deletions Demo/String+extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// String+extensions.swift
// FeatherweightRouter
//
// Created by Eliah Snakin on 23/08/2017.
// Copyright © 2017 Featherweight Labs. All rights reserved.
//

import Foundation

extension String {

func matches(_ regex: String) -> Bool {
return self.range(of: regex, options: .regularExpression, range: nil, locale: nil) != nil
}

func capturedGroups(withRegex pattern: String) -> [String] {
var results = [String]()

var regex: NSRegularExpression
do {
regex = try NSRegularExpression(pattern: pattern, options: [])
} catch {
return results
}

let matches = regex.matches(in: self, options: [], range: NSRange(location:0, length: self.characters.count))

guard let match = matches.first else { return results }

let lastRangeIndex = match.numberOfRanges - 1
guard lastRangeIndex >= 1 else { return results }

for i in 1...lastRangeIndex {
let capturedGroupIndex = match.rangeAt(i)
let matchedString = (self as NSString).substring(with: capturedGroupIndex)
results.append(matchedString)
}

return results
}
}
7 changes: 6 additions & 1 deletion Demo/ViewControllers/MockViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ protocol ProvidesMockData {
class MockViewController: UIViewController {

let viewModel: ProvidesMockData
var step: String?

@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var actionButton: UIButton!
Expand All @@ -25,6 +26,10 @@ class MockViewController: UIViewController {
tabBarItem.title = viewModel.title
tabBarItem.image = UIImage(named: "placeholder-icon")
}

public func setStepNumber(_ step: String) {
self.step = step
}

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -34,7 +39,7 @@ class MockViewController: UIViewController {
blue: CGFloat(viewModel.backgroundColor.2) / 255,
alpha: 1)

titleLabel.text = viewModel.title
titleLabel.text = viewModel.title + (step ?? "")

actionButton.setTitle(viewModel.callToActionTitle, for: UIControlState())

Expand Down
5 changes: 4 additions & 1 deletion Demo/ViewModels/MockViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ struct MockViewModel: ProvidesMockData {
let title: String
let callToActionTitle: String
let navigateToAction: () -> Void
var arbitraryArgument: String?

init(store: AppStore, backgroundColor: RGBColor, title: String, callToActionTitle: String,
callToActionRoute: String) {
callToActionRoute: String, arbitraryArgument: String? = nil) {

self.backgroundColor = backgroundColor
self.title = title
Expand All @@ -17,5 +18,7 @@ struct MockViewModel: ProvidesMockData {
navigateToAction = {
store.dispatchRoute(callToActionRoute)
}

self.arbitraryArgument = arbitraryArgument
}
}
47 changes: 8 additions & 39 deletions FeatherweightRouter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
737DC1351D0E68A000704F6C /* RouterRouteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 737DC1331D0E68A000704F6C /* RouterRouteTests.swift */; };
737DC1371D0E918F00704F6C /* RouterStackTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 737DC1361D0E918F00704F6C /* RouterStackTests.swift */; };
737DC1381D0E918F00704F6C /* RouterStackTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 737DC1361D0E918F00704F6C /* RouterStackTests.swift */; };
737DC13A1D0EA46800704F6C /* CachedPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 737DC1391D0EA46800704F6C /* CachedPresenter.swift */; };
737DC13B1D0EA46800704F6C /* CachedPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 737DC1391D0EA46800704F6C /* CachedPresenter.swift */; };
737DC13D1D0EA69300704F6C /* CachedPresenterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 737DC13C1D0EA69300704F6C /* CachedPresenterTests.swift */; };
737DC13E1D0EA69300704F6C /* CachedPresenterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 737DC13C1D0EA69300704F6C /* CachedPresenterTests.swift */; };
737DF5A11D0D63A900614CC0 /* PresenterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 737DF5A01D0D63A900614CC0 /* PresenterTests.swift */; };
Expand All @@ -59,6 +57,8 @@
7386DBBD1C5F5C3E00D385A9 /* UIKit+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7386DBBC1C5F5C3E00D385A9 /* UIKit+Extensions.swift */; };
73ED16781C3E2E44003B3827 /* WelcomeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73ED16771C3E2E44003B3827 /* WelcomeViewModel.swift */; };
73ED167A1C3E2E65003B3827 /* WelcomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 73ED16791C3E2E65003B3827 /* WelcomeViewController.swift */; };
D04D96AA1F4DA18100F03703 /* String+extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0CE898E1F4D9D1200CD69FC /* String+extensions.swift */; };
D0CE898F1F4D9D1200CD69FC /* String+extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0CE898E1F4D9D1200CD69FC /* String+extensions.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -110,7 +110,6 @@
73612BC31C3E13B100FD841A /* RegistrationPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegistrationPresenter.swift; sourceTree = "<group>"; };
737DC1331D0E68A000704F6C /* RouterRouteTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RouterRouteTests.swift; sourceTree = "<group>"; };
737DC1361D0E918F00704F6C /* RouterStackTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RouterStackTests.swift; sourceTree = "<group>"; };
737DC1391D0EA46800704F6C /* CachedPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CachedPresenter.swift; sourceTree = "<group>"; };
737DC13C1D0EA69300704F6C /* CachedPresenterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CachedPresenterTests.swift; sourceTree = "<group>"; };
737DC1401D0EAAE400704F6C /* .gitignore */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitignore; sourceTree = "<group>"; };
737DC1411D0EAAE400704F6C /* .hound.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .hound.yml; sourceTree = "<group>"; };
Expand All @@ -131,6 +130,7 @@
7386DBBC1C5F5C3E00D385A9 /* UIKit+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIKit+Extensions.swift"; sourceTree = "<group>"; };
73ED16771C3E2E44003B3827 /* WelcomeViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WelcomeViewModel.swift; sourceTree = "<group>"; };
73ED16791C3E2E65003B3827 /* WelcomeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WelcomeViewController.swift; sourceTree = "<group>"; };
D0CE898E1F4D9D1200CD69FC /* String+extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "String+extensions.swift"; path = "Demo/String+extensions.swift"; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -203,7 +203,6 @@
731836C51C5D867B00D5E1C6 /* FeatherweightRouter.h */,
731836C61C5D867B00D5E1C6 /* Info.plist */,
731836F81C5D87ED00D5E1C6 /* Array+pickFirst.swift */,
737DC1391D0EA46800704F6C /* CachedPresenter.swift */,
731836FE1C5D87ED00D5E1C6 /* Presenter.swift */,
731836FD1C5D87ED00D5E1C6 /* Router.swift */,
731836FA1C5D87ED00D5E1C6 /* Router+junction.swift */,
Expand Down Expand Up @@ -251,6 +250,7 @@
7349E7AC1C3DDA47004A507B /* Assets.xcassets */,
7349E7AD1C3DDA47004A507B /* LaunchScreen.storyboard */,
7349E7AF1C3DDA47004A507B /* Info.plist */,
D0CE898E1F4D9D1200CD69FC /* String+extensions.swift */,
);
path = "Supporting Files";
sourceTree = "<group>";
Expand Down Expand Up @@ -341,7 +341,6 @@
7349E73B1C3DD665004A507B /* Frameworks */,
7349E73C1C3DD665004A507B /* Headers */,
7349E73D1C3DD665004A507B /* Resources */,
731837091C5D887C00D5E1C6 /* SwiftLint */,
);
buildRules = (
);
Expand Down Expand Up @@ -395,7 +394,6 @@
737DF5A31D0D6EB200614CC0 /* Frameworks */,
737DF5A41D0D6EB200614CC0 /* Headers */,
737DF5A51D0D6EB200614CC0 /* Resources */,
737DC1491D0EABA800704F6C /* SwiftLint */,
);
buildRules = (
);
Expand Down Expand Up @@ -523,48 +521,17 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
731837091C5D887C00D5E1C6 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = SwiftLint;
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"error: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
};
737DC1491D0EABA800704F6C /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = SwiftLint;
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"error: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
7349E73A1C3DD665004A507B /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
731837011C5D87ED00D5E1C6 /* Array+pickFirst.swift in Sources */,
D0CE898F1F4D9D1200CD69FC /* String+extensions.swift in Sources */,
731837071C5D87ED00D5E1C6 /* Presenter.swift in Sources */,
731837061C5D87ED00D5E1C6 /* Router.swift in Sources */,
731837081C5D87ED00D5E1C6 /* Router+stack.swift in Sources */,
731837051C5D87ED00D5E1C6 /* Router+route.swift in Sources */,
737DC13A1D0EA46800704F6C /* CachedPresenter.swift in Sources */,
731837031C5D87ED00D5E1C6 /* Router+junction.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -592,6 +559,7 @@
7349E7B71C3DDAD2004A507B /* AppCoordinator.swift in Sources */,
731777831C68D8CB00806D29 /* TabBarPresenter.swift in Sources */,
7317777E1C68D44F00806D29 /* MockViewModel.swift in Sources */,
D04D96AA1F4DA18100F03703 /* String+extensions.swift in Sources */,
73ED16781C3E2E44003B3827 /* WelcomeViewModel.swift in Sources */,
73612BC51C3E13BD00FD841A /* RegistrationPresenter.swift in Sources */,
7317777C1C68D44600806D29 /* AboutPresenter.swift in Sources */,
Expand All @@ -615,7 +583,6 @@
737DF5C41D0D6FC400614CC0 /* Router.swift in Sources */,
737DF5C51D0D6FC400614CC0 /* Router+junction.swift in Sources */,
737DF5BE1D0D6F2200614CC0 /* Array+pickFirst.swift in Sources */,
737DC13B1D0EA46800704F6C /* CachedPresenter.swift in Sources */,
737DF5C71D0D6FC400614CC0 /* Router+stack.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -665,6 +632,7 @@
7349E7451C3DD665004A507B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_EMPTY_CONTEXT = YES;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
Expand Down Expand Up @@ -735,6 +703,7 @@
7349E7461C3DD665004A507B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_EMPTY_CONTEXT = YES;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
Expand Down
28 changes: 0 additions & 28 deletions Sources/CachedPresenter.swift

This file was deleted.

Loading