Skip to content

Commit

Permalink
Merge branch 'master' into mjarvis/mutable-middleware
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
Malcolm Jarvis committed Sep 27, 2019
2 parents ba117f8 + 5d493c9 commit 68b3edd
Show file tree
Hide file tree
Showing 26 changed files with 76 additions and 31 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
**API Changes:**
- Add capability to mutate `Middleware` after store creation. (#) - @mjarvis

**Other:**
- Make isDispatching of Store atomic (#341) - @zhongwuzw

# 5.0.0

*Released: 2019-06-30*
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ This repository contains the core component for ReSwift, the following extension

## Production Apps with Open Source Code

- [Product Hunt for OS X](https://github.com/producthunt/producthunt-osx) Official Product Hunt client for OS X.
- [Persephone](https://github.com/danbee/persephone), a MPD music player daemon controller for macOS
- [Product Hunt for OS X](https://github.com/producthunt/producthunt-osx) Official Product Hunt client for macOS

# Contributing

Expand Down
14 changes: 12 additions & 2 deletions ReSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
objects = {

/* Begin PBXBuildFile section */
0E1E565A2099A42E00959ADB /* AtomicBool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E1E56592099A42E00959ADB /* AtomicBool.swift */; };
0E1E565B2099A44100959ADB /* AtomicBool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E1E56592099A42E00959ADB /* AtomicBool.swift */; };
0E1E565C2099A44200959ADB /* AtomicBool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E1E56592099A42E00959ADB /* AtomicBool.swift */; };
0E1E565D2099A44300959ADB /* AtomicBool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E1E56592099A42E00959ADB /* AtomicBool.swift */; };
252982EE1C4FD21400281098 /* StoreType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 252982ED1C4FD21400281098 /* StoreType.swift */; };
252982EF1C4FD21400281098 /* StoreType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 252982ED1C4FD21400281098 /* StoreType.swift */; };
252982F01C4FD21400281098 /* StoreType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 252982ED1C4FD21400281098 /* StoreType.swift */; };
Expand Down Expand Up @@ -127,6 +131,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
0E1E56592099A42E00959ADB /* AtomicBool.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AtomicBool.swift; sourceTree = "<group>"; };
252982ED1C4FD21400281098 /* StoreType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoreType.swift; sourceTree = "<group>"; };
259737E91C2C611600869B8F /* StoreMiddlewareTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoreMiddlewareTests.swift; sourceTree = "<group>"; };
259737FA1C2C618A00869B8F /* TestFakes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestFakes.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -314,6 +319,7 @@
73E545D41D22BC3900D114E8 /* Assertions.swift */,
625E66B11C1FFC830027C288 /* Coding.swift */,
625E66B21C1FFC830027C288 /* TypeHelper.swift */,
0E1E56592099A42E00959ADB /* AtomicBool.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -531,7 +537,7 @@
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = "Benjamin Encz";
ORGANIZATIONNAME = "ReSwift Community";
TargetAttributes = {
25DBCF361C30BF2B00D63A58 = {
CreatedOnToolsVersion = 7.2;
Expand Down Expand Up @@ -682,7 +688,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"$SRCROOT/BuildPhases/run-swiftlint\"";
shellScript = "\"$SRCROOT/BuildPhases/run-swiftlint\"\n";
};
73E545D31D22B0D600D114E8 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
Expand Down Expand Up @@ -712,6 +718,7 @@
252982F11C4FD21400281098 /* StoreType.swift in Sources */,
73E545D81D22BC3900D114E8 /* Assertions.swift in Sources */,
81BCBED11C63167A00AA4F03 /* Subscription.swift in Sources */,
0E1E565D2099A44300959ADB /* AtomicBool.swift in Sources */,
25DBCF451C30C16000D63A58 /* StoreSubscriber.swift in Sources */,
25DBCF461C30C16000D63A58 /* Middleware.swift in Sources */,
25DBCF471C30C16000D63A58 /* Coding.swift in Sources */,
Expand All @@ -731,6 +738,7 @@
252982F01C4FD21400281098 /* StoreType.swift in Sources */,
73E545D71D22BC3900D114E8 /* Assertions.swift in Sources */,
81BCBED01C63167A00AA4F03 /* Subscription.swift in Sources */,
0E1E565C2099A44200959ADB /* AtomicBool.swift in Sources */,
25DBCF5C1C30C19500D63A58 /* StoreSubscriber.swift in Sources */,
25DBCF5D1C30C19500D63A58 /* Middleware.swift in Sources */,
25DBCF5E1C30C19500D63A58 /* Coding.swift in Sources */,
Expand Down Expand Up @@ -767,6 +775,7 @@
252982EF1C4FD21400281098 /* StoreType.swift in Sources */,
73E545D61D22BC3900D114E8 /* Assertions.swift in Sources */,
81BCBECF1C63167A00AA4F03 /* Subscription.swift in Sources */,
0E1E565B2099A44100959ADB /* AtomicBool.swift in Sources */,
25DBCF981C30C4F000D63A58 /* StoreSubscriber.swift in Sources */,
25DBCF991C30C4F000D63A58 /* Middleware.swift in Sources */,
25DBCF9A1C30C4F000D63A58 /* Coding.swift in Sources */,
Expand Down Expand Up @@ -811,6 +820,7 @@
259737FD1C2C661100869B8F /* Middleware.swift in Sources */,
252982EE1C4FD21400281098 /* StoreType.swift in Sources */,
73E545D51D22BC3900D114E8 /* Assertions.swift in Sources */,
0E1E565A2099A42E00959ADB /* AtomicBool.swift in Sources */,
81BCBECE1C63167A00AA4F03 /* Subscription.swift in Sources */,
625E66BE1C1FFC880027C288 /* Reducer.swift in Sources */,
625E66B41C1FFC830027C288 /* TypeHelper.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion ReSwift/CoreTypes/Action.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ReSwift
//
// Created by Benjamin Encz on 12/14/15.
// Copyright © 2015 Benjamin Encz. All rights reserved.
// Copyright © 2015 ReSwift Community. All rights reserved.
//

/// All actions that want to be able to be dispatched to a store need to conform to this protocol
Expand Down
2 changes: 2 additions & 0 deletions ReSwift/CoreTypes/DispatchingStoreType.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright © 2019 ReSwift Community. All rights reserved.

import Foundation

/**
Expand Down
2 changes: 1 addition & 1 deletion ReSwift/CoreTypes/Middleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ReSwift
//
// Created by Benji Encz on 12/24/15.
// Copyright © 2015 Benjamin Encz. All rights reserved.
// Copyright © 2015 ReSwift Community. All rights reserved.
//

public typealias DispatchFunction = (Action) -> Void
Expand Down
2 changes: 1 addition & 1 deletion ReSwift/CoreTypes/Reducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ReSwift
//
// Created by Benjamin Encz on 12/14/15.
// Copyright © 2015 Benjamin Encz. All rights reserved.
// Copyright © 2015 ReSwift Community. All rights reserved.
//

public typealias Reducer<ReducerStateType> =
Expand Down
2 changes: 1 addition & 1 deletion ReSwift/CoreTypes/State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ReSwift
//
// Created by Benjamin Encz on 12/14/15.
// Copyright © 2015 Benjamin Encz. All rights reserved.
// Copyright © 2015 ReSwift Community. All rights reserved.
//

public protocol StateType { }
12 changes: 6 additions & 6 deletions ReSwift/CoreTypes/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// ReSwift
//
// Created by Benjamin Encz on 11/11/15.
// Copyright © 2015 DigiTales. All rights reserved.
// Copyright © 2015 ReSwift Community. All rights reserved.
//

/**
This class is the default implementation of the `Store` protocol. You will use this store in most
This class is the default implementation of the `StoreType` protocol. You will use this store in most
of your applications. You shouldn't need to implement your own store.
You initialize the store with a reducer and an initial application state. If your app has multiple
reducers you can combine them by initializng a `MainReducer` with all of your reducers as an
Expand Down Expand Up @@ -35,7 +35,7 @@ open class Store<State: StateType>: StoreType {

var subscriptions: Set<SubscriptionType> = []

private var isDispatching = false
private var isDispatching = AtomicBool()

/// Indicates if new subscriptions attempt to apply `skipRepeats`
/// by default.
Expand Down Expand Up @@ -156,7 +156,7 @@ open class Store<State: StateType>: StoreType {

// swiftlint:disable:next identifier_name
open func _defaultDispatch(action: Action) {
guard !isDispatching else {
guard !isDispatching.value else {
raiseFatalError(
"ReSwift:ConcurrentMutationError- Action has been dispatched while" +
" a previous action is action is being processed. A reducer" +
Expand All @@ -165,9 +165,9 @@ open class Store<State: StateType>: StoreType {
)
}

isDispatching = true
isDispatching.value = true
let newState = reducer(action, state)
isDispatching = false
isDispatching.value = false

state = newState
}
Expand Down
4 changes: 2 additions & 2 deletions ReSwift/CoreTypes/StoreSubscriber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
// ReSwift
//
// Created by Benjamin Encz on 12/14/15.
// Copyright © 2015 Benjamin Encz. All rights reserved.
// Copyright © 2015 ReSwift Community. All rights reserved.
//

public protocol AnyStoreSubscriber: class {
public protocol AnyStoreSubscriber: AnyObject {
// swiftlint:disable:next identifier_name
func _newState(state: Any)
}
Expand Down
2 changes: 1 addition & 1 deletion ReSwift/CoreTypes/StoreType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ReSwift
//
// Created by Benjamin Encz on 11/28/15.
// Copyright © 2015 DigiTales. All rights reserved.
// Copyright © 2015 ReSwift Community. All rights reserved.
//

/**
Expand Down
2 changes: 1 addition & 1 deletion ReSwift/CoreTypes/Subscription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ReSwift
//
// Created by Virgilio Favero Neto on 4/02/2016.
// Copyright © 2016 Benjamin Encz. All rights reserved.
// Copyright © 2016 ReSwift Community. All rights reserved.
//

/// A box around subscriptions and subscribers.
Expand Down
2 changes: 1 addition & 1 deletion ReSwift/ReSwift.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ReSwift
//
// Created by Benjamin Encz on 12/14/15.
// Copyright © 2015 Benjamin Encz. All rights reserved.
// Copyright © 2015 ReSwift Community. All rights reserved.
//

#import <Foundation/Foundation.h>
Expand Down
25 changes: 25 additions & 0 deletions ReSwift/Utils/AtomicBool.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// AtomicBool.swift
// ReSwift-iOS
//
// Created by 钟武 on 2018/5/2.
// Copyright © 2015 ReSwift Community. All rights reserved.
//

import Foundation
/**
Struct is only used internally in ReSwift to implements atomic bool operation.
*/
internal struct AtomicBool {
private var flag: UInt8 = 0
internal var value: Bool {
get { return flag != 0}
set {
if newValue {
OSAtomicTestAndSet(7, &flag)
} else {
OSAtomicTestAndClear(7, &flag)
}
}
}
}
2 changes: 1 addition & 1 deletion ReSwift/Utils/Coding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ReSwift
//
// Created by Benjamin Encz on 11/27/15.
// Copyright © 2015 DigiTales. All rights reserved.
// Copyright © 2015 ReSwift Community. All rights reserved.
//

