-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathTestFakes.swift
95 lines (73 loc) · 2.08 KB
/
TestFakes.swift
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// TestFakes.swift
// ReactiveReSwift
//
// Created by Benji Encz on 12/24/15.
// Copyright © 2015 Benjamin Encz. All rights reserved.
//
import Foundation
import ReactiveReSwift
let dispatchQueue = DispatchQueue.global()
struct NoOpAction: Action {}
struct CounterState {
var count: Int = 0
}
struct TestAppState {
var testValue: Int?
}
struct TestStringAppState {
var testValue: String?
}
struct SetValueAction: StandardActionConvertible {
let value: Int
static let type = "SetValueAction"
init (_ value: Int) {
self.value = value
}
init(_ standardAction: StandardAction) {
self.value = standardAction.payload!["value"] as! Int
}
func toStandardAction() -> StandardAction {
return StandardAction(type: SetValueAction.type,
payload: ["value": value as AnyObject],
isTypedAction: true)
}
}
struct SetValueStringAction: StandardActionConvertible {
var value: String
static let type = "SetValueStringAction"
init (_ value: String) {
self.value = value
}
init(_ standardAction: StandardAction) {
self.value = standardAction.payload!["value"] as! String
}
func toStandardAction() -> StandardAction {
return StandardAction(type: SetValueStringAction.type,
payload: ["value": value as AnyObject],
isTypedAction: true)
}
}
let testReducer: Reducer<TestAppState> = { action, state in
switch action {
case let action as SetValueAction:
return TestAppState(testValue: action.value)
default:
return state
}
}
let testValueStringReducer: Reducer<TestStringAppState> = { action, state in
switch action {
case let action as SetValueStringAction:
return TestStringAppState(testValue: action.value)
default:
return state
}
}
class TestStoreSubscriber<T> {
var receivedStates: [T] = []
var subscription: ((T) -> Void)!
init() {
subscription = { self.receivedStates.append($0) }
}
}