Skip to content

Commit

Permalink
Convert syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
yonekawa committed Sep 22, 2016
1 parent 5561e69 commit 1e360c2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
6 changes: 6 additions & 0 deletions SwiftFlux.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,11 @@
};
CACC47F41B6B9DDA00FDF2BF = {
CreatedOnToolsVersion = 6.4;
LastSwiftMigration = 0800;
};
CACC47FF1B6B9DDA00FDF2BF = {
CreatedOnToolsVersion = 6.4;
LastSwiftMigration = 0800;
};
CAFDEA231BFF749B00AF7A09 = {
CreatedOnToolsVersion = 7.1.1;
Expand Down Expand Up @@ -1029,6 +1031,7 @@
PRODUCT_NAME = "$(PROJECT_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
};
name = Debug;
};
Expand All @@ -1053,6 +1056,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "jp.mog2dev.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(PROJECT_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 2.3;
};
name = Release;
};
Expand All @@ -1073,6 +1077,7 @@
LIBRARY_SEARCH_PATHS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = "jp.mog2dev.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = SwiftFluxTests;
SWIFT_VERSION = 2.3;
};
name = Debug;
};
Expand All @@ -1089,6 +1094,7 @@
LIBRARY_SEARCH_PATHS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = "jp.mog2dev.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = SwiftFluxTests;
SWIFT_VERSION = 2.3;
};
name = Release;
};
Expand Down
22 changes: 11 additions & 11 deletions SwiftFlux/Dispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import Result
public typealias DispatchToken = String

public protocol Dispatcher {
func dispatch<T: Action>(action: T, result: Result<T.Payload, T.Error>)
func register<T: Action>(type: T.Type, handler: (Result<T.Payload, T.Error>) -> ()) -> DispatchToken
func dispatch<T: Action>(action: T, result: Result)
func register<T: Action>(type: T.Type, handler: (Result) -> ()) -> DispatchToken
func unregister(dispatchToken: DispatchToken)
func waitFor<T: Action>(dispatchTokens: [DispatchToken], type: T.Type, result: Result<T.Payload, T.Error>)
func waitFor<T: Action>(dispatchTokens: [DispatchToken], type: T.Type, result: Result)
}

public class DefaultDispatcher: Dispatcher {
Expand All @@ -33,11 +33,11 @@ public class DefaultDispatcher: Dispatcher {
callbacks.removeAll()
}

public func dispatch<T: Action>(action: T, result: Result<T.Payload, T.Error>) {
public func dispatch<T: Action>(action: T, result: Result) {
dispatch(action.dynamicType, result: result)
}

public func register<T: Action>(type: T.Type, handler: (Result<T.Payload, T.Error>) -> Void) -> DispatchToken {
public func register<T: Action>(type: T.Type, handler: (Result) -> Void) -> DispatchToken {
let nextDispatchToken = NSUUID().UUIDString
callbacks[nextDispatchToken] = DispatchCallback<T>(type: type, handler: handler)
return nextDispatchToken
Expand All @@ -47,7 +47,7 @@ public class DefaultDispatcher: Dispatcher {
callbacks.removeValueForKey(dispatchToken)
}

public func waitFor<T: Action>(dispatchTokens: [DispatchToken], type: T.Type, result: Result<T.Payload, T.Error>) {
public func waitFor<T: Action>(dispatchTokens: [DispatchToken], type: T.Type, result: Result) {
for dispatchToken in dispatchTokens {
guard let callback = callbacks[dispatchToken] as? DispatchCallback<T> else { continue }
switch callback.status {
Expand All @@ -62,7 +62,7 @@ public class DefaultDispatcher: Dispatcher {
}
}

private func dispatch<T: Action>(type: T.Type, result: Result<T.Payload, T.Error>) {
private func dispatch<T: Action>(type: T.Type, result: Result) {
objc_sync_enter(self)

startDispatching(type)
Expand All @@ -80,7 +80,7 @@ public class DefaultDispatcher: Dispatcher {
}
}

private func invokeCallback<T: Action>(dispatchToken: DispatchToken, type: T.Type, result: Result<T.Payload, T.Error>) {
private func invokeCallback<T: Action>(dispatchToken: DispatchToken, type: T.Type, result: Result) {
guard let callback = callbacks[dispatchToken] as? DispatchCallback<T> else { return }
guard callback.status == .Waiting else { return }

Expand All @@ -92,11 +92,11 @@ public class DefaultDispatcher: Dispatcher {

private class DispatchCallback<T: Action> {
let type: T.Type
let handler: (Result<T.Payload, T.Error>) -> ()
let handler: (Result) -> ()
var status = DefaultDispatcher.Status.Waiting

init(type: T.Type, handler: (Result<T.Payload, T.Error>) -> ()) {
init(type: T.Type, handler: (Result) -> ()) {
self.type = type
self.handler = handler
}
}
}
2 changes: 1 addition & 1 deletion SwiftFlux/Utils/ReduceStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ReduceStore<T: Equatable>: StoreBase {
return internalState ?? initialState
}

public func reduce<A: Action>(type: A.Type, reducer: (T, Result<A.Payload, A.Error>) -> T) -> DispatchToken {
public func reduce<A: Action>(type: A.Type, reducer: (T, Result) -> T) -> DispatchToken {
return self.register(type) { (result) in
let startState = self.state
self.internalState = reducer(self.state, result)
Expand Down
2 changes: 1 addition & 1 deletion SwiftFlux/Utils/StoreBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class StoreBase: Store {

public init() {}

public func register<T: Action>(type: T.Type, handler: (Result<T.Payload, T.Error>) -> ()) -> DispatchToken {
public func register<T: Action>(type: T.Type, handler: (Result) -> ()) -> DispatchToken {
let dispatchToken = ActionCreator.dispatcher.register(type) { (result) -> () in
handler(result)
}
Expand Down

0 comments on commit 1e360c2

Please sign in to comment.