Skip to content

Commit

Permalink
Merge pull request #354 from ReSwift/private-store-state
Browse files Browse the repository at this point in the history
Removes the ability to directly set `state` by making it `private(set)`. This prevents users from bypassing reducers and middleware. All mutation of the state must occur through the normal `Action` & `Reducer` methods.
This deprecates the usage of `ReSwift-Recorder`. Changes may be made to that library in the future in order to support this change.
  • Loading branch information
Malcolm Jarvis committed Oct 12, 2018
2 parents 4f99933 + 83df438 commit b24ee18
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,11 @@
- The existence of `StandardAction` and `StandardActionConvertible` is somewhat confusing to new users, and does not have a direct use case within the core ReSwift library. Therefore, it has been moved to [ReSwift-Recorder](https://github.com/ReSwift/ReSwift-Recorder) where it belongs.
- If you're using `StandardAction` in your project without `ReSwift-Recorder`, you can copy the old implementation into your project as a middle ground while you migrate away from its usage.

- Make Store's state setter private (#354) - @mokagio

- Removes the ability to directly set `state` by making it `private(set)`. This prevents users from bypassing reducers and middleware. All mutation of the state must occur through the normal `Action` & `Reducer` methods.
- This deprecates the usage of `ReSwift-Recorder`. Changes may be made to that library in the future in order to support this change.

**Other**:
- Add Subscription `skip(when:)` and `only(when:)` (#242) - @mjarvis
- Add `automaticallySkipsRepeats` configuration option to Store initializer (#262) - @DivineDominion
Expand Down
6 changes: 1 addition & 5 deletions ReSwift/CoreTypes/Store.swift
Expand Up @@ -17,11 +17,7 @@ open class Store<State: StateType>: StoreType {

typealias SubscriptionType = SubscriptionBox<State>

// swiftlint:disable todo
// TODO: Setter should not be public; need way for store enhancers to modify appState anyway
// swiftlint:enable todo

/*private (set)*/ public var state: State! {
private(set) public var state: State! {
didSet {
subscriptions.forEach {
if $0.subscriber == nil {
Expand Down
2 changes: 1 addition & 1 deletion ReSwiftTests/StoreDispatchTests.swift
Expand Up @@ -7,7 +7,7 @@
//

import XCTest
import ReSwift
@testable import ReSwift

class StoreDispatchTests: XCTestCase {

Expand Down
2 changes: 1 addition & 1 deletion ReSwiftTests/StoreMiddlewareTests.swift
Expand Up @@ -7,7 +7,7 @@
//

import XCTest
import ReSwift
@testable import ReSwift

let firstMiddleware: Middleware<StateType> = { dispatch, getState in
return { next in
Expand Down

0 comments on commit b24ee18

Please sign in to comment.