-
Notifications
You must be signed in to change notification settings - Fork 37
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
[Team-13 iOS Neo] redux 구조 변경 #54
Open
HoonHaChoi
wants to merge
3
commits into
codesquad-members-2021:team-13
Choose a base branch
from
ghojeong:ios/feat/198/ReduxArchitecture
base: team-13
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
// | ||
|
||
import UIKit | ||
import KeychainSwift | ||
|
||
final class AppCoordinator: Coordinator { | ||
|
||
|
@@ -17,9 +16,15 @@ final class AppCoordinator: Coordinator { | |
var tabBarCoordinatorFactory: ((UINavigationController) -> TabBarCoordinator) | ||
} | ||
|
||
private let loginCoordinator: LoginViewCoordinator | ||
struct TokenState { | ||
var token: TokenAction = .initial | ||
} | ||
|
||
private var loginCoordinator: LoginViewCoordinator | ||
private let tabBarCoordinator: TabBarCoordinator | ||
|
||
var dispatch: ((TokenAction) -> Void)? | ||
|
||
init(navigation: UINavigationController = UINavigationController(), | ||
dependency: Dependency) { | ||
self.navigation = navigation | ||
|
@@ -29,32 +34,32 @@ final class AppCoordinator: Coordinator { | |
} | ||
|
||
func loadInitalView() { | ||
if isEmptyToken() { | ||
dispatch?(.initial) | ||
} | ||
|
||
func update(with state: TokenState) { | ||
switch state.token { | ||
case .empty: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 비동기적인 콜백함수를 처리하는 방식에 대해서 공부하셨으면 좋겠습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 switch 문이 아닌 비동기 콜백으로 고쳐보도록하겠습니다 강운 혹시 이 부분에 대해 문제점이 무엇인가요?? |
||
showLoginFlow() | ||
} else { | ||
case .existent, .completed: | ||
showTabBarFlow() | ||
case .initial: | ||
break | ||
} | ||
} | ||
|
||
private func showLoginFlow() { | ||
loginCoordinator.delegate = self | ||
loginCoordinator.authenticated = dispatch | ||
loginCoordinator.loadInitalView() | ||
} | ||
|
||
private func showTabBarFlow() { | ||
tabBarCoordinator.loadInitalView() | ||
} | ||
|
||
private func isEmptyToken() -> Bool { | ||
guard let toggle = KeychainSwift().get("token")?.isEmpty else { | ||
return true | ||
} | ||
return toggle | ||
} | ||
} | ||
|
||
extension AppCoordinator: LoginViewCoordinatorDelegate { | ||
func completeLogin() { | ||
showTabBarFlow() | ||
extension AppCoordinator.TokenState { | ||
init(state: AppStore.State) { | ||
token = state.token | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
mobile/issue-tracker/issue-tracker/Coordinator/AppStore.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// AppStore.swift | ||
// issue-tracker | ||
// | ||
// Created by HOONHA CHOI on 2021/07/26. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
import KeychainSwift | ||
|
||
final class AppStore { | ||
|
||
struct State { | ||
var token: TokenAction = .initial | ||
} | ||
|
||
struct Reducer { | ||
func reduce(action: TokenAction, state: inout State) { | ||
switch action { | ||
case .initial: | ||
state.token = (KeychainSwift().get("token")?.isEmpty ?? true) ? .empty : .existent | ||
case .empty: | ||
state.token = .empty | ||
case .completed, .existent: | ||
state.token = .existent | ||
} | ||
} | ||
} | ||
|
||
private var reducer: Reducer { | ||
return Reducer() | ||
} | ||
|
||
@Published private(set) var state: State | ||
private var cancellable: AnyCancellable? | ||
|
||
var updateState: ((AppCoordinator.TokenState) -> Void)? | ||
|
||
init(state: State) { | ||
self.state = state | ||
cancellable = $state.sink(receiveValue: { [weak self] state in | ||
self?.updateState?(AppCoordinator.TokenState(token: state.token)) | ||
}) | ||
} | ||
|
||
func dispatch(_ action: TokenAction) { | ||
reducer.reduce(action: action, state: &state) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
mobile/issue-tracker/issue-tracker/Coordinator/TokenAction.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// AppAction.swift | ||
// issue-tracker | ||
// | ||
// Created by HOONHA CHOI on 2021/07/26. | ||
// | ||
|
||
import Foundation | ||
|
||
enum TokenAction { | ||
case initial | ||
case empty | ||
case existent | ||
case completed | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
결과의 차이는 없겠지만, 엑션을 방출하는 건 외부에서 호출하는게 아닌 자기 자신이 해야할 의무같습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이것또한 바꿔 보도록 하겠습니다