From e5227113b02fc21fa4838e37a233e5c9fbcf6558 Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:23:18 +0200 Subject: [PATCH 01/29] Update DefaultBind --- Decide/Accessor/Default/DefaultBind.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Decide/Accessor/Default/DefaultBind.swift b/Decide/Accessor/Default/DefaultBind.swift index 6b1f308..5010eb5 100644 --- a/Decide/Accessor/Default/DefaultBind.swift +++ b/Decide/Accessor/Default/DefaultBind.swift @@ -14,16 +14,15 @@ import Foundation -/// @propertyWrapper -@MainActor public struct DefaultBind { +@MainActor public struct DefaultBind { @DefaultEnvironment var environment - private let propertyKeyPath: KeyPath> + private let propertyKeyPath: KeyPath> let context: Context public init( - _ keyPath: KeyPath>, + _ keyPath: KeyPath>, file: String = #fileID, line: Int = #line ) { From 1f3f99acfb8826f2f3b57648de7baa3dba7e14d5 Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:24:18 +0200 Subject: [PATCH 02/29] Update DefaultBindKeyed --- Decide/Accessor/Default/DefaultBindKeyed.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Decide/Accessor/Default/DefaultBindKeyed.swift b/Decide/Accessor/Default/DefaultBindKeyed.swift index 7d4b066..3ae31aa 100644 --- a/Decide/Accessor/Default/DefaultBindKeyed.swift +++ b/Decide/Accessor/Default/DefaultBindKeyed.swift @@ -16,15 +16,15 @@ import Foundation /// @propertyWrapper -@MainActor public struct DefaultBindKeyed, Value> { +@MainActor public struct DefaultBindKeyed, Value> { @DefaultEnvironment var environment - private let propertyKeyPath: KeyPath> - private var valueBinding: KeyedValueBinding? + private let propertyKeyPath: KeyPath> + private var valueBinding: KeyedValueBinding? let context: Context public init( - _ keyPath: KeyPath>, + _ keyPath: KeyPath>, file: String = #fileID, line: Int = #line ) { @@ -35,9 +35,9 @@ import Foundation public static subscript( _enclosingInstance instance: EnclosingObject, - wrapped wrappedKeyPath: KeyPath>, + wrapped wrappedKeyPath: KeyPath>, storage storageKeyPath: WritableKeyPath - ) -> KeyedValueBinding { + ) -> KeyedValueBinding { get { var storage = instance[keyPath: storageKeyPath] let propertyKeyPath = storage.propertyKeyPath @@ -60,7 +60,7 @@ import Foundation public var projectedValue: Self { self } @available(*, unavailable, message: "@DefaultBind can only be enclosed by EnvironmentObservingObject.") - public var wrappedValue: KeyedValueBinding { + public var wrappedValue: KeyedValueBinding { get { fatalError() } set { fatalError() } } From 529320a1b90aefb0abb860b5f5428f0dc8c45436 Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:24:53 +0200 Subject: [PATCH 03/29] Update KeyedValueBinding --- Decide/Accessor/Default/DefaultBindKeyed.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Decide/Accessor/Default/DefaultBindKeyed.swift b/Decide/Accessor/Default/DefaultBindKeyed.swift index 3ae31aa..c4ec35e 100644 --- a/Decide/Accessor/Default/DefaultBindKeyed.swift +++ b/Decide/Accessor/Default/DefaultBindKeyed.swift @@ -66,15 +66,15 @@ import Foundation } } -@MainActor public struct KeyedValueBinding, Value> { +@MainActor public struct KeyedValueBinding, Value> { unowned var environment: ApplicationEnvironment let observer: Observer - let propertyKeyPath: KeyPath> + let propertyKeyPath: KeyPath> let context: Context init( - bind propertyKeyPath: KeyPath>, + bind propertyKeyPath: KeyPath>, observer: Observer, environment: ApplicationEnvironment, context: Context @@ -85,7 +85,7 @@ import Foundation self.environment = environment } - public subscript(_ identifier: I) -> Value { + public subscript(_ identifier: Identifier) -> Value { get { environment.subscribe(observer, on: propertyKeyPath, at: identifier) return environment.getValue(propertyKeyPath, at: identifier) From fa4788df3b6f943c998e8c3f470ea98c35e50e56 Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:26:25 +0200 Subject: [PATCH 04/29] Update DefaultObserve --- Decide/Accessor/Default/DefaultObserve.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Decide/Accessor/Default/DefaultObserve.swift b/Decide/Accessor/Default/DefaultObserve.swift index a951c06..10570ff 100644 --- a/Decide/Accessor/Default/DefaultObserve.swift +++ b/Decide/Accessor/Default/DefaultObserve.swift @@ -17,18 +17,18 @@ import Foundation /// @propertyWrapper -@MainActor public struct DefaultObserve { +@MainActor public struct DefaultObserve { @DefaultEnvironment var environment - private let propertyKeyPath: KeyPath> + private let propertyKeyPath: KeyPath> - public init(_ keyPath: KeyPath>) { + public init(_ keyPath: KeyPath>) { self.propertyKeyPath = keyPath } - public init( - _ keyPath: KeyPath - ) where P.Value == Value { + public init( + _ keyPath: KeyPath + ) where WrappedProperty.Value == Value { propertyKeyPath = keyPath.appending(path: \.wrappedValue) } From 12c42072dc45e74893c17c32de7b811cd3c90b73 Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:27:01 +0200 Subject: [PATCH 05/29] Update DefaultObserveKeyed --- .../Default/DefaultObserveKeyed.swift | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Decide/Accessor/Default/DefaultObserveKeyed.swift b/Decide/Accessor/Default/DefaultObserveKeyed.swift index 555e894..0f7a45a 100644 --- a/Decide/Accessor/Default/DefaultObserveKeyed.swift +++ b/Decide/Accessor/Default/DefaultObserveKeyed.swift @@ -17,32 +17,32 @@ import Foundation /// @propertyWrapper @MainActor public struct DefaultObserveKeyed< - I: Hashable, - S: KeyedState, + Identifier: Hashable, + State: KeyedState, Value > { @DefaultEnvironment var environment - private let propertyKeyPath: KeyPath> - private var valueObserve: KeyedValueObserve? + private let propertyKeyPath: KeyPath> + private var valueObserve: KeyedValueObserve? public init( - _ keyPath: KeyPath> + _ keyPath: KeyPath> ) { propertyKeyPath = keyPath } public init( - _ keyPath: KeyPath + _ keyPath: KeyPath ) where P.Value == Value { propertyKeyPath = keyPath.appending(path: \.wrappedValue) } public static subscript( _enclosingInstance instance: EnclosingObject, - wrapped wrappedKeyPath: KeyPath>, + wrapped wrappedKeyPath: KeyPath>, storage storageKeyPath: WritableKeyPath - ) -> KeyedValueObserve { + ) -> KeyedValueObserve { get { var storage = instance[keyPath: storageKeyPath] let propertyKeyPath = storage.propertyKeyPath @@ -50,7 +50,7 @@ import Foundation storage.environment = environment let observer = Observer(instance) if storage.valueObserve == nil { - storage.valueObserve = KeyedValueObserve( + storage.valueObserve = KeyedValueObserve( bind: propertyKeyPath, observer: observer, environment: environment @@ -64,7 +64,7 @@ import Foundation public var projectedValue: Self { self } @available(*, unavailable, message: "@DefaultBind can only be enclosed by EnvironmentObservingObject.") - public var wrappedValue: KeyedValueObserve { + public var wrappedValue: KeyedValueObserve { get { fatalError() } set { fatalError() } } From df251964352ebb2aa835e0146e88aeb3db40e5b3 Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:27:41 +0200 Subject: [PATCH 06/29] Update KeyedValueObserve --- Decide/Accessor/Default/DefaultObserveKeyed.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Decide/Accessor/Default/DefaultObserveKeyed.swift b/Decide/Accessor/Default/DefaultObserveKeyed.swift index 0f7a45a..3c45dfb 100644 --- a/Decide/Accessor/Default/DefaultObserveKeyed.swift +++ b/Decide/Accessor/Default/DefaultObserveKeyed.swift @@ -70,14 +70,14 @@ import Foundation } } -@MainActor public struct KeyedValueObserve, Value> { +@MainActor public struct KeyedValueObserve, Value> { unowned var environment: ApplicationEnvironment let observer: Observer - let propertyKeyPath: KeyPath> + let propertyKeyPath: KeyPath> init( - bind propertyKeyPath: KeyPath>, + bind propertyKeyPath: KeyPath>, observer: Observer, environment: ApplicationEnvironment ) { @@ -86,7 +86,7 @@ import Foundation self.environment = environment } - public subscript(_ identifier: I) -> Value { + public subscript(_ identifier: Identifier) -> Value { get { environment.subscribe(observer, on: propertyKeyPath, at: identifier) return environment.getValue(propertyKeyPath, at: identifier) From e4f016bd4ec3e7b78c07bd8b5de64d5ada083fc8 Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:28:34 +0200 Subject: [PATCH 07/29] Update Bind --- Decide/Accessor/SwiftUI/Bind.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Decide/Accessor/SwiftUI/Bind.swift b/Decide/Accessor/SwiftUI/Bind.swift index 98ba4f0..f6db033 100644 --- a/Decide/Accessor/SwiftUI/Bind.swift +++ b/Decide/Accessor/SwiftUI/Bind.swift @@ -17,14 +17,18 @@ import SwiftUI /// **SwiftUI** property wrapper that provides two-way access to the value by ``Property`` KeyPath on ``AtomicState``from the view environment. @propertyWrapper -@MainActor public struct Bind: DynamicProperty { +@MainActor public struct Bind: DynamicProperty { @SwiftUI.Environment(\.stateEnvironment) var environment @ObservedObject var observer = ObservedObjectWillChangeNotification() let context: Context - let propertyKeyPath: KeyPath> + let propertyKeyPath: KeyPath> - public init(_ propertyKeyPath: KeyPath>, file: String = #fileID, line: Int = #line) { + public init( + _ propertyKeyPath: KeyPath>, + file: String = #fileID, + line: Int = #line + ) { let context = Context(file: file, line: line) self.context = context self.propertyKeyPath = propertyKeyPath.appending(path: \.wrappedValue) From fa8037f4d360c8f2cb1159d33ed4bceec1e19367 Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:29:35 +0200 Subject: [PATCH 08/29] Update BindKeyed --- Decide/Accessor/SwiftUI/BindKeyed.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Decide/Accessor/SwiftUI/BindKeyed.swift b/Decide/Accessor/SwiftUI/BindKeyed.swift index 97106ec..9c32d02 100644 --- a/Decide/Accessor/SwiftUI/BindKeyed.swift +++ b/Decide/Accessor/SwiftUI/BindKeyed.swift @@ -16,22 +16,22 @@ import SwiftUI /// **SwiftUI** property wrapper that provides two-way access to the value by ``Property`` KeyPath and a Key on ``KeyedState`` from the view environment. @propertyWrapper -@MainActor public struct BindKeyed, Value>: DynamicProperty { +@MainActor public struct BindKeyed, Value>: DynamicProperty { @SwiftUI.Environment(\.stateEnvironment) var environment @ObservedObject var observer = ObservedObjectWillChangeNotification() let context: Context - let propertyKeyPath: KeyPath> + let propertyKeyPath: KeyPath> - public init(_ propertyKeyPath: KeyPath>, file: String = #fileID, line: Int = #line) { + public init(_ propertyKeyPath: KeyPath>, file: String = #fileID, line: Int = #line) { let context = Context(file: file, line: line) self.context = context self.propertyKeyPath = propertyKeyPath.appending(path: \.wrappedValue) } - public subscript(_ identifier: I) -> Binding { + public subscript(_ identifier: Identifier) -> Binding { Binding( get: { environment.subscribe( @@ -47,7 +47,7 @@ import SwiftUI ) } - public subscript(_ identifier: I) -> Value { + public subscript(_ identifier: Identifier) -> Value { get { environment.subscribe(Observer(observer), on: propertyKeyPath, at: identifier) return environment.getValue(propertyKeyPath, at: identifier) From 9fa4515689d190766b6fa0ac0df01525a601d94e Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:30:06 +0200 Subject: [PATCH 09/29] Update Observe --- Decide/Accessor/SwiftUI/Observe.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Decide/Accessor/SwiftUI/Observe.swift b/Decide/Accessor/SwiftUI/Observe.swift index 3484462..94dce81 100644 --- a/Decide/Accessor/SwiftUI/Observe.swift +++ b/Decide/Accessor/SwiftUI/Observe.swift @@ -17,18 +17,18 @@ import SwiftUI /// **SwiftUI** property wrapper that provides read only access to the value by ``Property`` KeyPath on ``AtomicState``from the view environment. @propertyWrapper -@MainActor public struct Observe: DynamicProperty { +@MainActor public struct Observe: DynamicProperty { @SwiftUI.Environment(\.stateEnvironment) var environment @ObservedObject var observer = ObservedObjectWillChangeNotification() - let propertyKeyPath: KeyPath> + let propertyKeyPath: KeyPath> - public init(_ propertyKeyPath: KeyPath>) { + public init(_ propertyKeyPath: KeyPath>) { self.propertyKeyPath = propertyKeyPath } public init( - _ propertyKeyPath: KeyPath + _ propertyKeyPath: KeyPath ) where P.Value == Value { self.propertyKeyPath = propertyKeyPath.appending(path: \.wrappedValue) } From dae77fe316080e1271cdf866fd128cd9e630907c Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:30:36 +0200 Subject: [PATCH 10/29] Update BindKeyed init --- Decide/Accessor/SwiftUI/BindKeyed.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Decide/Accessor/SwiftUI/BindKeyed.swift b/Decide/Accessor/SwiftUI/BindKeyed.swift index 9c32d02..5c6a26b 100644 --- a/Decide/Accessor/SwiftUI/BindKeyed.swift +++ b/Decide/Accessor/SwiftUI/BindKeyed.swift @@ -25,7 +25,11 @@ import SwiftUI let propertyKeyPath: KeyPath> - public init(_ propertyKeyPath: KeyPath>, file: String = #fileID, line: Int = #line) { + public init( + _ propertyKeyPath: KeyPath>, + file: String = #fileID, + line: Int = #line + ) { let context = Context(file: file, line: line) self.context = context self.propertyKeyPath = propertyKeyPath.appending(path: \.wrappedValue) From 7aa266b56e40a420606b5908eb4ba39876b4bf2b Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:31:37 +0200 Subject: [PATCH 11/29] Update ObserveKeyed --- Decide/Accessor/SwiftUI/ObserveKeyed.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Decide/Accessor/SwiftUI/ObserveKeyed.swift b/Decide/Accessor/SwiftUI/ObserveKeyed.swift index 34e9fc9..5b1efa0 100644 --- a/Decide/Accessor/SwiftUI/ObserveKeyed.swift +++ b/Decide/Accessor/SwiftUI/ObserveKeyed.swift @@ -17,27 +17,27 @@ import SwiftUI /// **SwiftUI** property wrapper that provides read only access to the value by ``Property`` KeyPath and a Key on ``KeyedState`` from the view environment. @propertyWrapper @MainActor public struct ObserveKeyed< - I: Hashable, - S: KeyedState, + Identifier: Hashable, + State: KeyedState, Value >: DynamicProperty { @SwiftUI.Environment(\.stateEnvironment) var environment @ObservedObject var observer = ObservedObjectWillChangeNotification() - let propertyKeyPath: KeyPath> + let propertyKeyPath: KeyPath> - public init(_ propertyKeyPath: KeyPath>) { + public init(_ propertyKeyPath: KeyPath>) { self.propertyKeyPath = propertyKeyPath } public init( - _ propertyKeyPath: KeyPath + _ propertyKeyPath: KeyPath ) where P.Value == Value { self.propertyKeyPath = propertyKeyPath.appending(path: \.wrappedValue) } - public subscript(_ identifier: I) -> Value { + public subscript(_ identifier: Identifier) -> Value { get { environment.subscribe(Observer(observer), on: propertyKeyPath, at: identifier) return environment.getValue(propertyKeyPath, at: identifier) From 5c855828370ee84b383b19199d7e6b0e5efe978b Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:32:48 +0200 Subject: [PATCH 12/29] Update DefaultObserveKeyed WrappedProperty --- Decide/Accessor/Default/DefaultObserveKeyed.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Decide/Accessor/Default/DefaultObserveKeyed.swift b/Decide/Accessor/Default/DefaultObserveKeyed.swift index 3c45dfb..96aaa06 100644 --- a/Decide/Accessor/Default/DefaultObserveKeyed.swift +++ b/Decide/Accessor/Default/DefaultObserveKeyed.swift @@ -32,9 +32,9 @@ import Foundation propertyKeyPath = keyPath } - public init( - _ keyPath: KeyPath - ) where P.Value == Value { + public init( + _ keyPath: KeyPath + ) where WrappedProperty.Value == Value { propertyKeyPath = keyPath.appending(path: \.wrappedValue) } From c736cb8c85a933314b5a4a04a6e489f031294f4e Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:33:35 +0200 Subject: [PATCH 13/29] Update Observe WrappedProperty --- Decide/Accessor/SwiftUI/Observe.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Decide/Accessor/SwiftUI/Observe.swift b/Decide/Accessor/SwiftUI/Observe.swift index 94dce81..b604616 100644 --- a/Decide/Accessor/SwiftUI/Observe.swift +++ b/Decide/Accessor/SwiftUI/Observe.swift @@ -27,9 +27,9 @@ import SwiftUI self.propertyKeyPath = propertyKeyPath } - public init( - _ propertyKeyPath: KeyPath - ) where P.Value == Value { + public init( + _ propertyKeyPath: KeyPath + ) where WrappedProperty.Value == Value { self.propertyKeyPath = propertyKeyPath.appending(path: \.wrappedValue) } From a0eacb4d5a121c1ba7784e959723c0004c64e943 Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:33:57 +0200 Subject: [PATCH 14/29] Update ObserveKeyed WrappedProperty --- Decide/Accessor/SwiftUI/ObserveKeyed.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Decide/Accessor/SwiftUI/ObserveKeyed.swift b/Decide/Accessor/SwiftUI/ObserveKeyed.swift index 5b1efa0..dfb2f0e 100644 --- a/Decide/Accessor/SwiftUI/ObserveKeyed.swift +++ b/Decide/Accessor/SwiftUI/ObserveKeyed.swift @@ -31,9 +31,9 @@ import SwiftUI self.propertyKeyPath = propertyKeyPath } - public init( - _ propertyKeyPath: KeyPath - ) where P.Value == Value { + public init( + _ propertyKeyPath: KeyPath + ) where WrappedProperty.Value == Value { self.propertyKeyPath = propertyKeyPath.appending(path: \.wrappedValue) } From 9f63861c6e9e1b14be085c93e35414133b40e68e Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:35:25 +0200 Subject: [PATCH 15/29] Update Instance --- Decide/Accessor/Instance.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Decide/Accessor/Instance.swift b/Decide/Accessor/Instance.swift index dd6ae1e..ad7a293 100644 --- a/Decide/Accessor/Instance.swift +++ b/Decide/Accessor/Instance.swift @@ -14,21 +14,21 @@ import SwiftUI @propertyWrapper -@MainActor public struct Instance { +@MainActor public struct Instance { - public typealias PropertyKeyPath = KeyPath> + public typealias PropertyKeyPath = KeyPath> private let instanceKeyPath: PropertyKeyPath - public init(_ keyPath: KeyPath>) { + public init(_ keyPath: KeyPath>) { self.instanceKeyPath = keyPath } public static subscript( _enclosingInstance instance: EnclosingObject, - wrapped wrappedKeyPath: KeyPath, + wrapped wrappedKeyPath: KeyPath, storage storageKeyPath: KeyPath - ) -> O { + ) -> Object { get { let storage = instance[keyPath: storageKeyPath] let instanceKeyPath = storage.instanceKeyPath @@ -38,7 +38,7 @@ import SwiftUI } @available(*, unavailable, message: "@Instance must be enclosed in EnvironmentManagedObject.") - public var wrappedValue: O { + public var wrappedValue: Object { get { fatalError() } } } From 5c94a1b731eafd4bb88dd1c7d525299ee8561f91 Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:35:58 +0200 Subject: [PATCH 16/29] Update defaultInstance function --- Decide/Accessor/Instance.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Decide/Accessor/Instance.swift b/Decide/Accessor/Instance.swift index ad7a293..215786c 100644 --- a/Decide/Accessor/Instance.swift +++ b/Decide/Accessor/Instance.swift @@ -44,10 +44,10 @@ import SwiftUI } extension ApplicationEnvironment { - func defaultInstance( - at keyPath: KeyPath> - ) -> DefaultInstance { - let storage: S = self[S.key()] + func defaultInstance( + at keyPath: KeyPath> + ) -> DefaultInstance { + let storage: State = self[State.key()] return storage[keyPath: keyPath] } } From 7df6b2e3efa2615af1592fe366298a3114cccc3f Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:37:17 +0200 Subject: [PATCH 17/29] Update AtomicState --- Decide/Container/AtomicState.swift | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Decide/Container/AtomicState.swift b/Decide/Container/AtomicState.swift index 37fff5f..1bad081 100644 --- a/Decide/Container/AtomicState.swift +++ b/Decide/Container/AtomicState.swift @@ -40,17 +40,17 @@ extension ApplicationEnvironment { //===------------------------------------------------------------------===// // MARK: - Observability //===------------------------------------------------------------------===// - func notifyObservers( - _ keyPath: KeyPath> + func notifyObservers( + _ keyPath: KeyPath> ) { let observers = popObservers(keyPath) observers.forEach { $0.notify() } } - func popObservers( - _ keyPath: KeyPath> + func popObservers( + _ keyPath: KeyPath> ) -> Set { - let storage: S = self[S.key()] + let storage: State = self[State.key()] return storage[keyPath: keyPath].valueContainer.observerStorage.popObservers() } @@ -60,23 +60,23 @@ extension ApplicationEnvironment { //===------------------------------------------------------------------===// /// Subscribe ``Observer`` at ``Property`` KeyPath on ``AtomicState``. - func subscribe( + func subscribe( _ observer: Observer, - on keyPath: KeyPath> + on keyPath: KeyPath> ) { - let storage: S = self[S.key()] + let storage: State = self[State.key()] storage[keyPath: keyPath].projectedValue.valueContainer.observerStorage.subscribe(observer) } /// Get value at ``Property`` KeyPath on ``AtomicState``. - func getValue(_ keyPath: KeyPath>) -> Value { - let storage: S = self[S.key()] + func getValue(_ keyPath: KeyPath>) -> Value { + let storage: State = self[State.key()] return storage[keyPath: keyPath].wrappedValue } /// Set value at ``Property`` KeyPath on ``AtomicState``. - func setValue(_ newValue: Value, _ keyPath: KeyPath>) { - let storage: S = self[S.key()] + func setValue(_ newValue: Value, _ keyPath: KeyPath>) { + let storage: State = self[State.key()] storage[keyPath: keyPath].wrappedValue = newValue notifyObservers(keyPath) } From 79ddfd486574b8fb8d6e74f4ca68afd68842a7d9 Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:37:58 +0200 Subject: [PATCH 18/29] Update DefaultInstance --- Decide/Container/DefaultInstance.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Decide/Container/DefaultInstance.swift b/Decide/Container/DefaultInstance.swift index ba838bc..f65f5a8 100644 --- a/Decide/Container/DefaultInstance.swift +++ b/Decide/Container/DefaultInstance.swift @@ -16,8 +16,8 @@ import Foundation /// Managed by ``ApplicationEnvironment`` storage for objects, unlike ``Property`` it doesn't support mutation nor observation. @propertyWrapper -@MainActor public final class DefaultInstance { - public var wrappedValue: O { +@MainActor public final class DefaultInstance { + public var wrappedValue: Object { get { if let storage { return storage } let newValue = defaultValue() @@ -26,19 +26,19 @@ import Foundation } } - public var projectedValue: DefaultInstance { + public var projectedValue: DefaultInstance { self } - public init(wrappedValue: @autoclosure @escaping () -> O, file: StaticString = #fileID, line: UInt = #line) { + public init(wrappedValue: @autoclosure @escaping () -> Object, file: StaticString = #fileID, line: UInt = #line) { self.defaultValue = wrappedValue self.file = file.description self.line = line } // MARK: - Value Storage - private var storage: O? - private let defaultValue: () -> O + private var storage: Object? + private let defaultValue: () -> Object // MARK: - Tracing let file: String From d931be1240249fe37f31fedf1ea8162edd63c9fe Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:40:26 +0200 Subject: [PATCH 19/29] Update KeyedState --- Decide/Container/KeyedState.swift | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Decide/Container/KeyedState.swift b/Decide/Container/KeyedState.swift index 0eae8a1..f4126f7 100644 --- a/Decide/Container/KeyedState.swift +++ b/Decide/Container/KeyedState.swift @@ -35,9 +35,9 @@ extension ApplicationEnvironment { // MARK: - Observability //===------------------------------------------------------------------===// - func notifyObservers, Value>( - _ keyPath: KeyPath>, - _ identifier: I + func notifyObservers, Value>( + _ keyPath: KeyPath>, + _ identifier: Identifier ) { let observers = popObservers(keyPath, identifier) observers.forEach { $0.notify() } @@ -56,31 +56,31 @@ extension ApplicationEnvironment { //===------------------------------------------------------------------===// /// Subscribe ``ObservableValue`` at ``Property`` KeyPath on ``KeyedState``. - func subscribe, Value>( + func subscribe, Value>( _ observer: Observer, - on keyPath: KeyPath>, - at identifier: I + on keyPath: KeyPath>, + at identifier: Identifier ) { - let storage: S = self[S.key(identifier)] + let storage: State = self[State.key(identifier)] storage[keyPath: keyPath].projectedValue.valueContainer.observerStorage.subscribe(observer) } /// Get value at ``Property`` KeyPath on ``KeyedState``. - func getValue, Value>( - _ keyPath: KeyPath>, - at identifier: I + func getValue, Value>( + _ keyPath: KeyPath>, + at identifier: Identifier ) -> Value { - let storage: S = self[S.key(identifier)] + let storage: State = self[State.key(identifier)] return storage[keyPath: keyPath].wrappedValue } /// Set value at ``Property`` KeyPath on ``KeyedState``. - func setValue, Value>( + func setValue, Value>( _ newValue: Value, - _ keyPath: KeyPath>, - at identifier: I + _ keyPath: KeyPath>, + at identifier: Identifier ) { - let storage: S = self[S.key(identifier)] + let storage: State = self[State.key(identifier)] storage[keyPath: keyPath].wrappedValue = newValue notifyObservers(keyPath, identifier) } From 18eee597bb0fe24498a4ae7c3bb3f8a91ddbb334 Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:41:13 +0200 Subject: [PATCH 20/29] Update ApplicationEnvironment --- Decide/Environment/Environment.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Decide/Environment/Environment.swift b/Decide/Environment/Environment.swift index 30bee9a..28cce2b 100644 --- a/Decide/Environment/Environment.swift +++ b/Decide/Environment/Environment.swift @@ -44,9 +44,9 @@ import Foundation return Telemetry(observer: OSLogTelemetryObserver()) // .noTelemetry }() - subscript(_ key: Key) -> S { - if let state = storage[key] as? S { return state } - let newValue = S.init() + subscript(_ key: Key) -> Storage { + if let state = storage[key] as? Storage { return state } + let newValue = Storage.init() storage[key] = newValue return newValue } From 2d77301dbd0ec876430ea54ee64fc408bf3046e5 Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:43:10 +0200 Subject: [PATCH 21/29] Update DecisionEnvironment --- Decide/Structured State Mutation/Decision.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Decide/Structured State Mutation/Decision.swift b/Decide/Structured State Mutation/Decision.swift index 72b76d4..24b10ea 100644 --- a/Decide/Structured State Mutation/Decision.swift +++ b/Decide/Structured State Mutation/Decision.swift @@ -46,9 +46,9 @@ import Foundation } } - public subscript, Value>( + public subscript, Value>( _ propertyKeyPath: KeyPath>, - at identifier: ID + at identifier: Identifier ) -> Value { get { environment.getValue(propertyKeyPath, at: identifier) @@ -68,17 +68,17 @@ import Foundation } /// Set value at ``Property`` KeyPath on ``KeyedState``. - func setValue, Value>( + func setValue, Value>( _ keyPath: KeyPath>, _ newValue: Value, - at identifier: ID + at identifier: Identifier ) { transactions.insert( Transaction(keyPath, newValue: newValue, at: identifier) ) } - public func perform(effect: E) { + public func perform(effect: SideEffect) { effects.append(effect) } } From 839aa0fbaf91dfcd7f1522b2ce50994913cdff4b Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:45:19 +0200 Subject: [PATCH 22/29] Update EffectEnvironment --- Decide/Structured State Mutation/Effect.swift | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Decide/Structured State Mutation/Effect.swift b/Decide/Structured State Mutation/Effect.swift index 82c5d8f..e354c5e 100644 --- a/Decide/Structured State Mutation/Effect.swift +++ b/Decide/Structured State Mutation/Effect.swift @@ -28,30 +28,30 @@ public protocol Effect: Actor { self.environment = environment } - public subscript(_ propertyKeyPath: KeyPath>) -> V { + public subscript(_ propertyKeyPath: KeyPath>) -> Value { get { environment.getValue(propertyKeyPath) } } - public subscript( - _ propertyKeyPath: KeyPath>, - at identifier: I - ) -> V - where I: Hashable, S: KeyedState + public subscript( + _ propertyKeyPath: KeyPath>, + at identifier: Identifier + ) -> Value + where Identifier: Hashable, State: KeyedState { get { environment.getValue(propertyKeyPath, at: identifier) } } - public subscript(_ propertyKeyPath: KeyPath>) -> V { + public subscript(_ propertyKeyPath: KeyPath>) -> Value { get { environment.getValue(propertyKeyPath.appending(path: \.wrappedValue)) } } - public subscript( - _ propertyKeyPath: KeyPath>, - at identifier: I - ) -> V - where I: Hashable, S: KeyedState + public subscript( + _ propertyKeyPath: KeyPath>, + at identifier: Identifier + ) -> Value + where Identifier: Hashable, State: KeyedState { get { environment.getValue(propertyKeyPath.appending(path: \.wrappedValue), at: identifier) @@ -63,14 +63,14 @@ public protocol Effect: Actor { await environment.makeAwaiting(decision: decision) } - @MainActor public func instance(_ keyPath: KeyPath>) -> O { - let obj = environment.defaultInstance(at: keyPath).wrappedValue - return obj + @MainActor public func instance(_ keyPath: KeyPath>) -> Object { + let object = environment.defaultInstance(at: keyPath).wrappedValue + return object } - @MainActor public func instance(_ keyPath: KeyPath>) -> O { - let obj = environment.defaultInstance(at: keyPath).wrappedValue - obj.environment = self.environment - return obj + @MainActor public func instance(_ keyPath: KeyPath>) -> Object { + let object = environment.defaultInstance(at: keyPath).wrappedValue + object.environment = self.environment + return object } } From 532958e6d8536c7d2aee13625fa13fb1e2b76895 Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:46:05 +0200 Subject: [PATCH 23/29] Update Transaction --- Decide/Structured State Mutation/Transaction.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Decide/Structured State Mutation/Transaction.swift b/Decide/Structured State Mutation/Transaction.swift index fe8f10e..3488015 100644 --- a/Decide/Structured State Mutation/Transaction.swift +++ b/Decide/Structured State Mutation/Transaction.swift @@ -49,10 +49,10 @@ final class Transaction: Hashable { self.identity = propertyKeyPath } - @MainActor init, Value>( + @MainActor init, Value>( _ propertyKeyPath: KeyPath>, newValue: Value, - at identifier: ID + at identifier: Identifier ) { self.mutate = { environment in environment.setValue(newValue, propertyKeyPath, at: identifier) From 31643c450da57d44a425baa5ceb19e0dab5895ad Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:46:33 +0200 Subject: [PATCH 24/29] Update UnstructuredMutation --- Decide/Telemetry/Events/UnstructuredMutation.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Decide/Telemetry/Events/UnstructuredMutation.swift b/Decide/Telemetry/Events/UnstructuredMutation.swift index 0e95cd7..9dd869d 100644 --- a/Decide/Telemetry/Events/UnstructuredMutation.swift +++ b/Decide/Telemetry/Events/UnstructuredMutation.swift @@ -14,16 +14,16 @@ import OSLog -final class UnstructuredMutation: TelemetryEvent { +final class UnstructuredMutation: TelemetryEvent { let category: String = "Unstructured State Mutation" let name: String = "Property updated:" let logLevel: OSLogType = .debug let context: Decide.Context let keyPath: String - let value: V + let value: Value - init(context: Decide.Context, keyPath: String, value: V) { + init(context: Decide.Context, keyPath: String, value: Value) { self.keyPath = keyPath self.context = context self.value = value From 2914929dd4bf29ea5fb5d4c9f8705cafafb127da Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:47:38 +0200 Subject: [PATCH 25/29] Update OSLogTelemetryObserver --- Decide/Telemetry/LoggerObserver.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Decide/Telemetry/LoggerObserver.swift b/Decide/Telemetry/LoggerObserver.swift index d73c4a8..fa3e290 100644 --- a/Decide/Telemetry/LoggerObserver.swift +++ b/Decide/Telemetry/LoggerObserver.swift @@ -41,7 +41,7 @@ final class OSLogTelemetryObserver: TelemetryObserver { return false }() - func eventDidOccur(_ event: E) where E : TelemetryEvent { + func eventDidOccur(_ event: Event) where Event: TelemetryEvent { let logger = Logger(subsystem: Self.subsystem, category: event.category) if Self.unsafeTracingEnabled { unsafeTrace(event: event, logger: logger) @@ -51,7 +51,7 @@ final class OSLogTelemetryObserver: TelemetryObserver { } - func trace(event: E, logger: Logger) where E : TelemetryEvent { + func trace(event: Event, logger: Logger) where Event: TelemetryEvent { switch event.logLevel { case .debug: logger.debug("\(event.name): \(event.message(), privacy: .sensitive)\n context: \(event.context.debugDescription)") @@ -66,7 +66,7 @@ final class OSLogTelemetryObserver: TelemetryObserver { } } - func unsafeTrace(event: E, logger: Logger) where E : TelemetryEvent { + func unsafeTrace(event: Event, logger: Logger) where Event: TelemetryEvent { switch event.logLevel { case .debug: logger.debug("\(event.name): \(event.message(), privacy: .sensitive)\n context: \(event.context.debugDescription)") From acb55bd56cb1a1ad0d444d6060971ab5b9e0874a Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:48:31 +0200 Subject: [PATCH 26/29] Update Telemetry --- Decide/Telemetry/Telemetry.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Decide/Telemetry/Telemetry.swift b/Decide/Telemetry/Telemetry.swift index b4e9180..21a1e5a 100644 --- a/Decide/Telemetry/Telemetry.swift +++ b/Decide/Telemetry/Telemetry.swift @@ -27,7 +27,7 @@ final class Telemetry { self.observer = observer } - func log(event: E) { + func log(event: Event) { guard event.logLevel.rawValue >= self.logLevel.rawValue else { return } observer.eventDidOccur(event) @@ -35,7 +35,7 @@ final class Telemetry { } final class DoNotObserve: TelemetryObserver { - func eventDidOccur(_ event: E) where E : TelemetryEvent {} + func eventDidOccur(_ event: Event) where Event : TelemetryEvent {} } extension Telemetry { static let noTelemetry = Telemetry(observer: DoNotObserve()) @@ -54,6 +54,6 @@ protocol TelemetryEvent { protocol TelemetryObserver { /// Called every time an event with debug level /// equal or greater than current occur. - func eventDidOccur(_ event: E) + func eventDidOccur(_ event: Event) } From 4f80834cddfb7ee1836b63661486034184684735 Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:52:10 +0200 Subject: [PATCH 27/29] Update AssertValueAt --- DecideTesting/AssertValueAt.swift | 70 +++++++++++++++---------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/DecideTesting/AssertValueAt.swift b/DecideTesting/AssertValueAt.swift index dc3ca4f..2f829c3 100644 --- a/DecideTesting/AssertValueAt.swift +++ b/DecideTesting/AssertValueAt.swift @@ -21,9 +21,9 @@ public extension ApplicationEnvironment { //===------------------------------------------------------------------===// /// Asserts that value of given container is equal to given value. - func AssertValueIn( - _ valueA: V, - isEqual valueB: V, + func AssertValueIn( + _ valueA: Value, + isEqual valueB: Value, file: StaticString = #file, line: UInt = #line ) { @@ -37,46 +37,46 @@ public extension ApplicationEnvironment { /// Asserts that value at given KeyPath is equal to given value. func AssertValueAt< - P: PropertyModifier, - V: Equatable, - S: AtomicState - > ( - _ keyPath: KeyPath, - isEqual value: V, + WrappedProperty: PropertyModifier, + Value: Equatable, + State: AtomicState + >( + _ keyPath: KeyPath, + isEqual value: Value, file: StaticString = #file, line: UInt = #line - ) where P.Value == V { + ) where WrappedProperty.Value == Value { let containerValue = getValue(keyPath.appending(path: \.wrappedValue)) AssertValueIn(containerValue, isEqual: value, file: file, line: line) } /// Asserts that value at given KeyPath is equal to given value. func AssertValueAt< - V: Equatable, - S: AtomicState + Value: Equatable, + State: AtomicState >( - _ keyPath: KeyPath>, - isEqual value: V, + _ keyPath: KeyPath>, + isEqual value: Value, file: StaticString = #file, line: UInt = #line ) { let containerValue = getValue(keyPath) AssertValueIn(containerValue, isEqual: value, file: file, line: line) } - + //===------------------------------------------------------------------===// // MARK: - Keyed //===------------------------------------------------------------------===// /// Asserts that value of given container and Identifier is equal to given value. func AssertValueIn< - V: Equatable, - I: Hashable, - S: KeyedState + Value: Equatable, + Identifier: Hashable, + State: KeyedState >( - _ valueA: V, - identifier: I, - isEqual valueB: V, + _ valueA: Value, + identifier: Identifier, + isEqual valueB: Value, file: StaticString = #file, line: UInt = #line ) { @@ -89,30 +89,30 @@ public extension ApplicationEnvironment { /// Asserts that value at given KeyPath and Identifier is equal to given value. func AssertValueAt< - P: PropertyModifier, - V: Equatable, - I: Hashable, - S: KeyedState + WrappedProperty: PropertyModifier, + Value: Equatable, + Identifier: Hashable, + State: KeyedState >( - _ keyPath: KeyPath, - at identifier: I, - isEqual value: V, + _ keyPath: KeyPath, + at identifier: Identifier, + isEqual value: Value, file: StaticString = #file, line: UInt = #line - ) where P.Value == V { + ) where WrappedProperty.Value == Value { let containerValue = getValue(keyPath.appending(path: \.wrappedValue), at: identifier) AssertValueIn(containerValue, identifier: identifier, isEqual: value, file: file, line: line) } /// Asserts that value at given KeyPath and Identifier is equal to given value. func AssertValueAt< - V: Equatable, - I: Hashable, - S: KeyedState + Value: Equatable, + Identifier: Hashable, + State: KeyedState >( - _ keyPath: KeyPath>, - at identifier: I, - isEqual value: V, + _ keyPath: KeyPath>, + at identifier: Identifier, + isEqual value: Value, file: StaticString = #file, line: UInt = #line ) { From 95601a7e63b7495a31d3bbcec06380ef65afaf1e Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:52:24 +0200 Subject: [PATCH 28/29] Update Mirror+EnvironmentOverride --- DecideTesting/Mirror+EnvironmentOverride.swift | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/DecideTesting/Mirror+EnvironmentOverride.swift b/DecideTesting/Mirror+EnvironmentOverride.swift index b573cbd..185ba99 100644 --- a/DecideTesting/Mirror+EnvironmentOverride.swift +++ b/DecideTesting/Mirror+EnvironmentOverride.swift @@ -14,7 +14,10 @@ import Decide -@MainActor public func WithEnvironment(_ environment: ApplicationEnvironment, object: T) -> T { +@MainActor public func WithEnvironment( + _ environment: ApplicationEnvironment, + object: Object +) -> Object { Mirror(reflecting: object).replaceEnvironment(with: environment) return object } @@ -27,12 +30,12 @@ private extension Mirror { } @MainActor func replaceEnvironment(on child: inout Mirror.Child, with newEnvironment: ApplicationEnvironment) { - if let obj = child.value as? DefaultEnvironment { - obj.wrappedValue = newEnvironment + if let object = child.value as? DefaultEnvironment { + object.wrappedValue = newEnvironment return } - let m = Mirror(reflecting: child.value) - m.replaceEnvironment(with: newEnvironment) + let mirror = Mirror(reflecting: child.value) + mirror.replaceEnvironment(with: newEnvironment) } } From f777f6ca01dde2686f74595026b8c36855a1bfdc Mon Sep 17 00:00:00 2001 From: Serj Agopian Date: Sat, 2 Sep 2023 10:53:45 +0200 Subject: [PATCH 29/29] Update SetValue+Environment --- DecideTesting/SetValue+Environment.swift | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/DecideTesting/SetValue+Environment.swift b/DecideTesting/SetValue+Environment.swift index 32b1c85..17271de 100644 --- a/DecideTesting/SetValue+Environment.swift +++ b/DecideTesting/SetValue+Environment.swift @@ -17,16 +17,19 @@ import OSLog public extension ApplicationEnvironment { /// Set value at ``Mutable`` KeyPath on ``AtomicState``. - func setValue(_ newValue: Value, _ keyPath: KeyPath>) { + func setValue( + _ newValue: Value, + _ keyPath: KeyPath> + ) { setValue(newValue, keyPath.appending(path: \.wrappedValue)) telemetry.log(event: TestingMutation(context: .init(), keyPath: "\(keyPath)", value: newValue)) } /// Set value at ``Mutable`` KeyPath on ``AtomicState``. - func setValue, Value>( + func setValue, Value>( _ newValue: Value, - _ keyPath: KeyPath>, - at identifier: I + _ keyPath: KeyPath>, + at identifier: Identifier ) { setValue(newValue, keyPath.appending(path: \.wrappedValue), at: identifier) telemetry.log(event: TestingMutation(context: .init(), keyPath: "\(keyPath):\(identifier)", value: newValue)) @@ -34,16 +37,16 @@ public extension ApplicationEnvironment { } -final class TestingMutation: TelemetryEvent { +final class TestingMutation: TelemetryEvent { let category: String = "Testing: State Mutation" let name: String = "Property updated:" let logLevel: OSLogType = .debug let context: Decide.Context let keyPath: String - let value: V + let value: Value - init(context: Decide.Context, keyPath: String, value: V) { + init(context: Decide.Context, keyPath: String, value: Value) { self.keyPath = keyPath self.context = context self.value = value