Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving to Action-Mutation-State model #19

Merged
merged 15 commits into from
Apr 17, 2017
4 changes: 4 additions & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ platform :ios, '8.0'
target 'RxTodo' do
use_frameworks!

# Architecture
pod 'ReactorKit'

# Rx
pod 'RxSwift', '~> 3.1'
pod 'RxCocoa', '~> 3.1'
Expand All @@ -17,6 +20,7 @@ target 'RxTodo' do
pod 'Then', '~> 2.1'
pod 'ReusableKit', '~> 1.1'
pod 'CGFloatLiteral', '~> 0.2'
pod 'URLNavigator'

# Testing
target 'RxTodoTests' do
Expand Down
17 changes: 12 additions & 5 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
PODS:
- CGFloatLiteral (0.2.0)
- ManualLayout (1.3.0)
- ReactorKit (0.1.0):
- RxSwift (>= 3.0.0)
- ReusableKit (1.1.0)
- RxCocoa (3.1.0):
- RxSwift (~> 3.1)
- RxDataSources (1.0.0):
- RxCocoa (~> 3.0)
- RxSwift (~> 3.0)
- RxExpect (0.3.0):
- RxExpect (0.5.1):
- RxCocoa (>= 3.0)
- RxSwift (>= 3.0)
- RxTest (>= 3.0)
- RxOptional (3.1.3):
- RxCocoa
- RxSwift
- RxSwift (3.1.0)
- RxTest (3.1.0):
- RxTest (3.2.0):
- RxSwift (~> 3.0)
- SnapKit (3.0.0)
- Then (2.1.0)
- URLNavigator (1.1.2)

DEPENDENCIES:
- CGFloatLiteral (~> 0.2)
- ManualLayout (~> 1.3)
- ReactorKit
- ReusableKit (~> 1.1)
- RxCocoa (~> 3.1)
- RxDataSources (~> 1.0)
Expand All @@ -32,20 +36,23 @@ DEPENDENCIES:
- RxTest (~> 3.1)
- SnapKit (~> 3.0)
- Then (~> 2.1)
- URLNavigator

SPEC CHECKSUMS:
CGFloatLiteral: 5bdcd81cb54b56cd71c4e5e66a33cb86cd51ecbf
ManualLayout: 68ac8cfa6b5f656f7a9fadec3730208b95986880
ReactorKit: b461941775ff25f28b6326b786445b68f9e48dfd
ReusableKit: 89e743a120bab0d95848bff27e481833c2768905
RxCocoa: 50d7564866da9299161e86a263ce12a0873904d8
RxDataSources: 824693e84d00781d0a5e5cedc1ff95ce9250aacd
RxExpect: 93b45e5b313327d3de055c52835a3d2c4da3d8e6
RxExpect: b5b995662f56e8efa3c15a600b187b07f0578b44
RxOptional: b97b59183af80d1e729ac9e51d09a10be668d6a8
RxSwift: 83ff553e7593fdfdcb2562933a64c0284dffdadc
RxTest: 661e33b5022682961784da03cf79c175fcc4bd64
RxTest: 85fdd6f753e8e62635a58d37bbdd3ce7d5abbef3
SnapKit: 98af0a4e9369d3c58f758967518081dbdc7eb1d9
Then: 8496793c8fcac95482b943909b440724c7d8d82c
URLNavigator: 269e73ee727a7cabfa8e510a312bac3884325cc3

PODFILE CHECKSUM: 47ea27ad7edd38a55354e0e31e56dc4ae7bbcfe7
PODFILE CHECKSUM: 60519df89c88988afbfefffcc9293654d3a20bfc

