Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IdentityEquatable and IdentityHashable
- Loading branch information
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// IdentityEquatable.swift | ||
// ReactorKit | ||
// | ||
// Created by Suyeol Jeon on 2019/10/17. | ||
// | ||
|
||
public protocol IdentityEquatable: class, Equatable { | ||
} | ||
|
||
public extension IdentityEquatable { | ||
static func == (lhs: Self, rhs: Self) -> Bool { | ||
return lhs === rhs | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// IdentityHashable.swift | ||
// ReactorKit | ||
// | ||
// Created by Suyeol Jeon on 2019/10/17. | ||
// | ||
|
||
public protocol IdentityHashable: Hashable, IdentityEquatable { | ||
} | ||
|
||
public extension IdentityHashable { | ||
func hash(into hasher: inout Hasher) { | ||
hasher.combine(ObjectIdentifier(self).hashValue) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// IdentityEquatableTests.swift | ||
// ReactorKitTests | ||
// | ||
// Created by Suyeol Jeon on 2019/10/17. | ||
// | ||
|
||
import XCTest | ||
import ReactorKit | ||
import RxSwift | ||
|
||
final class IdentityEquatableTests: XCTestCase { | ||
func testReactorEqual_whenCurrentStatesAreEqual() { | ||
let reactorA = SimpleReactor() | ||
let reactorB = reactorA | ||
XCTAssertEqual(reactorA, reactorB) | ||
} | ||
} | ||
|
||
private final class SimpleReactor: Reactor, IdentityEquatable { | ||
typealias Action = Never | ||
typealias Mutation = Never | ||
struct State { | ||
} | ||
|
||
let initialState = State() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// IdentityHashableTests.swift | ||
// ReactorKitTests | ||
// | ||
// Created by Suyeol Jeon on 2019/10/17. | ||
// | ||
|
||
import XCTest | ||
import ReactorKit | ||
import RxSwift | ||
|
||
final class IdentityHashableTests: XCTestCase { | ||
func testReactorHashValue() { | ||
let reactorA = SimpleReactor() | ||
let reactorB = reactorA | ||
XCTAssertEqual(reactorA.hashValue, reactorB.hashValue) | ||
XCTAssertEqual(reactorA, reactorB) | ||
} | ||
} | ||
|
||
private final class SimpleReactor: Reactor, IdentityHashable { | ||
typealias Action = Never | ||
typealias Mutation = Never | ||
struct State { | ||
} | ||
|
||
let initialState = State() | ||
} |