diff --git a/Sources/SwiftEnvironment/EnvironmentValuesResolver.swift b/Sources/SwiftEnvironment/EnvironmentValuesResolver.swift index 8b988e1..871661a 100644 --- a/Sources/SwiftEnvironment/EnvironmentValuesResolver.swift +++ b/Sources/SwiftEnvironment/EnvironmentValuesResolver.swift @@ -1,6 +1,6 @@ // // EnvironmentValuesResolver.swift -// +// // // Created by Nayanda Haberty on 14/3/24. // @@ -37,28 +37,55 @@ public class EnvironmentValuesResolver { public func environment( _ keyPath: WritableKeyPath, resolveOn queue: DispatchQueue? = nil, - _ value: @escaping () -> V) -> EnvironmentValuesResolver { + _ value: @autoclosure @escaping () -> V) -> EnvironmentValuesResolver { resolvers[keyPath] = SingletonInstanceResolver(queue: queue, resolver: value) return self } + @discardableResult + public func environment( + _ keyPath: WritableKeyPath, + resolveOn queue: DispatchQueue? = nil, + resolver: @escaping () -> V) -> EnvironmentValuesResolver { + resolvers[keyPath] = SingletonInstanceResolver(queue: queue, resolver: resolver) + return self + } + @discardableResult public func transient( _ keyPath: WritableKeyPath, resolveOn queue: DispatchQueue? = nil, - _ value: @escaping () -> V) -> EnvironmentValuesResolver { + _ value: @autoclosure @escaping () -> V) -> EnvironmentValuesResolver { resolvers[keyPath] = TransientInstanceResolver(queue: queue, resolver: value) return self } + @discardableResult + public func transient( + _ keyPath: WritableKeyPath, + resolveOn queue: DispatchQueue? = nil, + resolver: @escaping () -> V) -> EnvironmentValuesResolver { + resolvers[keyPath] = TransientInstanceResolver(queue: queue, resolver: resolver) + return self + } + @discardableResult public func weak( _ keyPath: WritableKeyPath, resolveOn queue: DispatchQueue? = nil, - _ value: @escaping () -> V) -> EnvironmentValuesResolver { + _ value: @autoclosure @escaping () -> V) -> EnvironmentValuesResolver { resolvers[keyPath] = WeakInstanceResolver(queue: queue, resolver: value) return self } + + @discardableResult + public func weak( + _ keyPath: WritableKeyPath, + resolveOn queue: DispatchQueue? = nil, + resolver: @escaping () -> V) -> EnvironmentValuesResolver { + resolvers[keyPath] = WeakInstanceResolver(queue: queue, resolver: resolver) + return self + } } extension EnvironmentValuesResolver { diff --git a/Sources/SwiftEnvironment/GlobalResolver.swift b/Sources/SwiftEnvironment/GlobalResolver.swift index 5cef058..9f0a09b 100644 --- a/Sources/SwiftEnvironment/GlobalResolver.swift +++ b/Sources/SwiftEnvironment/GlobalResolver.swift @@ -47,7 +47,7 @@ public struct GlobalResolver { _ keyPath: WritableKeyPath, resolveOn queue: DispatchQueue? = nil, resolver: @escaping () -> V) -> EnvironmentValuesResolver { - EnvironmentValuesResolver.global.environment(keyPath, resolveOn: queue, resolver) + EnvironmentValuesResolver.global.environment(keyPath, resolveOn: queue, resolver: resolver) } @inlinable @@ -64,7 +64,7 @@ public struct GlobalResolver { _ keyPath: WritableKeyPath, resolveOn queue: DispatchQueue? = nil, resolver: @escaping () -> V) -> EnvironmentValuesResolver { - EnvironmentValuesResolver.global.transient(keyPath, resolveOn: queue, resolver) + EnvironmentValuesResolver.global.transient(keyPath, resolveOn: queue, resolver: resolver) } @inlinable @@ -81,6 +81,6 @@ public struct GlobalResolver { _ keyPath: WritableKeyPath, resolveOn queue: DispatchQueue? = nil, resolver: @escaping () -> V) -> EnvironmentValuesResolver { - EnvironmentValuesResolver.global.weak(keyPath, resolveOn: queue, resolver) + EnvironmentValuesResolver.global.weak(keyPath, resolveOn: queue, resolver: resolver) } }