-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestDatasource.swift
More file actions
47 lines (40 loc) · 1.79 KB
/
TestDatasource.swift
File metadata and controls
47 lines (40 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import Foundation
import DataSourcerer
internal extension ValueStream {
internal init<Value, P: ResourceParams>(
testStates states: [ResourceState<Value, P, TestStateError>],
testError: TestStateError,
loadImpulseEmitter: AnyLoadImpulseEmitter<P>) where ObservedValue == ResourceState<Value, P, TestStateError> {
self.init(
makeStatesWithClosure: { loadImpulse, sendState -> Disposable in
if let state = states.first(where: { $0.loadImpulse == loadImpulse }) {
sendState(state)
} else {
let errorState = ResourceState<Value, P, TestStateError>.error(
error: testError,
loadImpulse: loadImpulse,
fallbackValueBox: nil
)
sendState(errorState)
}
return VoidDisposable()
},
loadImpulseEmitter: loadImpulseEmitter
)
}
}
struct OneTwoThreeStringTestStates {
public static var oneTwoThreeStringStates: [ResourceState<String, String, TestStateError>] = {
return [
ResourceState.value(valueBox: EquatableBox("1"),
loadImpulse: LoadImpulse(params: "1", type: .initial),
fallbackError: nil),
ResourceState.value(valueBox: EquatableBox("2"),
loadImpulse: LoadImpulse(params: "2", type: LoadImpulseType(mode: .fullRefresh, issuer: .user)),
fallbackError: nil),
ResourceState.value(valueBox: EquatableBox("3"),
loadImpulse: LoadImpulse(params: "3", type: LoadImpulseType(mode: .fullRefresh, issuer: .user)),
fallbackError: nil)
]
}()
}