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
ObservedPublisher for CurrentValueSubject #75
Comments
@fatbobman this is a great catch, and I actually faced the exact same problem while initially writing it! Very neat workaround, just trying to think of any possible downsides. Could you also think about any potential problems with the delay? I'd be inclined to accept this solution and incorporate it immediately, except I've been burnt by optimistic reactive programming one too many times :p |
Okay. Since I'll be using this scheme for my own projects, I'll be watching closely and continuing to study it. The biggest pitfall at the moment is that the internal implementation mechanism of Combine is still unstable and may be subject to constant change. |
@fatbobman how about this instead? self._subscription = .init(
initialValue: Publishers.Concatenate(
prefix: Just(initial)
.delay(for: .nanoseconds(1), scheduler: RunLoop.main),
suffix: publisher
).sink(receiveValue: {
updateWrappedValue.value($0)
})
) The reason I'm hesitant to use the initial solution is because it's a constant |
Good solution! The logic is also clearer. |
@fatbobman could you see if this works for you, in your projects? I'm testing here as well. |
@vmanot I've tested it and it runs well in my project. |
@fatbobman implemented. Thanks again! |
Could you also use |
ObservedPublisher is a great solution that combines @State and onRecevie into one. But when using CurrentValueSubject there is a problem, ObservedPublisher ignores dropping the first value.
I added a line to the code and now it adapts nicely to CurrentValueSubject.
The text was updated successfully, but these errors were encountered: