Skip to content
Permalink
Browse files

Merge pull request #136 from ReactorKit/identity-equatable-hashable

Inroduce IdentityEquatable and IdentityHashable
  • Loading branch information
devxoul committed Nov 19, 2019
2 parents 98964ae + 30edd8d commit 9c57545d5662bb56d1065d02ffc9ee14a2af3be6
@@ -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)
}
}

This file was deleted.

This file was deleted.

@@ -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()
}

This file was deleted.

This file was deleted.

0 comments on commit 9c57545

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