Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up generics #37

Merged
merged 29 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e522711
Update DefaultBind
serjooo Sep 2, 2023
1f3f99a
Update DefaultBindKeyed
serjooo Sep 2, 2023
529320a
Update KeyedValueBinding
serjooo Sep 2, 2023
fa4788d
Update DefaultObserve
serjooo Sep 2, 2023
12c4207
Update DefaultObserveKeyed
serjooo Sep 2, 2023
df25196
Update KeyedValueObserve
serjooo Sep 2, 2023
e4f016b
Update Bind
serjooo Sep 2, 2023
fa8037f
Update BindKeyed
serjooo Sep 2, 2023
9fa4515
Update Observe
serjooo Sep 2, 2023
dae77fe
Update BindKeyed init
serjooo Sep 2, 2023
7aa266b
Update ObserveKeyed
serjooo Sep 2, 2023
5c85582
Update DefaultObserveKeyed WrappedProperty
serjooo Sep 2, 2023
c736cb8
Update Observe WrappedProperty
serjooo Sep 2, 2023
a0eacb4
Update ObserveKeyed WrappedProperty
serjooo Sep 2, 2023
9f63861
Update Instance
serjooo Sep 2, 2023
5c94a1b
Update defaultInstance function
serjooo Sep 2, 2023
7df6b2e
Update AtomicState
serjooo Sep 2, 2023
79ddfd4
Update DefaultInstance
serjooo Sep 2, 2023
d931be1
Update KeyedState
serjooo Sep 2, 2023
18eee59
Update ApplicationEnvironment
serjooo Sep 2, 2023
2d77301
Update DecisionEnvironment
serjooo Sep 2, 2023
839aa0f
Update EffectEnvironment
serjooo Sep 2, 2023
532958e
Update Transaction
serjooo Sep 2, 2023
31643c4
Update UnstructuredMutation
serjooo Sep 2, 2023
2914929
Update OSLogTelemetryObserver
serjooo Sep 2, 2023
acb55bd
Update Telemetry
serjooo Sep 2, 2023
4f80834
Update AssertValueAt
serjooo Sep 2, 2023
95601a7
Update Mirror+EnvironmentOverride
serjooo Sep 2, 2023
f777f6c
Update SetValue+Environment
serjooo Sep 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Decide/Accessor/Default/DefaultBind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@

import Foundation

