Skip to content
Permalink
Browse files

Add IdentityEquatable and IdentityHashable

  • Loading branch information
devxoul committed Nov 19, 2019
1 parent 2770c46 commit 30edd8db589f229d73b86781eff40fae05e4ce85
@@ -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
}
}
@@ -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)
}
}
@@ -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()
}
@@ -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()
}

0 comments on commit 30edd8d

Please sign in to comment.
You can’t perform that action at this time.