Skip to content

Commit

Permalink
fix: Commented out code that is not necessary with comments
Browse files Browse the repository at this point in the history
  • Loading branch information
andrej.jasso@goodrequest.com committed Aug 10, 2021
1 parent 085a369 commit 6dc44f7
Show file tree
Hide file tree
Showing 25 changed files with 1,719 additions and 452 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ final class ___VARIABLE_ID___Factory {

enum SectionType: Int {

case first = 0
case second = 1
// Sample section types
//
// case first = 0
// case second = 1

}

Expand All @@ -31,15 +33,17 @@ final class ___VARIABLE_ID___Factory {

}

var title: String? {
switch type {
case .first:
return "First"

case .second:
return "Second"
}
}
// Sample title
//
// var title: String? {
// switch type {
// case .first:
// return "First"
//
// case .second:
// return "Second"
// }
// }

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ final class ___VARIABLE_ID___LayoutComposer {
heightDimension: CGFloat
) -> UICollectionViewCompositionalLayout {
return UICollectionViewCompositionalLayout { [unowned provider] index, _ -> NSCollectionLayoutSection? in
switch provider.sections[index].type {
case .first:
return self.prepareFirstSection()

case .second:
return self.prepareSecondSection()
}
// Use factory sections to switch over
//
// switch provider.sections[index].type {
// case .first:
// return self.prepareFirstSection()
//
// case .second:
// return self.prepareSecondSection()
// }
}
}

Expand All @@ -47,44 +49,46 @@ final class ___VARIABLE_ID___LayoutComposer {

private extension ___VARIABLE_ID___LayoutComposer {

func prepareFirstSection() -> NSCollectionLayoutSection {
let itemSize = NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1.0),
heightDimension: .absolute(230)
)
let item = NSCollectionLayoutItem(layoutSize: itemSize)

let group = NSCollectionLayoutGroup.horizontal(
layoutSize: itemSize,
subitem: item,
count: 1
)

let section = NSCollectionLayoutSection(group: group)
section.interGroupSpacing = 16.0
section.contentInsets = C.defaultContentInsets

return section
}

func prepareSecondSection() -> NSCollectionLayoutSection {
let itemSize = NSCollectionLayoutSize(
widthDimension: .absolute(80.0),
heightDimension: .absolute(80.0)
)

let item = NSCollectionLayoutItem(layoutSize: itemSize)

let group = NSCollectionLayoutGroup.horizontal(
layoutSize: itemSize,
subitems: [item]
)
let section = NSCollectionLayoutSection(group: group)
section.interGroupSpacing = 8
section.contentInsets = C.defaultContentInsets
section.orthogonalScrollingBehavior = .continuous

return section
}
// Sample section layouts
//
// func prepareFirstSection() -> NSCollectionLayoutSection {
// let itemSize = NSCollectionLayoutSize(
// widthDimension: .fractionalWidth(1.0),
// heightDimension: .absolute(230)
// )
// let item = NSCollectionLayoutItem(layoutSize: itemSize)
//
// let group = NSCollectionLayoutGroup.horizontal(
// layoutSize: itemSize,
// subitem: item,
// count: 1
// )
//
// let section = NSCollectionLayoutSection(group: group)
// section.interGroupSpacing = 16.0
// section.contentInsets = C.defaultContentInsets
//
// return section
// }
//
// func prepareSecondSection() -> NSCollectionLayoutSection {
// let itemSize = NSCollectionLayoutSize(
// widthDimension: .absolute(80.0),
// heightDimension: .absolute(80.0)
// )
//
// let item = NSCollectionLayoutItem(layoutSize: itemSize)
//
// let group = NSCollectionLayoutGroup.horizontal(
// layoutSize: itemSize,
// subitems: [item]
// )
// let section = NSCollectionLayoutSection(group: group)
// section.interGroupSpacing = 8
// section.contentInsets = C.defaultContentInsets
// section.orthogonalScrollingBehavior = .continuous
//
// return section
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,26 @@ private extension ___VARIABLE_ID___ViewController {
extension ___VARIABLE_ID___ViewController {

func bindState(reactor: ___VARIABLE_ID___ViewModel) {

reactor.state
.map { $0.dataFetchingState }
.removeDuplicates()
.sink { [weak self] state in
switch state {
case .idle:
self?.showIdleState()

case .loading:
self?.showLoadingState()

case .failure(let error):
self?.showErrorState(error: error)

case .empty:
self?.showEmptyState()
}
// Switch over data fetching states to handle
//
// switch state {
// case .idle:
// self?.showIdleState()
//
// case .loading:
// self?.showLoadingState()
//
// case .failure(let error):
// self?.showErrorState(error: error)
//
// case .empty:
// self?.showEmptyState()
// }
}
.store(in: &cancellables)

Expand All @@ -141,25 +144,27 @@ extension ___VARIABLE_ID___ViewController {

extension ___VARIABLE_ID___ViewController {

func showIdleState() {
collectionView.refreshControl?.endCurrentRefreshing()
}

func showLoadingState() {

}

func showErrorState(error: AppError) {
collectionView.refreshControl?.endCurrentRefreshing()
if viewModel.currentState.sections.isEmpty {

} else {

}
}

func showEmptyState() {
collectionView.refreshControl?.endCurrentRefreshing()
}
// Sample state handling functions
//
// func updateToIdleState() {
// collectionView.refreshControl?.endCurrentRefreshing()
// }
//
// func updateToLoadingState() {
//
// }
//
// func updateToErrorState(error: AppError) {
// collectionView.refreshControl?.endCurrentRefreshing()
// if viewModel.currentState.sections.isEmpty {
//
// } else {
//
// }
// }
//
// func updateToEmptyState() {
// collectionView.refreshControl?.endCurrentRefreshing()
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,30 @@ final class ___VARIABLE_ID___ViewModel: GoodReactor {

enum DataFetchingState: Equatable {

case idle
case loading
case failure(AppError)
case empty
// Sample data fetching states
//
// case idle
// case loading
// case failure(AppError)
// case empty

}

enum Action {

case refreshData
// Sample actions
//
// case refreshData

}

enum Mutation {

case didFetchData(String)
case didFailFetchingData(AppError)
case didStartLoadingData
// Sample mutations
//
// case didFetchData(String)
// case didFailFetchingData(AppError)
// case didStartLoadingData

}

Expand Down Expand Up @@ -73,10 +79,13 @@ final class ___VARIABLE_ID___ViewModel: GoodReactor {
extension ___VARIABLE_ID___ViewModel {

func navigate(action: Action) -> AppStep? {
switch action {
case .refreshData:
return nil
}
return nil
// Use switch over action when handling more than one action
//
// switch action {
// case .refreshData:
// return nil
// }
}

}
Expand All @@ -85,56 +94,67 @@ extension ___VARIABLE_ID___ViewModel {

extension ___VARIABLE_ID___ViewModel {

func transform(mutation: AnyPublisher<Mutation, Never>) -> AnyPublisher<Mutation, Never> {
return mutation
.merge(with: fetchData(requestManager: di.requestManager))
.eraseToAnyPublisher()
}
// Use transform mutation to call a data fetching mutation on view model init ( Prefeching data before UI loads )
//
// func transform(mutation: AnyPublisher<Mutation, Never>) -> AnyPublisher<Mutation, Never> {
// return mutation
// .merge(with: fetchData(requestManager: di.requestManager))
// .eraseToAnyPublisher()
// }

func mutate(action: Action) -> AnyPublisher<Mutation, Never> {
switch action {
case .refreshData:
return fetchData(requestManager: di.requestManager)
}
return Empty().eraseToAnyPublisher()
// User switch over actions when using more than one action
//
// switch action {
// case .refreshData:
// return fetchData(requestManager: di.requestManager)
// }
}

func reduce(state: State, mutation: Mutation) -> State {
var state = state

switch mutation {
case .didFetchData(let dataResponse):
state.dataResponse = dataResponse
state.dataFetchingState = .idle
state = updateSections(state: state)

case .didFailFetchingData(let error):
state.dataFetchingState = .failure(error)

case .didStartLoadingData:
state.dataFetchingState = .loading
}
// Switch over mutations when using more than one mutation
//
// switch mutation {
// case .didFetchData(let dataResponse):
// state.dataResponse = dataResponse
// state.dataFetchingState = .idle
// state = updateSections(state: state)
//
// case .didFailFetchingData(let error):
// state.dataFetchingState = .failure(error)
//
// case .didStartLoadingData:
// state.dataFetchingState = .loading
// }

return state
}

private func updateSections(state: State) -> State {
var newState = state

newState.sections = factory.makeSections(for: state.dataResponse)
newState.dataFetchingState = state.sections.isEmpty ? .empty : .idle

return newState
}
// Use function to handle repetitive section updates
//
// private func updateSections(state: State) -> State {
// var newState = state
//
// newState.sections = factory.makeSections(for: state.dataResponse)
// newState.dataFetchingState = state.sections.isEmpty ? .empty : .idle
//
// return newState
// }

}

// MARK: - Private

private extension ___VARIABLE_ID___ViewModel {

func fetchData(requestManager: RequestManagerType) -> AnyPublisher<Mutation, Never> {
return Just(Mutation.didStartLoadingData)
.eraseToAnyPublisher()
}
// Use a separate function to handle data fetching
//
// func fetchData(requestManager: RequestManagerType) -> AnyPublisher<Mutation, Never> {
// return Just(Mutation.didStartLoadingData)
// .eraseToAnyPublisher()
// }

}
Loading

0 comments on commit 6dc44f7

Please sign in to comment.