///
@propertyWrapper
@MainActor public struct DefaultBind<S: AtomicState, Value> {
@MainActor public struct DefaultBind<State: AtomicState, Value> {
@DefaultEnvironment var environment

private let propertyKeyPath: KeyPath<S, Property<Value>>
private let propertyKeyPath: KeyPath<State, Property<Value>>
let context: Context

public init(
_ keyPath: KeyPath<S, Mutable<Value>>,
_ keyPath: KeyPath<State, Mutable<Value>>,
file: String = #fileID,
line: Int = #line
) {
Expand Down
22 changes: 11 additions & 11 deletions Decide/Accessor/Default/DefaultBindKeyed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import Foundation

///
@propertyWrapper
@MainActor public struct DefaultBindKeyed<I: Hashable, S: KeyedState<I>, Value> {
@MainActor public struct DefaultBindKeyed<Identifier: Hashable, State: KeyedState<Identifier>, Value> {
@DefaultEnvironment var environment

private let propertyKeyPath: KeyPath<S, Property<Value>>
private var valueBinding: KeyedValueBinding<I, S, Value>?
private let propertyKeyPath: KeyPath<State, Property<Value>>
private var valueBinding: KeyedValueBinding<Identifier, State, Value>?
let context: Context

public init(
_ keyPath: KeyPath<S, Mutable<Value>>,
_ keyPath: KeyPath<State, Mutable<Value>>,
file: String = #fileID,
line: Int = #line
) {
Expand All @@ -35,9 +35,9 @@ import Foundation

public static subscript<EnclosingObject: EnvironmentObservingObject>(
_enclosingInstance instance: EnclosingObject,
wrapped wrappedKeyPath: KeyPath<EnclosingObject, KeyedValueBinding<I, S, Value>>,
wrapped wrappedKeyPath: KeyPath<EnclosingObject, KeyedValueBinding<Identifier, State, Value>>,
storage storageKeyPath: WritableKeyPath<EnclosingObject, Self>
) -> KeyedValueBinding<I, S, Value> {
) -> KeyedValueBinding<Identifier, State, Value> {
get {
var storage = instance[keyPath: storageKeyPath]
let propertyKeyPath = storage.propertyKeyPath
Expand All @@ -60,21 +60,21 @@ import Foundation
public var projectedValue: Self { self }

@available(*, unavailable, message: "@DefaultBind can only be enclosed by EnvironmentObservingObject.")
public var wrappedValue: KeyedValueBinding<I, S, Value> {
public var wrappedValue: KeyedValueBinding<Identifier, State, Value> {
get { fatalError() }
set { fatalError() }
}
}

@MainActor public struct KeyedValueBinding<I: Hashable, S: KeyedState<I>, Value> {
@MainActor public struct KeyedValueBinding<Identifier: Hashable, State: KeyedState<Identifier>, Value> {
unowned var environment: ApplicationEnvironment

let observer: Observer
let propertyKeyPath: KeyPath<S, Property<Value>>
let propertyKeyPath: KeyPath<State, Property<Value>>
let context: Context

init(
bind propertyKeyPath: KeyPath<S, Property<Value>>,
bind propertyKeyPath: KeyPath<State, Property<Value>>,
observer: Observer,
environment: ApplicationEnvironment,
context: Context
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions Decide/Accessor/Default/DefaultObserve.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ import Foundation

///
@propertyWrapper
@MainActor public struct DefaultObserve<S: AtomicState, Value> {
@MainActor public struct DefaultObserve<State: AtomicState, Value> {
@DefaultEnvironment var environment

private let propertyKeyPath: KeyPath<S, Property<Value>>
private let propertyKeyPath: KeyPath<State, Property<Value>>

public init(_ keyPath: KeyPath<S, Property<Value>>) {
public init(_ keyPath: KeyPath<State, Property<Value>>) {
self.propertyKeyPath = keyPath
}

public init<P: PropertyModifier>(
_ keyPath: KeyPath<S, P>
) where P.Value == Value {
public init<WrappedProperty: PropertyModifier>(
_ keyPath: KeyPath<State, WrappedProperty>
) where WrappedProperty.Value == Value {
propertyKeyPath = keyPath.appending(path: \.wrappedValue)
}

Expand Down
32 changes: 16 additions & 16 deletions Decide/Accessor/Default/DefaultObserveKeyed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,40 @@ import Foundation
///
@propertyWrapper
@MainActor public struct DefaultObserveKeyed<
I: Hashable,
S: KeyedState<I>,
Identifier: Hashable,
State: KeyedState<Identifier>,
Value
> {
@DefaultEnvironment var environment

private let propertyKeyPath: KeyPath<S, Property<Value>>
private var valueObserve: KeyedValueObserve<I, S, Value>?
private let propertyKeyPath: KeyPath<State, Property<Value>>
private var valueObserve: KeyedValueObserve<Identifier, State, Value>?

public init(
_ keyPath: KeyPath<S, Property<Value>>
_ keyPath: KeyPath<State, Property<Value>>
) {
propertyKeyPath = keyPath
}

public init<P: PropertyModifier>(
_ keyPath: KeyPath<S, P>
) where P.Value == Value {
public init<WrappedProperty: PropertyModifier>(
_ keyPath: KeyPath<State, WrappedProperty>
) where WrappedProperty.Value == Value {
propertyKeyPath = keyPath.appending(path: \.wrappedValue)
}

public static subscript<EnclosingObject: EnvironmentObservingObject>(
_enclosingInstance instance: EnclosingObject,
wrapped wrappedKeyPath: KeyPath<EnclosingObject, KeyedValueObserve<I, S, Value>>,
wrapped wrappedKeyPath: KeyPath<EnclosingObject, KeyedValueObserve<Identifier, State, Value>>,
storage storageKeyPath: WritableKeyPath<EnclosingObject, Self>
) -> KeyedValueObserve<I, S, Value> {
) -> KeyedValueObserve<Identifier, State, Value> {
get {
var storage = instance[keyPath: storageKeyPath]
let propertyKeyPath = storage.propertyKeyPath
let environment = instance.environment
storage.environment = environment
let observer = Observer(instance)
if storage.valueObserve == nil {
storage.valueObserve = KeyedValueObserve<I, S, Value>(
storage.valueObserve = KeyedValueObserve<Identifier, State, Value>(
bind: propertyKeyPath,
observer: observer,
environment: environment
Expand All @@ -64,20 +64,20 @@ import Foundation
public var projectedValue: Self { self }

@available(*, unavailable, message: "@DefaultBind can only be enclosed by EnvironmentObservingObject.")
public var wrappedValue: KeyedValueObserve<I, S, Value> {
public var wrappedValue: KeyedValueObserve<Identifier, State, Value> {
get { fatalError() }
set { fatalError() }
}
}

@MainActor public struct KeyedValueObserve<I: Hashable, S: KeyedState<I>, Value> {
@MainActor public struct KeyedValueObserve<Identifier: Hashable, State: KeyedState<Identifier>, Value> {
unowned var environment: ApplicationEnvironment

let observer: Observer
let propertyKeyPath: KeyPath<S, Property<Value>>
let propertyKeyPath: KeyPath<State, Property<Value>>

init(
bind propertyKeyPath: KeyPath<S, Property<Value>>,
bind propertyKeyPath: KeyPath<State, Property<Value>>,
observer: Observer,
environment: ApplicationEnvironment
) {
Expand All @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions Decide/Accessor/Instance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
import SwiftUI

@propertyWrapper
@MainActor public struct Instance<S: AtomicState, O> {
@MainActor public struct Instance<State: AtomicState, Object> {

public typealias PropertyKeyPath = KeyPath<S, DefaultInstance<O>>
public typealias PropertyKeyPath = KeyPath<State, DefaultInstance<Object>>

private let instanceKeyPath: PropertyKeyPath

public init(_ keyPath: KeyPath<S, DefaultInstance<O>>) {
public init(_ keyPath: KeyPath<State, DefaultInstance<Object>>) {
self.instanceKeyPath = keyPath
}

public static subscript<EnclosingObject: EnvironmentManagedObject>(
_enclosingInstance instance: EnclosingObject,
wrapped wrappedKeyPath: KeyPath<EnclosingObject, O>,
wrapped wrappedKeyPath: KeyPath<EnclosingObject, Object>,
storage storageKeyPath: KeyPath<EnclosingObject, Self>
) -> O {
) -> Object {
get {
let storage = instance[keyPath: storageKeyPath]
let instanceKeyPath = storage.instanceKeyPath
Expand All @@ -38,16 +38,16 @@ import SwiftUI
}

@available(*, unavailable, message: "@Instance must be enclosed in EnvironmentManagedObject.")
public var wrappedValue: O {
public var wrappedValue: Object {
get { fatalError() }
}
}

extension ApplicationEnvironment {
func defaultInstance<S: AtomicState, O>(
at keyPath: KeyPath<S, DefaultInstance<O>>
) -> DefaultInstance<O> {
let storage: S = self[S.key()]
func defaultInstance<State: AtomicState, Object>(
at keyPath: KeyPath<State, DefaultInstance<Object>>
) -> DefaultInstance<Object> {
let storage: State = self[State.key()]
return storage[keyPath: keyPath]
}
}
Expand Down
10 changes: 7 additions & 3 deletions Decide/Accessor/SwiftUI/Bind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<S: AtomicState, Value>: DynamicProperty {
@MainActor public struct Bind<State: AtomicState, Value>: DynamicProperty {
@SwiftUI.Environment(\.stateEnvironment) var environment
@ObservedObject var observer = ObservedObjectWillChangeNotification()
let context: Context

let propertyKeyPath: KeyPath<S, Property<Value>>
let propertyKeyPath: KeyPath<State, Property<Value>>

public init(_ propertyKeyPath: KeyPath<S, Mutable<Value>>, file: String = #fileID, line: Int = #line) {
public init(
_ propertyKeyPath: KeyPath<State, Mutable<Value>>,
file: String = #fileID,
line: Int = #line
) {
let context = Context(file: file, line: line)
self.context = context
self.propertyKeyPath = propertyKeyPath.appending(path: \.wrappedValue)
Expand Down
14 changes: 9 additions & 5 deletions Decide/Accessor/SwiftUI/BindKeyed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,26 @@ 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<I: Hashable, S: KeyedState<I>, Value>: DynamicProperty {
@MainActor public struct BindKeyed<Identifier: Hashable, State: KeyedState<Identifier>, Value>: DynamicProperty {

@SwiftUI.Environment(\.stateEnvironment) var environment
@ObservedObject var observer = ObservedObjectWillChangeNotification()
let context: Context


let propertyKeyPath: KeyPath<S, Property<Value>>
let propertyKeyPath: KeyPath<State, Property<Value>>

public init(_ propertyKeyPath: KeyPath<S, Mutable<Value>>, file: String = #fileID, line: Int = #line) {
public init(
_ propertyKeyPath: KeyPath<State, Mutable<Value>>,
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<Value> {
public subscript(_ identifier: Identifier) -> Binding<Value> {
Binding<Value>(
get: {
environment.subscribe(
Expand All @@ -47,7 +51,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)
Expand Down
12 changes: 6 additions & 6 deletions Decide/Accessor/SwiftUI/Observe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ 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<S: AtomicState, Value>: DynamicProperty {
@MainActor public struct Observe<State: AtomicState, Value>: DynamicProperty {
@SwiftUI.Environment(\.stateEnvironment) var environment
@ObservedObject var observer = ObservedObjectWillChangeNotification()

let propertyKeyPath: KeyPath<S, Property<Value>>
let propertyKeyPath: KeyPath<State, Property<Value>>

public init(_ propertyKeyPath: KeyPath<S, Property<Value>>) {
public init(_ propertyKeyPath: KeyPath<State, Property<Value>>) {
self.propertyKeyPath = propertyKeyPath
}

public init<P: PropertyModifier>(
_ propertyKeyPath: KeyPath<S, P>
) where P.Value == Value {
public init<WrappedProperty: PropertyModifier>(
_ propertyKeyPath: KeyPath<State, WrappedProperty>
) where WrappedProperty.Value == Value {
self.propertyKeyPath = propertyKeyPath.appending(path: \.wrappedValue)
}

Expand Down
16 changes: 8 additions & 8 deletions Decide/Accessor/SwiftUI/ObserveKeyed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<I>,
Identifier: Hashable,
State: KeyedState<Identifier>,
Value
>: DynamicProperty {

@SwiftUI.Environment(\.stateEnvironment) var environment
@ObservedObject var observer = ObservedObjectWillChangeNotification()

let propertyKeyPath: KeyPath<S, Property<Value>>
let propertyKeyPath: KeyPath<State, Property<Value>>

public init(_ propertyKeyPath: KeyPath<S, Property<Value>>) {
public init(_ propertyKeyPath: KeyPath<State, Property<Value>>) {
self.propertyKeyPath = propertyKeyPath
}

public init<P: PropertyModifier>(
_ propertyKeyPath: KeyPath<S, P>
) where P.Value == Value {
public init<WrappedProperty: PropertyModifier>(
_ propertyKeyPath: KeyPath<State, WrappedProperty>
) where WrappedProperty.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)
Expand Down
Loading