ios - ReactiveCocoa: how to keep signal until the server is connected? -
i have 2 signals (racsignal
):
synchronizetoserversignal
: signal containing info sent server. serverconnectionsignal
: signal containing boolean value indicate connection state. the synchronizetoserversignal
triggered when content changed, , signal controlled serverconnectionsignal
:
serverconnectionsignal
yes
, synchronizetoserversignal
maintain sending next value (data
). if latest value of serverconnectionsignal
no
, synchronizetoserversignal
maintain holding latest value , discarding old values. 1 time serverconnectionsignal
sends yes
, serverconnectionsignal
maintain sending next value again. how utilize reactivecocoa accomplish this?
replaylast
give signal holds onto latest value sent , discards old values. if:then:else:
allows switch between 2 signals based on value of 3rd boolean signal.
but switch between? since want ignore values, can utilize [racsignal empty]
-- switching between signal useful value , signal no values:
[racsignal if:serverconnectionsignal then:[synchronizetoserversignal replaylast] else:[racsignal empty]] subscribenext:^(id x) { // sync here }];
the intent of code made lot more clear helper method in category, though:
@implementation racsignal (helpers) - (racsignal *)guard:(racsignal *)boolsignal { homecoming [racsignal if:boolsignal then:self else:[racsignal empty]]; } @end
then can write:
[[synchronizetoserversignal replaylast] guard:serverconnectionsignal]
much more clear!
ios reactive-cocoa
No comments:
Post a Comment