COCOAPODS: 1.1.1
12 changes: 12 additions & 0 deletions RxTodo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
030BC4881D6B5EC700744138 /* TaskEditViewReactorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030BC4871D6B5EC700744138 /* TaskEditViewReactorTests.swift */; };
034AEF111E8BAC28001528E9 /* AlertService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 034AEF101E8BAC28001528E9 /* AlertService.swift */; };
035362FE1E26C8D1005B565E /* ServiceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035362FD1E26C8D1005B565E /* ServiceProvider.swift */; };
035363001E26C8E9005B565E /* TaskService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035362FF1E26C8E9005B565E /* TaskService.swift */; };
035363021E26C9D4005B565E /* UserDefaultsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035363011E26C9D4005B565E /* UserDefaultsService.swift */; };
Expand All @@ -16,6 +17,7 @@
035363091E26D0B8005B565E /* UIViewController+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035363081E26D0B8005B565E /* UIViewController+Rx.swift */; };
038232231E2AAE2C0022E1CE /* MockServiceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038232221E2AAE2C0022E1CE /* MockServiceProvider.swift */; };
038232251E2AAE330022E1CE /* MockUserDefaultsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038232241E2AAE330022E1CE /* MockUserDefaultsService.swift */; };
03A20F961E86E86D0066A057 /* Array+SectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03A20F951E86E86D0066A057 /* Array+SectionModel.swift */; };
03D0C0CC1D26A13E00EE93D5 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D0C0C51D26A13E00EE93D5 /* AppDelegate.swift */; };
03D0C0CD1D26A13E00EE93D5 /* TaskListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D0C0C81D26A13E00EE93D5 /* TaskListViewController.swift */; };
03D0C0D51D26A18900EE93D5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 03D0C0D21D26A18900EE93D5 /* Assets.xcassets */; };
Expand All @@ -33,6 +35,7 @@
03D0C0F81D26C8B100EE93D5 /* TaskEditViewReactor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D0C0F71D26C8B100EE93D5 /* TaskEditViewReactor.swift */; };
03D0C0FB1D26DE2C00EE93D5 /* ObservableConvertibleType+Void.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D0C0FA1D26DE2C00EE93D5 /* ObservableConvertibleType+Void.swift */; };
03D0C0FE1D26E55B00EE93D5 /* RxOperators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D0C0FD1D26E55B00EE93D5 /* RxOperators.swift */; };
03DE44DD1E8D090D00EC791F /* MockAlertService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03DE44DC1E8D090D00EC791F /* MockAlertService.swift */; };
03FB82F61D58BC02004EF4FB /* TaskListViewReactorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03FB82F11D58BC02004EF4FB /* TaskListViewReactorTests.swift */; };
03FB82F91D58BC0F004EF4FB /* MockError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03FB82F81D58BC0F004EF4FB /* MockError.swift */; };
03FB82FB1D591556004EF4FB /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03FB82FA1D591556004EF4FB /* main.swift */; };
Expand All @@ -52,6 +55,7 @@

/* Begin PBXFileReference section */
030BC4871D6B5EC700744138 /* TaskEditViewReactorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskEditViewReactorTests.swift; sourceTree = "<group>"; };
034AEF101E8BAC28001528E9 /* AlertService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertService.swift; sourceTree = "<group>"; };
035362FD1E26C8D1005B565E /* ServiceProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServiceProvider.swift; sourceTree = "<group>"; };
035362FF1E26C8E9005B565E /* TaskService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskService.swift; sourceTree = "<group>"; };
035363011E26C9D4005B565E /* UserDefaultsService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserDefaultsService.swift; sourceTree = "<group>"; };
Expand All @@ -60,6 +64,7 @@
035363081E26D0B8005B565E /* UIViewController+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+Rx.swift"; sourceTree = "<group>"; };
038232221E2AAE2C0022E1CE /* MockServiceProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockServiceProvider.swift; sourceTree = "<group>"; };
038232241E2AAE330022E1CE /* MockUserDefaultsService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockUserDefaultsService.swift; sourceTree = "<group>"; };
03A20F951E86E86D0066A057 /* Array+SectionModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Array+SectionModel.swift"; sourceTree = "<group>"; };
03D0C0AF1D269F7900EE93D5 /* RxTodo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RxTodo.app; sourceTree = BUILT_PRODUCTS_DIR; };
03D0C0C51D26A13E00EE93D5 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
03D0C0C81D26A13E00EE93D5 /* TaskListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskListViewController.swift; sourceTree = "<group>"; };
Expand All @@ -79,6 +84,7 @@
03D0C0F71D26C8B100EE93D5 /* TaskEditViewReactor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskEditViewReactor.swift; sourceTree = "<group>"; };
03D0C0FA1D26DE2C00EE93D5 /* ObservableConvertibleType+Void.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ObservableConvertibleType+Void.swift"; sourceTree = "<group>"; };
03D0C0FD1D26E55B00EE93D5 /* RxOperators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxOperators.swift; sourceTree = "<group>"; };
03DE44DC1E8D090D00EC791F /* MockAlertService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockAlertService.swift; sourceTree = "<group>"; };
03FB82E11D58BBDD004EF4FB /* RxTodoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RxTodoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
03FB82F11D58BC02004EF4FB /* TaskListViewReactorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskListViewReactorTests.swift; sourceTree = "<group>"; };
03FB82F31D58BC02004EF4FB /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -125,6 +131,7 @@
children = (
038232221E2AAE2C0022E1CE /* MockServiceProvider.swift */,
038232241E2AAE330022E1CE /* MockUserDefaultsService.swift */,
03DE44DC1E8D090D00EC791F /* MockAlertService.swift */,
);
path = Services;
sourceTree = "<group>";
Expand Down Expand Up @@ -230,6 +237,7 @@
035363061E26CE45005B565E /* BaseService.swift */,
035363011E26C9D4005B565E /* UserDefaultsService.swift */,
035362FF1E26C8E9005B565E /* TaskService.swift */,
034AEF101E8BAC28001528E9 /* AlertService.swift */,
);
path = Services;
sourceTree = "<group>";
Expand All @@ -239,6 +247,7 @@
children = (
03D0C0F31D26C50100EE93D5 /* Snap.swift */,
03D0C0F11D26C4D900EE93D5 /* String+BoundingRect.swift */,
03A20F951E86E86D0066A057 /* Array+SectionModel.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -528,13 +537,15 @@
03D0C0F21D26C4D900EE93D5 /* String+BoundingRect.swift in Sources */,
03D0C0F41D26C50100EE93D5 /* Snap.swift in Sources */,
03D0C0FE1D26E55B00EE93D5 /* RxOperators.swift in Sources */,
03A20F961E86E86D0066A057 /* Array+SectionModel.swift in Sources */,
03D0C0EA1D26AD2800EE93D5 /* TaskCellReactor.swift in Sources */,
03D0C0FB1D26DE2C00EE93D5 /* ObservableConvertibleType+Void.swift in Sources */,
03D0C0CD1D26A13E00EE93D5 /* TaskListViewController.swift in Sources */,
03D0C0F81D26C8B100EE93D5 /* TaskEditViewReactor.swift in Sources */,
035363021E26C9D4005B565E /* UserDefaultsService.swift in Sources */,
035362FE1E26C8D1005B565E /* ServiceProvider.swift in Sources */,
03D0C0E01D26ABD600EE93D5 /* TaskCell.swift in Sources */,
034AEF111E8BAC28001528E9 /* AlertService.swift in Sources */,
03D0C0CC1D26A13E00EE93D5 /* AppDelegate.swift in Sources */,
03D0C0F61D26C8AB00EE93D5 /* TaskEditViewController.swift in Sources */,
035363071E26CE45005B565E /* BaseService.swift in Sources */,
Expand All @@ -547,6 +558,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
03DE44DD1E8D090D00EC791F /* MockAlertService.swift in Sources */,
03FB82F61D58BC02004EF4FB /* TaskListViewReactorTests.swift in Sources */,
030BC4881D6B5EC700744138 /* TaskEditViewReactorTests.swift in Sources */,
038232231E2AAE2C0022E1CE /* MockServiceProvider.swift in Sources */,
Expand Down
19 changes: 19 additions & 0 deletions RxTodo/Sources/Rx/RxOperators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,22 @@ extension ObservableType {
return self.catchError { _ in .empty() }
}
}


