-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64c8c0c
commit 52430f1
Showing
44 changed files
with
3,140 additions
and
7 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
7 changes: 7 additions & 0 deletions
7
...ement-async-effects/PrimeTime/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
...-state-management-async-effects/PrimeTime/ComposableArchitecture/ComposableArchitecture.h
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,19 @@ | ||
// | ||
// ComposableArchitecture.h | ||
// ComposableArchitecture | ||
// | ||
// Created by Stephen Celis on 9/8/19. | ||
// Copyright © 2019 Point-Free. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
//! Project version number for ComposableArchitecture. | ||
FOUNDATION_EXPORT double ComposableArchitectureVersionNumber; | ||
|
||
//! Project version string for ComposableArchitecture. | ||
FOUNDATION_EXPORT const unsigned char ComposableArchitectureVersionString[]; | ||
|
||
// In this header, you should import all the public headers of your framework using statements like #import <ComposableArchitecture/PublicHeader.h> | ||
|
||
|
106 changes: 106 additions & 0 deletions
106
...te-management-async-effects/PrimeTime/ComposableArchitecture/ComposableArchitecture.swift
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,106 @@ | ||
import Combine | ||
import SwiftUI | ||
|
||
struct Parallel<A> { | ||
let run: (@escaping (A) -> Void) -> Void | ||
} | ||
|
||
//DispatchQueue.main.async(execute: () -> Void) -> Void | ||
//UIView.animate(withDuration: TimeInterval, animations: () -> Void) -> Void | ||
//URLSession.shared.dataTask(with: URL, completionHandler: (Data?, URLResponse?, Error?) -> Void) -> Void | ||
|
||
public typealias Effect<Action> = (@escaping (Action) -> Void) -> Void | ||
|
||
public typealias Reducer<Value, Action> = (inout Value, Action) -> [Effect<Action>] | ||
|
||
//Button.init("Save", action: <#() -> Void#>) | ||
|
||
public final class Store<Value, Action>: ObservableObject { | ||
private let reducer: Reducer<Value, Action> | ||
@Published public private(set) var value: Value | ||
private var cancellable: Cancellable? | ||
|
||
public init(initialValue: Value, reducer: @escaping Reducer<Value, Action>) { | ||
self.reducer = reducer | ||
self.value = initialValue | ||
} | ||
|
||
public func send(_ action: Action) { | ||
let effects = self.reducer(&self.value, action) | ||
effects.forEach { effect in | ||
effect(self.send) | ||
} | ||
// DispatchQueue.global().async { | ||
// effects.forEach { effect in | ||
// if let action = effect() { | ||
// DispatchQueue.main.async { | ||
// self.send(action) | ||
// } | ||
// } | ||
// } | ||
// } | ||
} | ||
|
||
public func view<LocalValue, LocalAction>( | ||
value toLocalValue: @escaping (Value) -> LocalValue, | ||
action toGlobalAction: @escaping (LocalAction) -> Action | ||
) -> Store<LocalValue, LocalAction> { | ||
let localStore = Store<LocalValue, LocalAction>( | ||
initialValue: toLocalValue(self.value), | ||
reducer: { localValue, localAction in | ||
self.send(toGlobalAction(localAction)) | ||
localValue = toLocalValue(self.value) | ||
return [] | ||
} | ||
) | ||
localStore.cancellable = self.$value.sink { [weak localStore] newValue in | ||
localStore?.value = toLocalValue(newValue) | ||
} | ||
return localStore | ||
} | ||
} | ||
|
||
public func combine<Value, Action>( | ||
_ reducers: Reducer<Value, Action>... | ||
) -> Reducer<Value, Action> { | ||
return { value, action in | ||
let effects = reducers.flatMap { $0(&value, action) } | ||
return effects | ||
} | ||
} | ||
|
||
public func pullback<LocalValue, GlobalValue, LocalAction, GlobalAction>( | ||
_ reducer: @escaping Reducer<LocalValue, LocalAction>, | ||
value: WritableKeyPath<GlobalValue, LocalValue>, | ||
action: WritableKeyPath<GlobalAction, LocalAction?> | ||
) -> Reducer<GlobalValue, GlobalAction> { | ||
return { globalValue, globalAction in | ||
guard let localAction = globalAction[keyPath: action] else { return [] } | ||
let localEffects = reducer(&globalValue[keyPath: value], localAction) | ||
return localEffects.map { localEffect in | ||
{ callback in | ||
// guard let localAction = localEffect() else { return nil } | ||
localEffect { localAction in | ||
var globalAction = globalAction | ||
globalAction[keyPath: action] = localAction | ||
callback(globalAction) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
public func logging<Value, Action>( | ||
_ reducer: @escaping Reducer<Value, Action> | ||
) -> Reducer<Value, Action> { | ||
return { value, action in | ||
let effects = reducer(&value, action) | ||
let newValue = value | ||
return [{ _ in | ||
print("Action: \(action)") | ||
print("Value:") | ||
dump(newValue) | ||
print("---") | ||
}] + effects | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
0078-effectful-state-management-async-effects/PrimeTime/ComposableArchitecture/Info.plist
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,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>$(CURRENT_PROJECT_VERSION)</string> | ||
</dict> | ||
</plist> |
34 changes: 34 additions & 0 deletions
34
...ent-async-effects/PrimeTime/ComposableArchitectureTests/ComposableArchitectureTests.swift
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,34 @@ | ||
// | ||
// ComposableArchitectureTests.swift | ||
// ComposableArchitectureTests | ||
// | ||
// Created by Stephen Celis on 9/8/19. | ||
// Copyright © 2019 Point-Free. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import ComposableArchitecture | ||
|
||
class ComposableArchitectureTests: XCTestCase { | ||
|
||
override func setUp() { | ||
// Put setup code here. This method is called before the invocation of each test method in the class. | ||
} | ||
|
||
override func tearDown() { | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
} | ||
|
||
func testExample() { | ||
// This is an example of a functional test case. | ||
// Use XCTAssert and related functions to verify your tests produce the correct results. | ||
} | ||
|
||
func testPerformanceExample() { | ||
// This is an example of a performance test case. | ||
self.measure { | ||
// Put the code you want to measure the time of here. | ||
} | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...effectful-state-management-async-effects/PrimeTime/ComposableArchitectureTests/Info.plist
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,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
</dict> | ||
</plist> |
19 changes: 19 additions & 0 deletions
19
0078-effectful-state-management-async-effects/PrimeTime/Counter/Counter.h
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,19 @@ | ||
// | ||
// Counter.h | ||
// Counter | ||
// | ||
// Created by Stephen Celis on 9/8/19. | ||
// Copyright © 2019 Point-Free. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
//! Project version number for Counter. | ||
FOUNDATION_EXPORT double CounterVersionNumber; | ||
|
||
//! Project version string for Counter. | ||
FOUNDATION_EXPORT const unsigned char CounterVersionString[]; | ||
|
||
// In this header, you should import all the public headers of your framework using statements like #import <Counter/PublicHeader.h> | ||
|
||
|
Oops, something went wrong.