ios - Accessing previous values in a ReactiveCocoa -flattenMap:/-then: chain -
let's have chain of reactivecocoa signals using -flattenmap: , -then:, so:
__weak typeof(self) weakself = self [[[self foosignal] flattenmap:^racstream *(foo *foo) { return [weakself barsignal]; }] then:^racsignal *{ // create signal using foo }]; in case, barsignal dependent on foosignal completing (next-ing, strictly speaking, foosignal once) without error, , next value barsignal nonsensical (+combinelatest: doesn't apply). if sending next, they're dependent operations, not parallel ones.
obviously, can use __block variable access foo, feels stylistically incorrect , hard follow (not strict chain downwards).
i can write custom operator achieve this, that's more code __block variable , difficult make generic, think.
is there clean way access foo?
i drop second -flattenmap: , instead add -then: end of barsignal. foo variable in scope there, , wait until barsignal complete before being subscribed to.
__weak typeof(self) weakself = self [[self foosignal] flattenmap:^racstream *(foo *foo) { return [[weakself barsignal] then:^racsignal * { // create signal using foo return [racsignal createsignal ... }]; }];
Comments
Post a Comment