Action icon indicating copy to clipboard operation
Action copied to clipboard

Should `executing` be emitting `false` as first value ?

Open c0diq opened this issue 7 years ago • 2 comments

ReactiveCocoa contract was that the executing observable would emit false as a first value when subscribed to and the command was not executing. This would allow to directly use it in the enabledIf of another opposite action. Instead we have to manually send false which can have side effects if the action is actually executing.

let stopAction = Action<(), ()> { _ in .just(()) }
let startAction = Action<(), ()>(enabledIf: stopAction.startWith(false).not()) { _ in
   .just(())
}

Instead of

let stopAction = Action<(), ()> { _ in .just(()) }
let startAction = Action<(), ()>(enabledIf: stopAction.not()) { _ in
   .just(())
}

c0diq avatar Oct 11 '18 17:10 c0diq

That makes sense to me – are you able to open a PR adding this behaviour (and a test)?

ashfurrow avatar Oct 11 '18 18:10 ashfurrow

@c0diq Just do a quick check and executing always emit false first? You can refer to this line of code: https://github.com/RxSwiftCommunity/Action/blob/6ee74293788871b3e85cf4816f4d1be8b02dc93b/Sources/Action/Action.swift#L106

dangthaison91 avatar Oct 22 '18 19:10 dangthaison91