0

I'm trying to migrate some parts of a project that was initially written in Obj-C. Currently I'm trying to migrate a code that relies heavily on signals. To give you a general idea of what I'm trying to migrate, here is a little piece of code which is part of a custom UIButton :

- (instancetype)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        _objectA = [ObjectAStore sharedInstance].objectA;
        [self awakeFromNib]; // Here I'm doing some processing on changes done to [self varQ] below

        RACSignal *ownObjectA = RACObserve(self, objectA);

        RACSignal *ownObjectB = RACObserve(self, objectB)

        RACSignal *ownObjectC = [RACObserve(self, objectC) distinctUntilChanged];

        RACSignal *objectAWithB = [RACSignal combineLatest:@[ownObjectA, ownObjectB]];

        RACSignal *objectBFromC = [objectAWithB reduceEach:^ObjectB *(ObjectA *a, ObjectC *c) {
            return [a objectBFromCIdentifier:c.identifier];
        }];

        RACSignal *objectBFromExternal = [[objectAWithB reduceEach:^RACSignal *(ObjectA *a, ObjectC *c) {
            return [a observedObjectAForObjectC:[[ObjectExternal alloc] initWithObjectC:c]];
        }] switchToLatest];

        RAC(self, currentObjectB) = [RACSignal merge:@[ownObjectB, objectBFromC, objectBFromExternal]];

        RAC(self, varQ) = RACObserve(self, currentObjectB.varQ);
    }
    return self;
}

And these are the properties :

@interface CustomUIButton ()

@property (nonatomic, strong) ObjectB *currentObjectB;

@end

@implementation CustomUIButton

@synthesize objectA = _objectA;
@synthesize objectC = _objectC;
@synthesize objectB = _objectB;

The synthesized ones are being assigned with setters.

I've been trying to wrap my head around this for quite some time now and I've made little to no progress. What's the best approach to migrate this piece of code?

Meamine
  • 11
  • 4

0 Answers0