Skip to content

Commit 9051b2a

Browse files
author
Валерий Коканов
committed
Live update
1 parent 6718d31 commit 9051b2a

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

ExchangerApp.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
4FBE40B721BECCFF60A44784 /* Pods_ExchangerApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B5E1546233581A529E4B6AE /* Pods_ExchangerApp.framework */; };
1111
EF1BC2662131A74500185884 /* IntervalRunner.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF1BC2652131A74500185884 /* IntervalRunner.swift */; };
1212
EF1C3206213CF53800E4D97E /* RatesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF1C3205213CF53800E4D97E /* RatesView.swift */; };
13+
EF48649F21416532002BEAA4 /* Store+Dispatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF48649E21416532002BEAA4 /* Store+Dispatch.swift */; };
1314
EF6C413A21280C900094675B /* MainStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF6C413921280C900094675B /* MainStore.swift */; };
1415
EF6C413C21280CA20094675B /* MainReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF6C413B21280CA20094675B /* MainReducer.swift */; };
1516
EF6C413E21280CAC0094675B /* MainState.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF6C413D21280CAC0094675B /* MainState.swift */; };
@@ -40,6 +41,7 @@
4041
505A1DEC03414F45E6085B4C /* Pods-ExchangerApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExchangerApp.release.xcconfig"; path = "Pods/Target Support Files/Pods-ExchangerApp/Pods-ExchangerApp.release.xcconfig"; sourceTree = "<group>"; };
4142
EF1BC2652131A74500185884 /* IntervalRunner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntervalRunner.swift; sourceTree = "<group>"; };
4243
EF1C3205213CF53800E4D97E /* RatesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RatesView.swift; sourceTree = "<group>"; };
44+
EF48649E21416532002BEAA4 /* Store+Dispatch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Store+Dispatch.swift"; sourceTree = "<group>"; };
4345
EF6C413921280C900094675B /* MainStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainStore.swift; sourceTree = "<group>"; };
4446
EF6C413B21280CA20094675B /* MainReducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainReducer.swift; sourceTree = "<group>"; };
4547
EF6C413D21280CAC0094675B /* MainState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainState.swift; sourceTree = "<group>"; };
@@ -149,6 +151,7 @@
149151
EF6C4146212811760094675B /* MainStoreLogger.swift */,
150152
EF6C415C2129C7B80094675B /* Result+Get.swift */,
151153
EF8B0D21212DCF9E00AEFC58 /* Bundle+Dictionary.swift */,
154+
EF48649E21416532002BEAA4 /* Store+Dispatch.swift */,
152155
);
153156
path = ExchangerApp;
154157
sourceTree = "<group>";
@@ -294,6 +297,7 @@
294297
EF6C4168212B06510094675B /* RatesService.swift in Sources */,
295298
EF6C416C212B09080094675B /* Translator.swift in Sources */,
296299
EF6C415B2129B7810094675B /* RatesState.swift in Sources */,
300+
EF48649F21416532002BEAA4 /* Store+Dispatch.swift in Sources */,
297301
EF6C413C21280CA20094675B /* MainReducer.swift in Sources */,
298302
EF6C414D212838890094675B /* RatesCell.swift in Sources */,
299303
EF6C414321280EDB0094675B /* RatesReducer.swift in Sources */,

ExchangerApp/Rates/RatesActions.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ extension RatesActions {
5252
.flatMap(translator.translate(from:))
5353
.subscribeOn(ConcurrentMainScheduler.instance)
5454
.subscribe(
55-
onNext: { [value] in mainStore.dispatch(UpdateTableAction(rates: $0, value: value)) },
56-
onError: { mainStore.dispatch(PresentableAction(viewState: .failure(.underlyingError($0)))) }
55+
onNext: { [value] in mainStore.dispatch(action: UpdateTableAction(rates: $0, value: value)) },
56+
onError: { mainStore.dispatch(action: PresentableAction(viewState: .failure(.underlyingError($0)))) }
5757
).disposed(by: disposeBag)
5858
}
5959
}
@@ -74,7 +74,7 @@ extension RatesActions {
7474
else { return }
7575
rates.remove(at: index)
7676
rates.insert(selectedRate, at: 0)
77-
mainStore.dispatch(PresentableAction(viewState: .success(rates)))
77+
mainStore.dispatch(action: PresentableAction(viewState: .success(rates)))
7878
}
7979
}
8080

@@ -98,16 +98,16 @@ extension RatesActions {
9898
guard
9999
!existedRates.isEmpty
100100
else {
101-
mainStore.dispatch(PresentableAction(viewState: .success(newRates)))
101+
mainStore.dispatch(action: PresentableAction(viewState: .success(newRates)))
102102
return
103103
}
104104
var tableRates = zip(newRates, existedRates).map { (arg: (newRate: Rate, exRate: Rate)) -> Rate in
105105
var rate = arg.exRate
106106
rate.value = block(arg.newRate.rate * self.value)
107107
return rate
108108
}
109-
tableRates[0].value = block(value)
110-
mainStore.dispatch(PresentableAction(viewState: .success(tableRates)))
109+
tableRates[0] = existedRates[0] // avoid reloading first row
110+
mainStore.dispatch(action: PresentableAction(viewState: .success(tableRates)))
111111
}
112112
}
113113

ExchangerApp/Rates/RatesService.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class RatesService {
1818
urlWithParameters.queryItems = [URLQueryItem(name: "base", value: currency)]
1919
return session.rx
2020
.data(request: .init(url: urlWithParameters.url!))
21+
.takeLast(1)
2122
.flatMap(translator.translate(from:))
2223
}
2324
}

ExchangerApp/Rates/RatesViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class RatesViewController: UIViewController {
5656
intervalRunner.start()
5757
},
5858
changeValue: { rate, value in
59+
mainStore.dispatch(action: RatesActions.fetch(currency: rate.title, count: value).action())
5960
intervalRunner.stop()
60-
dispatcher(RatesActions.select(rate).action())
6161
self.intervalRunner.set(action: .fetch(currency: rate.title, count: value))
6262
intervalRunner.start()
6363
}
@@ -75,7 +75,7 @@ class RatesViewController: UIViewController {
7575

7676
private lazy var controlProperty: (Rate, Observable<String?>) -> Void = { [ratesView, disposeBag] rate, property in
7777
property
78-
.debounce(1.5, scheduler: MainScheduler.instance)
78+
.debounce(0.5, scheduler: ConcurrentMainScheduler.instance)
7979
.map { $0 ?? "" }
8080
.distinctUntilChanged()
8181
.filter { !$0.isEmpty }

ExchangerApp/Store+Dispatch.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import ReSwift
2+
3+
extension Store {
4+
func dispatch(action: Action, in queue: DispatchQueue = .main) {
5+
queue.async {
6+
mainStore.dispatch(action)
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)