-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update Dependencies * Updat macOS Action
- Loading branch information
Showing
11 changed files
with
386 additions
and
70 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
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
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
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,24 @@ | ||
import Combine | ||
import SwiftUI | ||
|
||
/// The `@AppDependency` property wrapper is a feature provided by AppState, intended to simplify dependency handling throughout your application. It makes it easy to access, share, and manage dependencies in a neat and Swift idiomatic way. | ||
@propertyWrapper public struct AppDependency<Value> { | ||
/// Path for accessing `Dependency` from Application. | ||
private let keyPath: KeyPath<Application, Application.Dependency<Value>> | ||
|
||
/// Represents the current value of the `Dependency`. | ||
public var wrappedValue: Value { | ||
Application.dependency(keyPath) | ||
} | ||
|
||
/** | ||
Initializes the AppDependency with a `keyPath` for accessing `Dependency` in Application. | ||
|
||
- Parameter keyPath: The `KeyPath` for accessing `Dependency` in Application. | ||
*/ | ||
public init( | ||
_ keyPath: KeyPath<Application, Application.Dependency<Value>> | ||
) { | ||
self.keyPath = keyPath | ||
} | ||
} |
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
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,55 @@ | ||
extension Application { | ||
/// `Dependency` struct encapsulates dependencies used throughout the app. | ||
public struct Dependency<Value>: CustomStringConvertible { | ||
/// The dependency value. | ||
let value: Value | ||
|
||
/// The scope in which this state exists. | ||
let scope: Scope | ||
|
||
/** | ||
Initializes a new dependency within a given scope with an initial value. | ||
|
||
A Dependency allows for defining services or shared objects across the app. It is designed to be read-only and can only be changed by re-initializing it, ensuring thread-safety in your app. | ||
|
||
- Parameters: | ||
- value: The initial value of the dependency. | ||
- scope: The scope in which the dependency exists. | ||
*/ | ||
init( | ||
_ value: Value, | ||
scope: Scope | ||
) { | ||
self.value = value | ||
self.scope = scope | ||
} | ||
|
||
public var description: String { | ||
"Dependency<\(Value.self)>(\(value)) (\(scope.key))" | ||
} | ||
} | ||
|
||
/// `DependencyOverride` provides a handle to revert a dependency override operation. | ||
public class DependencyOverride { | ||
/// Closure to be invoked when the dependency override is cancelled. This closure typically contains logic to revert the overrides on the dependency. | ||
private let cancelOverride: () -> Void | ||
|
||
/** | ||
Initializes a `DependencyOverride` instance. | ||
|
||
- Parameter cancelOverride: The closure to be invoked when the | ||
dependency override is cancelled. | ||
*/ | ||
init(cancelOverride: @escaping () -> Void) { | ||
self.cancelOverride = cancelOverride | ||
} | ||
|
||
/// Automatically cancels the override when `DependencyOverride` instance is deallocated. | ||
deinit { cancel() } | ||
|
||
/// Cancels the override and resets the Dependency back to its value before the override. | ||
public func cancel() { | ||
cancelOverride() | ||
} | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.