-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code by separating event-only-driven
Machine
and `StateMac…
…hine`. - Add `Machine` (event-only-driven state machine). - Add `Disposable` derived from ReactiveCocoa. - Add Package.swift & change directory structure for Swift-Package-Manager.
- Loading branch information
Showing
43 changed files
with
2,061 additions
and
1,393 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 |
---|---|---|
|
@@ -17,3 +17,5 @@ DerivedData | |
*.xcuserstate | ||
|
||
Carthage/Build | ||
.build | ||
Packages/ |
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,13 @@ | ||
// | ||
// Package.swift | ||
// SwiftState | ||
// | ||
// Created by Yasuhiro Inami on 2015-12-05. | ||
// Copyright © 2015 Yasuhiro Inami. All rights reserved. | ||
// | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "SwiftState" | ||
) |
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
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,45 @@ | ||
// | ||
// Disposable.swift | ||
// ReactiveCocoa | ||
// | ||
// Created by Justin Spahr-Summers on 2014-06-02. | ||
// Copyright (c) 2014 GitHub. All rights reserved. | ||
// | ||
|
||
// | ||
// NOTE: | ||
// This file is a partial copy from ReactiveCocoa v4.0.0-alpha.4 (removing `Atomic` dependency), | ||
// which has not been taken out as microframework yet. | ||
// https://github.com/ReactiveCocoa/ReactiveCocoa/issues/2579 | ||
// | ||
// Note that `ActionDisposable` also works as `() -> ()` wrapper to help suppressing warning: | ||
// "Expression resolved to unused function", when returned function was not used. | ||
// | ||
|
||
/// Represents something that can be “disposed,” usually associated with freeing | ||
/// resources or canceling work. | ||
public protocol Disposable { | ||
/// Whether this disposable has been disposed already. | ||
var disposed: Bool { get } | ||
|
||
func dispose() | ||
} | ||
|
||
/// A disposable that will run an action upon disposal. | ||
public final class ActionDisposable: Disposable { | ||
private var action: (() -> ())? | ||
|
||
public var disposed: Bool { | ||
return action == nil | ||
} | ||
|
||
/// Initializes the disposable to run the given action upon disposal. | ||
public init(action: () -> ()) { | ||
self.action = action | ||
} | ||
|
||
public func dispose() { | ||
self.action?() | ||
self.action = nil | ||
} | ||
} |
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,62 @@ | ||
// | ||
// EventType.swift | ||
// SwiftState | ||
// | ||
// Created by Yasuhiro Inami on 2014/08/05. | ||
// Copyright (c) 2014年 Yasuhiro Inami. All rights reserved. | ||
// | ||
|
||
public protocol EventType: Hashable {} | ||
|
||
// MARK: Event | ||
|
||
/// `EventType` wrapper for handling`.Any` event. | ||
public enum Event<E: EventType>: Hashable | ||
{ | ||
case Some(E) | ||
case Any | ||
|
||
public var value: E? | ||
{ | ||
switch self { | ||
case .Some(let x): return x | ||
default: return nil | ||
} | ||
} | ||
|
||
public var hashValue: Int | ||
{ | ||
switch self { | ||
case .Some(let x): return x.hashValue | ||
case .Any: return _hashValueForAny | ||
} | ||
} | ||
} | ||
|
||
public func == <E: EventType>(lhs: Event<E>, rhs: Event<E>) -> Bool | ||
{ | ||
switch (lhs, rhs) { | ||
case let (.Some(x1), .Some(x2)) where x1 == x2: | ||
return true | ||
case (.Any, .Any): | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
// MARK: NoEvent | ||
|
||
/// Useful for creating StateMachine without events, i.e. `StateMachine<MyState, NoEvent>`. | ||
public enum NoEvent: EventType | ||
{ | ||
public var hashValue: Int | ||
{ | ||
return 0 | ||
} | ||
} | ||
|
||
public func == (lhs: NoEvent, rhs: NoEvent) -> Bool | ||
{ | ||
return true | ||
} |
File renamed without changes.
Oops, something went wrong.