Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
maximkhatskevich committed Jan 14, 2017
2 parents a2467b6 + 29495ff commit d70977e
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 128 deletions.
4 changes: 2 additions & 2 deletions Info/MKHViewState.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.1.2</string>
<string>1.2.0</string>
<key>CFBundleVersion</key>
<string>5</string>
<string>6</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
4 changes: 2 additions & 2 deletions Info/MKHViewStateTst.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.1.2</string>
<string>1.2.0</string>
<key>CFBundleVersion</key>
<string>5</string>
<string>6</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion MKHViewState.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = 'MKHViewState'
s.version = '1.1.2'
s.version = '1.2.0'
s.summary = 'Implement any view as a discrete system and describe its states in a declarative style.'
s.homepage = 'https://github.com/maximkhatskevich/#{s.name}'
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand Down
44 changes: 34 additions & 10 deletions MKHViewState.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
3E5077E26783FA34042273ED /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50AB9958D55288E3A7070D02 /* UIKit.framework */; };
5B3869AB93BCFBEB916A9A94 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50AB9958D55288E3A7070D02 /* UIKit.framework */; };
7B8F605282EE0069FF96CCEC /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CFA55C2B17FFE6789F1B8C1 /* Foundation.framework */; };
94FAE3381E102E78009706A0 /* Declarations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94FAE3371E102E78009706A0 /* Declarations.swift */; };
945C20331E2A576B0004DE2E /* DiscreteSystem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 945C20321E2A576B0004DE2E /* DiscreteSystem.swift */; };
945C20391E2ACAEB0004DE2E /* MyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 945C20371E2ACACC0004DE2E /* MyView.swift */; };
945C203B1E2ACB410004DE2E /* MyView.Normal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 945C203A1E2ACB410004DE2E /* MyView.Normal.swift */; };
945C203D1E2ACC490004DE2E /* MyView.Highlighted.swift in Sources */ = {isa = PBXBuildFile; fileRef = 945C203C1E2ACC490004DE2E /* MyView.Highlighted.swift */; };
945C203F1E2ACC8F0004DE2E /* MyView.Disabled.swift in Sources */ = {isa = PBXBuildFile; fileRef = 945C203E1E2ACC8F0004DE2E /* MyView.Disabled.swift */; };
94FAE33A1E102FD7009706A0 /* ViewState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94FAE3391E102FD7009706A0 /* ViewState.swift */; };
94FAE33E1E10329A009706A0 /* StateCtrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94FAE33D1E10329A009706A0 /* StateCtrl.swift */; };
B5E7581830AE943E755AEE7D /* Main.swift in Sources */ = {isa = PBXBuildFile; fileRef = D21A9606F2A231FFCCDB1994 /* Main.swift */; };
Expand All @@ -23,7 +27,11 @@
1BC20771415FE04771603E40 /* MKHViewState. */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.framework; name = MKHViewState.; path = MKHViewState.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3CFA55C2B17FFE6789F1B8C1 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; };
50AB9958D55288E3A7070D02 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; };
94FAE3371E102E78009706A0 /* Declarations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Declarations.swift; sourceTree = "<group>"; };
945C20321E2A576B0004DE2E /* DiscreteSystem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DiscreteSystem.swift; sourceTree = "<group>"; };
945C20371E2ACACC0004DE2E /* MyView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MyView.swift; sourceTree = "<group>"; };
945C203A1E2ACB410004DE2E /* MyView.Normal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MyView.Normal.swift; sourceTree = "<group>"; };
945C203C1E2ACC490004DE2E /* MyView.Highlighted.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MyView.Highlighted.swift; sourceTree = "<group>"; };
945C203E1E2ACC8F0004DE2E /* MyView.Disabled.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MyView.Disabled.swift; sourceTree = "<group>"; };
94FAE3391E102FD7009706A0 /* ViewState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewState.swift; sourceTree = "<group>"; };
94FAE33D1E10329A009706A0 /* StateCtrl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StateCtrl.swift; sourceTree = "<group>"; };
D21A9606F2A231FFCCDB1994 /* Main.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = Main.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -84,6 +92,7 @@
isa = PBXGroup;
children = (
D21A9606F2A231FFCCDB1994 /* Main.swift */,
945C20361E2ACABB0004DE2E /* Spec */,
);
path = Tst;
sourceTree = "<group>";
Expand All @@ -104,12 +113,23 @@
path = "Src-Extra";
sourceTree = "<group>";
};
945C20361E2ACABB0004DE2E /* Spec */ = {
isa = PBXGroup;
children = (
945C20371E2ACACC0004DE2E /* MyView.swift */,
945C203A1E2ACB410004DE2E /* MyView.Normal.swift */,
945C203C1E2ACC490004DE2E /* MyView.Highlighted.swift */,
945C203E1E2ACC8F0004DE2E /* MyView.Disabled.swift */,
);
path = Spec;
sourceTree = "<group>";
};
B862B84F2298A0BCEA456373 /* Src */ = {
isa = PBXGroup;
children = (
94FAE3371E102E78009706A0 /* Declarations.swift */,
94FAE3391E102FD7009706A0 /* ViewState.swift */,
94FAE33D1E10329A009706A0 /* StateCtrl.swift */,
945C20321E2A576B0004DE2E /* DiscreteSystem.swift */,
);
path = Src;
sourceTree = "<group>";
Expand Down Expand Up @@ -191,7 +211,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
945C20391E2ACAEB0004DE2E /* MyView.swift in Sources */,
B5E7581830AE943E755AEE7D /* Main.swift in Sources */,
945C203F1E2ACC8F0004DE2E /* MyView.Disabled.swift in Sources */,
945C203B1E2ACB410004DE2E /* MyView.Normal.swift in Sources */,
945C203D1E2ACC490004DE2E /* MyView.Highlighted.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -200,7 +224,7 @@
buildActionMask = 2147483647;
files = (
94FAE33E1E10329A009706A0 /* StateCtrl.swift in Sources */,
94FAE3381E102E78009706A0 /* Declarations.swift in Sources */,
945C20331E2A576B0004DE2E /* DiscreteSystem.swift in Sources */,
94FAE33A1E102FD7009706A0 /* ViewState.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -212,12 +236,12 @@
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 6;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UJA88X59XP;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 5;
DYLIB_CURRENT_VERSION = 6;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -298,7 +322,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 6;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -348,7 +372,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
COPY_PHASE_STRIP = YES;
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 6;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand All @@ -373,12 +397,12 @@
isa = XCBuildConfiguration;
buildSettings = {
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
CURRENT_PROJECT_VERSION = 5;
CURRENT_PROJECT_VERSION = 6;
DEBUG_INFORMATION_FORMAT = dwarf;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UJA88X59XP;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 5;
DYLIB_CURRENT_VERSION = 6;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down
24 changes: 0 additions & 24 deletions Src/Declarations.swift

This file was deleted.

30 changes: 30 additions & 0 deletions Src/DiscreteSystem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// DiscreteSystem.swift
// MKHViewState
//
// Created by Maxim Khatskevich on 1/14/17.
// Copyright © 2017 Maxim Khatskevich. All rights reserved.
//

import UIKit

//===

public
protocol DiscreteSystem: class
{
associatedtype TargetView: UIView

var stateCtrl: StateCtrl<TargetView> { get }
}

//===

public
extension DiscreteSystem
{
func apply(_ newState: ViewState<TargetView>)
{
stateCtrl.apply(newState)
}
}
35 changes: 17 additions & 18 deletions Src/StateCtrl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,30 @@ class StateCtrl<TargetView: UIView>
weak
var targetView: TargetView?

public private(set)
//===

public fileprivate(set)
var current: ViewState<TargetView>? = nil

public private(set)
public fileprivate(set)
var next: ViewState<TargetView>? = nil

public
var isReadyForTransition: Bool { return next == nil }

//===

public
init(for view: TargetView)
{
self.targetView = view
}

//===

public
}

//=== MARK: Apply

extension StateCtrl
{
func apply(_ newState: ViewState<TargetView>)
{
guard
Expand All @@ -55,19 +62,19 @@ class StateCtrl<TargetView: UIView>
//===

/*
Q: What we've checked so far?
A: If we are already in the target state,
or if we are currently transitioning into that state, then
no need to do anything at all, and no need to throw an exception.
or if we are currently transitioning into that state, then
no need to do anything at all, and no need to throw an exception.
*/

//===

guard
let targetView = targetView // must be optional to be weak!
let targetView = targetView
else
{
return
Expand Down Expand Up @@ -99,11 +106,3 @@ class StateCtrl<TargetView: UIView>
}
}
}

