Skip to content

Commit 1115a25

Browse files
committed
[Dependencies] Update Router to Work with ReSwift 0.2.4
- Also add a Changelog
1 parent 457930e commit 1115a25

File tree

6 files changed

+55
-14
lines changed

6 files changed

+55
-14
lines changed

Changelog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#Upcoming Release
2+
3+
#0.2.4
4+
5+
*Released: 01/23/2015*
6+
7+
**Other:**
8+
9+
- Due to the new requirement in ReSwift, that top level reducers need to be able to take an empty application state and return a hydrated one, `NavigationReducer` is no longer a top-level reducer. You now need to call it from within your app reducer. Refer to the docs for more details. - @Ben-G
10+
- Drop iOS Deployment target to 8.0 - @Ben-G
11+
- Add Support for watchOS, tvOS, OSX - @Ben-G
12+
- Documentation updates - @Ben-G

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,22 @@ After you've initialized your store, create an instance of `Router`, passing in
6363
router = Router(store: mainStore, rootRoutable: RootRoutable(routable: rootViewController))
6464
```
6565

66-
We'll discuss `Routable` in the next section.
66+
We'll discuss `Routable` in the next main section.
67+
68+
##Calling the Navigation Reducer
69+
70+
The `NavigationReducer` is provided as part of `ReSwiftRouter`. You need to call it from within your top-level reducer. Here's a simple example from the specs:
71+
72+
```swift
73+
struct AppReducer: Reducer {
74+
func handleAction(action: Action, state: FakeAppState?) -> FakeAppState {
75+
return FakeAppState(
76+
navigationState: NavigationReducer.handleAction(action, state: state?.navigationState)
77+
)
78+
}
79+
}
80+
```
81+
This will reducer will handle all routing relevant actions.
6782

6883
#Implementing `Routable`
6984

ReSwiftRouter/NavigationReducer.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88

99
import ReSwift
1010

11-
public struct NavigationReducer: Reducer {
11+
/**
12+
The Navigation Reducer handles the state slice concerned with storing the current navigation
13+
information. Note, that this reducer is **not** a *top-level* reducer, you need to use it within
14+
another reducer and pass in the relevant state slice. Take a look at the specs to see an
15+
example set up.
16+
*/
17+
public struct NavigationReducer {
1218

13-
public init() {}
19+
public static func handleAction(action: Action, state: NavigationState?) -> NavigationState {
20+
let state = state ?? NavigationState()
1421

15-
public func handleAction(state: HasNavigationState, action: Action) -> HasNavigationState {
1622
switch action {
1723
case let action as SetRouteAction:
1824
return setRoute(state, route: action.route)
@@ -23,10 +29,10 @@ public struct NavigationReducer: Reducer {
2329
return state
2430
}
2531

26-
func setRoute(var state: HasNavigationState, route: [RouteElementIdentifier]) -> HasNavigationState {
27-
state.navigationState.route = route
32+
static func setRoute(var state: NavigationState, route: [RouteElementIdentifier]) -> NavigationState {
33+
state.route = route
2834

2935
return state
3036
}
3137

32-
}
38+
}

ReSwiftRouter/NavigationState.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ public struct NavigationState {
1919

2020
public protocol HasNavigationState {
2121
var navigationState: NavigationState { get set }
22-
}
22+
}

ReSwiftRouter/Router.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import ReSwift
1111

1212
public class Router<State: StateType>: StoreSubscriber {
1313

14-
var store: MainStore<State>
14+
var store: Store<State>
1515
var lastNavigationState = NavigationState()
1616
var routables: [Routable] = []
1717
let waitForRoutingCompletionQueue = dispatch_queue_create("WaitForRoutingCompletionQueue", nil)
1818

19-
public init(store: MainStore<State>, rootRoutable: Routable) {
19+
public init(store: Store<State>, rootRoutable: Routable) {
2020
self.store = store
2121
self.routables.append(rootRoutable)
2222

ReSwiftRouterTests/ReSwiftRouterIntegrationTests.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,16 @@ struct FakeAppState: StateType, HasNavigationState {
3939
}
4040

4141
class FakeReducer: Reducer {
42-
func handleAction(state: FakeAppState, action: Action) -> FakeAppState {
43-
return state
42+
func handleAction(action: Action, state: FakeAppState?) -> FakeAppState {
43+
return state ?? FakeAppState()
44+
}
45+
}
46+
47+
struct AppReducer: Reducer {
48+
func handleAction(action: Action, state: FakeAppState?) -> FakeAppState {
49+
return FakeAppState(
50+
navigationState: NavigationReducer.handleAction(action, state: state?.navigationState)
51+
)
4452
}
4553
}
4654

@@ -50,10 +58,10 @@ class SwiftFlowRouterIntegrationTests: QuickSpec {
5058

5159
describe("routing calls") {
5260

53-
var store: MainStore<FakeAppState>!
61+
var store: Store<FakeAppState>!
5462

5563
beforeEach {
56-
store = MainStore(reducer: CombinedReducer([NavigationReducer()]), state: FakeAppState())
64+
store = Store(reducer: CombinedReducer([AppReducer()]), state: FakeAppState())
5765
}
5866

5967
describe("setup") {

0 commit comments

Comments
 (0)