public protocol Coding {
Expand Down
2 changes: 1 addition & 1 deletion ReSwift/Utils/TypeHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ReSwift
//
// Created by Benjamin Encz on 11/27/15.
// Copyright © 2015 DigiTales. All rights reserved.
// Copyright © 2015 ReSwift Community. All rights reserved.
//

/**
Expand Down
2 changes: 1 addition & 1 deletion ReSwiftTests/AutomaticallySkipRepeatsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ReSwift
//
// Created by Daniel Martín Prieto on 03/11/2017.
// Copyright © 2017 Benjamin Encz. All rights reserved.
// Copyright © 2017 ReSwift Community. All rights reserved.
//
import XCTest
import ReSwift
Expand Down
2 changes: 2 additions & 0 deletions ReSwiftTests/PerformanceTests.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright © 2019 ReSwift Community. All rights reserved.

import XCTest
import ReSwift

Expand Down
2 changes: 1 addition & 1 deletion ReSwiftTests/StoreDispatchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ReSwift
//
// Created by Karl Bowden on 20/07/2016.
// Copyright © 2016 Benjamin Encz. All rights reserved.
// Copyright © 2016 ReSwift Community. All rights reserved.
//

import XCTest
Expand Down
4 changes: 2 additions & 2 deletions ReSwiftTests/StoreMiddlewareTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// StoreMiddlewareTests.swift
// ReSwift
//
// Created by Benji Encz on 12/24/15.
// Copyright © 2015 Benjamin Encz. All rights reserved.
// Created by Benjamin Encz on 12/24/15.
// Copyright © 2015 ReSwift Community. All rights reserved.
//

import XCTest
Expand Down
4 changes: 2 additions & 2 deletions ReSwiftTests/StoreSubscriberTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// StoreSubscriberTests.swift
// ReSwift
//
// Created by Benji Encz on 1/23/16.
// Copyright © 2016 Benjamin Encz. All rights reserved.
// Created by Benjamin Encz on 1/23/16.
// Copyright © 2016 ReSwift Community. All rights reserved.
//

import XCTest
Expand Down
2 changes: 1 addition & 1 deletion ReSwiftTests/StoreSubscriptionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ReSwift
//
// Created by Benjamin Encz on 11/27/15.
// Copyright © 2015 DigiTales. All rights reserved.
// Copyright © 2015 ReSwift Community. All rights reserved.
//

import XCTest
Expand Down
2 changes: 1 addition & 1 deletion ReSwiftTests/StoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ReSwift
//
// Created by Benjamin Encz on 11/27/15.
// Copyright © 2015 DigiTales. All rights reserved.
// Copyright © 2015 ReSwift Community. All rights reserved.
//

import XCTest
Expand Down
4 changes: 2 additions & 2 deletions ReSwiftTests/TestFakes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// TestFakes.swift
// ReSwift
//
// Created by Benji Encz on 12/24/15.
// Copyright © 2015 Benjamin Encz. All rights reserved.
// Created by Benjamin Encz on 12/24/15.
// Copyright © 2015 ReSwift Community. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion ReSwiftTests/TypeHelperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ReSwift
//
// Created by Benjamin Encz on 12/20/15.
// Copyright © 2015 Benjamin Encz. All rights reserved.
// Copyright © 2015 ReSwift Community. All rights reserved.
//

import XCTest
Expand Down
2 changes: 2 additions & 0 deletions ReSwiftTests/XCTest+Compatibility.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright © 2019 ReSwift Community. All rights reserved.

import XCTest

func dispatchAsync(execute work: @escaping @convention(block) () -> Swift.Void) {
Expand Down

0 comments on commit 68b3edd

Please sign in to comment.