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

Why is the work only replaying the last value? #156

Open
c0diq opened this issue Oct 10, 2018 · 6 comments
Open

Why is the work only replaying the last value? #156

c0diq opened this issue Oct 10, 2018 · 6 comments

Comments

@c0diq
Copy link

c0diq commented Oct 10, 2018

In Action.swift, only the last value emitted by work factory is being replayed. Is it intentional?

return Observable.of(workFactory(input)
                                             .do(onError: { errorsSubject.onNext(.underlyingError($0)) })
                                             .share(replay: 1, scope: .forever))

This have the side effect that trying to share the last execution, only the last value is being replayed.

@ashfurrow
Copy link
Member

Yes; if we replayed all values, the memory use would grow forever as more executions are called. Rather than replay an arbitrary number of elements, we use 1 (which is necessary to compute internal state, if I recall correctly). Let me know what I can clarify.

@c0diq
Copy link
Author

c0diq commented Oct 11, 2018

Understood. I wonder if it would be better to not replay anything at all in this case and calculate the state differently. Because one may incorrectly assume that only one value got sent.

@ashfurrow
Copy link
Member

Yeah, I can see why you'd get that impression from reading the code. From the outside perspective, I think our API contract adheres to RxSwift norms. You wouldn't normally expect to get all values from a stream when you subscribe to it, but having the current value (that is to say, subscribing to the observable and doing stuff with it right away) is often useful. Let me know what I can clarify here 👍

@dangthaison91
Copy link
Contributor

@ashfurrow @c0diq Should we remove implicit replay latest value and leave developer to decide if they need to?

@ashfurrow
Copy link
Member

I think we need the last value, if an existing Action gets assigned to .rx.action on seem UI element, that element needs to set its enabled state right away.

@dangthaison91
Copy link
Contributor

@ashfurrow I see now we only need isEnabled to set enable states UI element .rx.action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants