Merge pull request #2 from 0xLeif/develop

0.0.2
This commit is contained in:
Zach Eriksen 2021-03-16 18:57:58 -05:00 committed by GitHub
commit 9e04c70567
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 5 deletions

View File

@ -1,3 +1,4 @@
import E
import Chain
@propertyWrapper public struct Observed<T> {
@ -8,29 +9,37 @@ import Chain
observedValue.didChangeHandler = didChangeHandler
}
}
public var wrappedValue: T {
didSet {
observedValue.update(value: wrappedValue)
_ = observedValue.update(value: wrappedValue)
}
}
public init(wrappedValue: T) {
self.wrappedValue = wrappedValue
}
}
public class ObservedValue<T> {
private(set) var value: T?
private(set) public var value: T?
public var callChain: Chain = .end
public var didChangeHandler: Chain?
public init(value: T? = nil) {
self.value = value
self.callChain = .complete(
.out { [weak self] in
self?.didChangeHandler?.run(name: "ObservedValue<\(T.self)>.didChangeHandler") ?? .void
}
)
}
public func update(value: T) {
@discardableResult
public func update(value: T) -> Variable {
self.value = value
_ = didChangeHandler?.run(name: "ObservedValue<\(T.self)>.didChangeHandler")
return callChain.run(name: "ObservedValue<\(T.self)>.callChain")
}
}