Skip to content

Commit

Permalink
Remove Equatable
Browse files Browse the repository at this point in the history
  • Loading branch information
bvic23 committed Nov 28, 2015
1 parent 53f0d25 commit ef653b8
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 101 deletions.
6 changes: 0 additions & 6 deletions VinceRP.xcodeproj/project.pbxproj
Expand Up @@ -65,7 +65,6 @@
791F30F51C0392B1004AA9E2 /* Timer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791F30AA1C03924C004AA9E2 /* Timer.swift */; };
791F31051C0392C0004AA9E2 /* Box.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791F30F71C0392C0004AA9E2 /* Box.swift */; };
791F31061C0392C0004AA9E2 /* CommonConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791F30F81C0392C0004AA9E2 /* CommonConstants.swift */; };
791F31071C0392C0004AA9E2 /* EquatableArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791F30F91C0392C0004AA9E2 /* EquatableArray.swift */; };
791F31081C0392C0004AA9E2 /* ExceptionHandling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791F30FA1C0392C0004AA9E2 /* ExceptionHandling.swift */; };
791F31091C0392C0004AA9E2 /* Flattenable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791F30FB1C0392C0004AA9E2 /* Flattenable.swift */; };
791F310A1C0392C0004AA9E2 /* FunctionalArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791F30FC1C0392C0004AA9E2 /* FunctionalArray.swift */; };
Expand All @@ -79,7 +78,6 @@
791F31121C0392C0004AA9E2 /* WeakSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791F31041C0392C0004AA9E2 /* WeakSet.swift */; };
791F31131C0392CB004AA9E2 /* Box.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791F30F71C0392C0004AA9E2 /* Box.swift */; };
791F31141C0392CB004AA9E2 /* CommonConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791F30F81C0392C0004AA9E2 /* CommonConstants.swift */; };
791F31151C0392CB004AA9E2 /* EquatableArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791F30F91C0392C0004AA9E2 /* EquatableArray.swift */; };
791F31161C0392CB004AA9E2 /* ExceptionHandling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791F30FA1C0392C0004AA9E2 /* ExceptionHandling.swift */; };
791F31171C0392CB004AA9E2 /* Flattenable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791F30FB1C0392C0004AA9E2 /* Flattenable.swift */; };
791F31181C0392CB004AA9E2 /* FunctionalArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 791F30FC1C0392C0004AA9E2 /* FunctionalArray.swift */; };
Expand Down Expand Up @@ -224,7 +222,6 @@
791F30EA1C0392A7004AA9E2 /* ThreadLocal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ThreadLocal.swift; path = ../vincerp/Common/Threading/ThreadLocal.swift; sourceTree = "<group>"; };
791F30F71C0392C0004AA9E2 /* Box.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Box.swift; path = ../vincerp/Common/Util/Box.swift; sourceTree = "<group>"; };
791F30F81C0392C0004AA9E2 /* CommonConstants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CommonConstants.swift; path = ../vincerp/Common/Util/CommonConstants.swift; sourceTree = "<group>"; };
791F30F91C0392C0004AA9E2 /* EquatableArray.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EquatableArray.swift; path = ../vincerp/Common/Util/EquatableArray.swift; sourceTree = "<group>"; };
791F30FA1C0392C0004AA9E2 /* ExceptionHandling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ExceptionHandling.swift; path = ../vincerp/Common/Util/ExceptionHandling.swift; sourceTree = "<group>"; };
791F30FB1C0392C0004AA9E2 /* Flattenable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Flattenable.swift; path = ../vincerp/Common/Util/Flattenable.swift; sourceTree = "<group>"; };
791F30FC1C0392C0004AA9E2 /* FunctionalArray.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FunctionalArray.swift; path = ../vincerp/Common/Util/FunctionalArray.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -395,7 +392,6 @@
children = (
791F30F71C0392C0004AA9E2 /* Box.swift */,
791F30F81C0392C0004AA9E2 /* CommonConstants.swift */,
791F30F91C0392C0004AA9E2 /* EquatableArray.swift */,
791F30FA1C0392C0004AA9E2 /* ExceptionHandling.swift */,
791F30FB1C0392C0004AA9E2 /* Flattenable.swift */,
791F30FC1C0392C0004AA9E2 /* FunctionalArray.swift */,
Expand Down Expand Up @@ -1130,7 +1126,6 @@
791F312D1C039612004AA9E2 /* NSTextField+VinceRP.swift in Sources */,
791F311F1C0392CB004AA9E2 /* WeakReference.swift in Sources */,
791F30DE1C039286004AA9E2 /* Propagator.swift in Sources */,
791F31151C0392CB004AA9E2 /* EquatableArray.swift in Sources */,
791F30D71C039286004AA9E2 /* ChangeObserver.swift in Sources */,
791F30F41C0392AC004AA9E2 /* ThreadLocal.swift in Sources */,
);
Expand Down Expand Up @@ -1183,7 +1178,6 @@
791F30B41C039260004AA9E2 /* Addable.swift in Sources */,
791F30D21C039273004AA9E2 /* Throttle.swift in Sources */,
02C489DE1BE3CBE6004FD281 /* UIResponder+VinceRP.swift in Sources */,
791F31071C0392C0004AA9E2 /* EquatableArray.swift in Sources */,
795FF5521BB814D400E19285 /* UIActivityIndicatorView+VinceRP.swift in Sources */,
791F31091C0392C0004AA9E2 /* Flattenable.swift in Sources */,
791F30CE1C039273004AA9E2 /* Reducer.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion VinceRP/Common/Api.swift
Expand Up @@ -33,7 +33,7 @@ public func reactive<T>(initValue: T) -> Source<T> {
return Source(initValue: initValue)
}

public func reactive<T:Equatable>() -> Source<T> {
public func reactive<T>() -> Source<T> {
return Source()
}

Expand Down
4 changes: 2 additions & 2 deletions VinceRP/Common/Core/BatchUpdate.swift
Expand Up @@ -7,7 +7,7 @@ protocol UpdateProtocol {
func ancestors() -> [NodeTuple]
}

public struct BatchUpdate<T: Equatable> {
public struct BatchUpdate<T> {
var updates: [UpdateProtocol]

init(_ v: Source<T>, withValue t: T) {
Expand All @@ -30,7 +30,7 @@ public struct BatchUpdate<T: Equatable> {

}

struct Update<T:Equatable>: UpdateProtocol {
struct Update<T>: UpdateProtocol {
let v: Source<T>
let t: T

Expand Down
2 changes: 1 addition & 1 deletion VinceRP/Common/Core/Node.swift
Expand Up @@ -3,7 +3,7 @@
// Copyright (c) 2015 Viktor Belenyesi. All rights reserved.
//

public class Node: Hashable, Equatable {
public class Node: Hashable {

private static var hashCounter = AtomicLong(0)
private let childrenHolder = SpinSet<WeakSet<Node>>(WeakSet())
Expand Down
2 changes: 1 addition & 1 deletion VinceRP/Common/Core/NodeTuple.swift
Expand Up @@ -3,7 +3,7 @@
// Copyright (c) 2015 Viktor Belenyesi. All rights reserved.
//

struct NodeTuple: Hashable, Equatable {
struct NodeTuple: Hashable {
let source: Node
let reactor: Node

Expand Down
2 changes: 1 addition & 1 deletion VinceRP/Common/Core/Source.swift
Expand Up @@ -5,7 +5,7 @@

private let noValueError = NSError(domain: "no value", code: -1, userInfo: nil)

public class Source<T: Equatable>: Hub<T> {
public class Source<T>: Hub<T> {

let state: AtomicReference<Box<Try<T>>>

Expand Down
2 changes: 1 addition & 1 deletion VinceRP/Common/Threading/AtomicLong.swift
Expand Up @@ -5,7 +5,7 @@

public typealias long = Int32

public class AtomicLong: Hashable, Equatable {
public class AtomicLong: Hashable {

private let pointer: UnsafeMutablePointer<long> = UnsafeMutablePointer < long>.alloc(1)

Expand Down
54 changes: 0 additions & 54 deletions VinceRP/Common/Util/EquatableArray.swift

This file was deleted.

14 changes: 7 additions & 7 deletions VinceRP/Common/Util/ReactivePropertyGenerator.swift
Expand Up @@ -15,38 +15,38 @@ public class ReactivePropertyGenerator {
return "\(targetObject.hash)\(propertyName) "
}

static func getEmitter<T:Equatable>(targetObject: AnyObject, propertyName: String) -> Source<T>? {
static func getEmitter<T>(targetObject: AnyObject, propertyName: String) -> Source<T>? {
let key = getKey(targetObject, propertyName: propertyName)
return propertyMap[key] as! Source<T>?
}

static func synthesizeEmitter<T:Equatable>(initValue: T) -> Source<T> {
static func synthesizeEmitter<T>(initValue: T) -> Source<T> {
return Source<T>(initValue: initValue)
}

static func synthesizeObserver<T:Equatable>(targetObject: AnyObject, propertyName: String, initValue: T) -> PropertyObserver {
static func synthesizeObserver<T>(targetObject: AnyObject, propertyName: String, initValue: T) -> PropertyObserver {
return PropertyObserver(targetObject: targetObject as! NSObject, propertyName: propertyName) { (currentTargetObject: NSObject, currentPropertyName:String, currentValue:AnyObject) in
if let existingEmitter:Source<T> = getEmitter(currentTargetObject, propertyName: propertyName) {
existingEmitter.update(currentValue as! T)
}
}
}

static func createEmitter<T:Equatable>(targetObject: AnyObject, propertyName: String, initValue: T) -> Source<T> {
static func createEmitter<T>(targetObject: AnyObject, propertyName: String, initValue: T) -> Source<T> {
let result = synthesizeEmitter(initValue)
let key = getKey(targetObject, propertyName: propertyName)
propertyMap[key] = result
return result
}

static func createObserver<T:Equatable>(targetObject: AnyObject, propertyName: String, initValue: T) -> PropertyObserver {
static func createObserver<T>(targetObject: AnyObject, propertyName: String, initValue: T) -> PropertyObserver {
let result = synthesizeObserver(targetObject, propertyName: propertyName, initValue: initValue)
let key = getKey(targetObject, propertyName: propertyName)
observerMap[key] = result
return result
}

public static func source<T:Equatable>(targetObject: AnyObject, propertyName: String, initValue: T, initializer: ((Source<T>) -> ())? = nil) -> Source<T> {
public static func source<T>(targetObject: AnyObject, propertyName: String, initValue: T, initializer: ((Source<T>) -> ())? = nil) -> Source<T> {
if let emitter:Source<T> = getEmitter(targetObject, propertyName: propertyName) {
return emitter
}
Expand All @@ -58,7 +58,7 @@ public class ReactivePropertyGenerator {
return emitter
}

public static func property<T:Equatable>(targetObject: AnyObject, propertyName: String, initValue: T, initializer: ((Source<T>) -> ())? = nil) -> Hub<T> {
public static func property<T>(targetObject: AnyObject, propertyName: String, initValue: T, initializer: ((Source<T>) -> ())? = nil) -> Hub<T> {
let result = source(targetObject, propertyName: propertyName, initValue: initValue, initializer: initializer)
createObserver(targetObject, propertyName: propertyName, initValue: initValue)
return result as Hub<T>
Expand Down
2 changes: 1 addition & 1 deletion VinceRP/Common/Util/WeakReference.swift
Expand Up @@ -4,7 +4,7 @@
//
// https://github.com/scala/scala/blob/2.11.x/src/library/scala/ref/WeakReference.scala

public class WeakReference<T: AnyObject where T: Hashable>: Hashable, Equatable {
public class WeakReference<T: AnyObject where T: Hashable>: Hashable {
public weak var value: T?

public init(_ value: T) {
Expand Down
4 changes: 2 additions & 2 deletions VinceRP/Extension/AppKit/NSResponder+VinceRP.swift
Expand Up @@ -7,11 +7,11 @@ import AppKit

public extension NSResponder {

public func reactiveProperty<T: Equatable>(forProperty propertyName: String, initValue: T, initializer: ((Source<T>) -> ())? = nil) -> Hub<T> {
public func reactiveProperty<T>(forProperty propertyName: String, initValue: T, initializer: ((Source<T>) -> ())? = nil) -> Hub<T> {
return ReactivePropertyGenerator.property(self, propertyName: propertyName, initValue: initValue, initializer: initializer)
}

public func reactiveEmitter<T: Equatable>(name propertyName: String, initValue: T) -> Source<T> {
public func reactiveEmitter<T>(name propertyName: String, initValue: T) -> Source<T> {
return ReactivePropertyGenerator.source(self, propertyName: propertyName, initValue: initValue)
}

Expand Down
4 changes: 2 additions & 2 deletions VinceRP/Extension/UIKit/UIResponder+VinceRP.swift
Expand Up @@ -7,11 +7,11 @@ import UIKit

public extension UIResponder {

public func reactiveProperty<T:Equatable>(forProperty propertyName: String, initValue: T, initializer: ((Source<T>) -> ())? = nil) -> Hub<T> {
public func reactiveProperty<T>(forProperty propertyName: String, initValue: T, initializer: ((Source<T>) -> ())? = nil) -> Hub<T> {
return ReactivePropertyGenerator.property(self, propertyName: propertyName, initValue: initValue, initializer: initializer)
}

public func reactiveSource<T:Equatable>(name propertyName: String, initValue: T) -> Source<T> {
public func reactiveSource<T>(name propertyName: String, initValue: T) -> Source<T> {
return ReactivePropertyGenerator.source(self, propertyName: propertyName, initValue: initValue)
}

Expand Down
63 changes: 42 additions & 21 deletions VinceRPTests/Common/SmokeSpec.swift
Expand Up @@ -19,27 +19,6 @@ class SmokeSpec: QuickSpec {
describe("basic") {

context("reactive variable") {

it("is happy without default value") {
// given
let a: Source<Int> = reactive()

// then
expect(a.hasValue()) == false

// when
a <- 1

// then
expect(a*) == 1
expect(a.hasValue()) == true

// when
a <- fakeError

// then
expect(a.hasValue()) == true
}

it("holds the initial value") {
// given
Expand Down Expand Up @@ -213,6 +192,48 @@ class SmokeSpec: QuickSpec {
expect(f*) == "budapest=8+6"
expect(counter) == 3
}

it("is happy without default value") {
// given
let a: Source<Int> = reactive()

// then
expect(a.hasValue()) == false

// when
a <- 1

// then
expect(a*) == 1
expect(a.hasValue()) == true

// when
a <- fakeError

// then
expect(a.hasValue()) == true
}


it("is works with optionals") {
// given
let a: Source<Int?> = reactive(1)

// then
expect(a*) == 1

// when
a <- nil

// then
expect(a*).to(beNil())

// when
a <- fakeError

// then
expect(a.toTry().isFailure()) == true
}

}

Expand Down
2 changes: 1 addition & 1 deletion VinceRPTests/Common/Threading/AtomicReferenceSpec.swift
Expand Up @@ -8,7 +8,7 @@
import Quick
import Nimble

class Foo : Equatable {
class Foo: Equatable {
let i: Int
init(_ i: Int) {
self.i = i
Expand Down

0 comments on commit ef653b8

Please sign in to comment.