-
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
6dc59ba
commit efd492f
Showing
39 changed files
with
2,909 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...lar-state-management-view-state/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> | ||
|
||
|
80 changes: 80 additions & 0 deletions
80
...state-management-view-state/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,80 @@ | ||
import Combine | ||
import SwiftUI | ||
|
||
public final class Store<Value, Action>: ObservableObject { | ||
private let reducer: (inout Value, Action) -> Void | ||
@Published public private(set) var value: Value | ||
private var cancellable: Cancellable? | ||
|
||
public init(initialValue: Value, reducer: @escaping (inout Value, Action) -> Void) { | ||
self.reducer = reducer | ||
self.value = initialValue | ||
} | ||
|
||
public func send(_ action: Action) { | ||
self.reducer(&self.value, action) | ||
} | ||
|
||
// ((Value) -> LocalValue) -> ((Store<Value, _>) -> Store<LocalValue, _> | ||
// ((A) -> B) -> ((Store<A, _>) -> Store<B, _> | ||
// map: ((A) -> B) -> ((F<A>) -> F<B> | ||
|
||
func view<LocalValue>( | ||
_ f: @escaping (Value) -> LocalValue | ||
) -> Store<LocalValue, Action> { | ||
let localStore = Store<LocalValue, Action>( | ||
initialValue: f(self.value), | ||
reducer: { localValue, action in | ||
self.send(action) | ||
localValue = f(self.value) | ||
} | ||
) | ||
localStore.cancellable = self.$value.sink { [weak localStore] newValue in | ||
localStore?.value = f(newValue) | ||
} | ||
return localStore | ||
} | ||
} | ||
|
||
|
||
func transform<A, B, Action>( | ||
_ reducer: (A, Action) -> A, | ||
_ f: (A) -> B | ||
) -> (B, Action) -> B { | ||
fatalError() | ||
} | ||
|
||
|
||
public func combine<Value, Action>( | ||
_ reducers: (inout Value, Action) -> Void... | ||
) -> (inout Value, Action) -> Void { | ||
return { value, action in | ||
for reducer in reducers { | ||
reducer(&value, action) | ||
} | ||
} | ||
} | ||
|
||
public func pullback<LocalValue, GlobalValue, LocalAction, GlobalAction>( | ||
_ reducer: @escaping (inout LocalValue, LocalAction) -> Void, | ||
value: WritableKeyPath<GlobalValue, LocalValue>, | ||
action: WritableKeyPath<GlobalAction, LocalAction?> | ||
) -> (inout GlobalValue, GlobalAction) -> Void { | ||
return { globalValue, globalAction in | ||
guard let localAction = globalAction[keyPath: action] else { return } | ||
reducer(&globalValue[keyPath: value], localAction) | ||
} | ||
} | ||
|
||
public func logging<Value, Action>( | ||
_ reducer: @escaping (inout Value, Action) -> Void | ||
) -> (inout Value, Action) -> Void { | ||
return { value, action in | ||
reducer(&value, action) | ||
print("Action: \(action)") | ||
print("Value:") | ||
dump(value) | ||
print("---") | ||
} | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
0073-modular-state-management-view-state/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
...gement-view-state/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
0073-modular-state-management-view-state/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
0073-modular-state-management-view-state/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> | ||
|
||
|
15 changes: 15 additions & 0 deletions
15
0073-modular-state-management-view-state/PrimeTime/Counter/Counter.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,15 @@ | ||
|
||
public enum CounterAction { | ||
case decrTapped | ||
case incrTapped | ||
} | ||
|
||
public func counterReducer(state: inout Int, action: CounterAction) { | ||
switch action { | ||
case .decrTapped: | ||
state -= 1 | ||
|
||
case .incrTapped: | ||
state += 1 | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
0073-modular-state-management-view-state/PrimeTime/Counter/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
0073-modular-state-management-view-state/PrimeTime/CounterTests/CounterTests.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 @@ | ||
// | ||
// CounterTests.swift | ||
// CounterTests | ||
// | ||
// Created by Stephen Celis on 9/8/19. | ||
// Copyright © 2019 Point-Free. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import Counter | ||
|
||
class CounterTests: 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
0073-modular-state-management-view-state/PrimeTime/CounterTests/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
0073-modular-state-management-view-state/PrimeTime/FavoritePrimes/FavoritePrimes.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 @@ | ||
// | ||
// FavoritePrimes.h | ||
// FavoritePrimes | ||
// | ||
// Created by Stephen Celis on 9/8/19. | ||
// Copyright © 2019 Point-Free. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
//! Project version number for FavoritePrimes. | ||
FOUNDATION_EXPORT double FavoritePrimesVersionNumber; | ||
|
||
//! Project version string for FavoritePrimes. | ||
FOUNDATION_EXPORT const unsigned char FavoritePrimesVersionString[]; | ||
|
||
// In this header, you should import all the public headers of your framework using statements like #import <FavoritePrimes/PublicHeader.h> | ||
|
||
|
13 changes: 13 additions & 0 deletions
13
0073-modular-state-management-view-state/PrimeTime/FavoritePrimes/FavoritePrimes.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,13 @@ | ||
|
||
public enum FavoritePrimesAction { | ||
case deleteFavoritePrimes(IndexSet) | ||
} | ||
|
||
public func favoritePrimesReducer(state: inout [Int], action: FavoritePrimesAction) { | ||
switch action { | ||
case let .deleteFavoritePrimes(indexSet): | ||
for index in indexSet { | ||
state.remove(at: index) | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
0073-modular-state-management-view-state/PrimeTime/FavoritePrimes/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
...dular-state-management-view-state/PrimeTime/FavoritePrimesTests/FavoritePrimesTests.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 @@ | ||
// | ||
// FavoritePrimesTests.swift | ||
// FavoritePrimesTests | ||
// | ||
// Created by Stephen Celis on 9/8/19. | ||
// Copyright © 2019 Point-Free. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import FavoritePrimes | ||
|
||
class FavoritePrimesTests: 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. | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.