//===

public
extension StateCtrl
{
var isReadyForTransition: Bool { return next == nil }
}
26 changes: 22 additions & 4 deletions Src/ViewState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,23 @@ import UIKit

//===

public
struct TransitionParams
{
public
let mutation: () -> Void

public
let completion: (_ finished: Bool) -> Void
}

//===

public
final
class ViewState<TargetView: UIView>
{
let id: ViewStateId
let id: String

let transition: (_: TransitionParams) -> Void

Expand All @@ -24,7 +36,7 @@ class ViewState<TargetView: UIView>

public
init(
id: ViewStateId = NSUUID().uuidString,
id: String = NSUUID().uuidString,
transition: @escaping (_: TransitionParams) -> Void = { $0.mutation(); $0.completion(true) },
mutation: @escaping (_ view: TargetView) -> Void
)
Expand All @@ -42,7 +54,10 @@ class ViewState<TargetView: UIView>
extension ViewState: Equatable { }

public
func ==<LView: UIView, RView: UIView>(lhs: ViewState<LView>, rhs: ViewState<RView>) -> Bool
func ==<LView: UIView, RView: UIView>(
lhs: ViewState<LView>,
rhs: ViewState<RView>
) -> Bool
{
return lhs.id == rhs.id
}
Expand All @@ -51,7 +66,10 @@ func ==<LView: UIView, RView: UIView>(lhs: ViewState<LView>, rhs: ViewState<RVie

extension ViewState
{
func apply(on view: TargetView, completion: @escaping (_ finished: Bool) -> Void)
func apply(
on view: TargetView,
completion: @escaping (_ finished: Bool) -> Void
)
{
transition(
TransitionParams(
Expand Down
Loading

0 comments on commit d70977e

Please sign in to comment.