// MARK: - Filter

extension ObservableType {
func filter<O: ObservableType>(_ predicate: O) -> Observable<E> where O.E == Bool {
return self
.withLatestFrom(predicate) { element, predicate in (element, predicate) }
.filter { _, predicate in predicate }
.map { element, _ in element }
}

func filterNot<O: ObservableType>(_ predicate: O) -> Observable<E> where O.E == Bool {
return self
.withLatestFrom(predicate) { element, predicate in (element, predicate) }
.filter { _, predicate in !predicate }
.map { element, _ in element }
}
}
58 changes: 58 additions & 0 deletions RxTodo/Sources/Services/AlertService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// AlertService.swift
// RxTodo
//
// Created by Suyeol Jeon on 29/03/2017.
// Copyright © 2017 Suyeol Jeon. All rights reserved.
//

import UIKit

import RxSwift
import URLNavigator

protocol AlertActionType {
var title: String? { get }
var style: UIAlertActionStyle { get }
}

extension AlertActionType {
var style: UIAlertActionStyle {
return .default
}
}

protocol AlertServiceType: class {
func show<Action: AlertActionType>(
title: String?,
message: String?,
preferredStyle: UIAlertControllerStyle,
actions: [Action]
) -> Observable<Action>
}

final class AlertService: BaseService, AlertServiceType {

func show<Action: AlertActionType>(
title: String?,
message: String?,
preferredStyle: UIAlertControllerStyle,
actions: [Action]
) -> Observable<Action> {
return Observable.create { observer in
let alert = UIAlertController(title: title, message: message, preferredStyle: preferredStyle)
for action in actions {
let alertAction = UIAlertAction(title: action.title, style: action.style) { _ in
observer.onNext(action)
observer.onCompleted()
}
alert.addAction(alertAction)
}
Navigator.present(alert)
return Disposables.create {
alert.dismiss(animated: true, completion: nil)
}
}
}

}
2 changes: 2 additions & 0 deletions RxTodo/Sources/Services/ServiceProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

protocol ServiceProviderType: class {
var userDefaultsService: UserDefaultsServiceType { get }
var alertService: AlertServiceType { get }
var taskService: TaskServiceType { get }
}

final class ServiceProvider: ServiceProviderType {
lazy var userDefaultsService: UserDefaultsServiceType = UserDefaultsService(provider: self)
lazy var alertService: AlertServiceType = AlertService(provider: self)
lazy var taskService: TaskServiceType = TaskService(provider: self)
}
Loading