美文网首页
RacChannel

RacChannel

作者: 我是小胡胡分胡 | 来源:发表于2018-02-23 09:44 被阅读24次

    RacChannel ---RacChannelTerminal+++UIControl
    RacKVOChannel ------RACChannelTo
    RacObserve -------RacDelegateProxy

    1, RACKVOChannel
    双向绑定+继承于RACChannel

    代理人模式;实现KVO;
    底层还是依赖于RACKVO

        [RACKVOProxy.sharedProxy addObserver:self forContext:(__bridge void *)self];
        [strongTarget addObserver:RACKVOProxy.sharedProxy forKeyPath:self.keyPath options:options context:(__bridge void *)self];
    
    
    
    

    RACChannelTo

    
     [[RACKVOChannel alloc] initWithTarget:(TARGET) keyPath:@keypath(TARGET, KEYPATH) nilValue:(NILVALUE)][@keypath(RACKVOChannel.new, followingTerminal)]
    

    管道------ A[0] = 111; ///实现中括号下标操作符

    - (RACChannelTerminal *)objectForKeyedSubscript:(NSString *)key {
        NSCParameterAssert(key != nil);
    
        RACChannelTerminal *terminal = [self valueForKey:key];
        NSCAssert([terminal isKindOfClass:RACChannelTerminal.class], @"Key \"%@\" does not identify a channel terminal", key);
    
        return terminal;
    }
    
    - (void)setObject:(RACChannelTerminal *)otherTerminal forKeyedSubscript:(NSString *)key {
        NSCParameterAssert(otherTerminal != nil);
    
        RACChannelTerminal *selfTerminal = [self objectForKeyedSubscript:key];
        [otherTerminal subscribe:selfTerminal];
        [[selfTerminal skip:1] subscribe:otherTerminal];
    }
    
    

    2,
    使用KVC实现+ RACChannel

    - (RACChannelTerminal *)rac_channelForControlEvents:(UIControlEvents)controlEvents key:(NSString *)key nilValue:(nullable id)nilValue;
    
    
    
        [[self
            rac_liftSelector:@selector(valueForKey:) withSignals:eventSignal, nil]
            subscribe:channel.followingTerminal];
    
    
        [self rac_liftSelector:@selector(setValue:forKey:) withSignals:valuesSignal, [RACSignal return:key], nil];
    
    
    
    
    
    

    相关文章

      网友评论

          本文标题:RacChannel

          本文链接:https://www.haomeiwen.com/subject/tqitxftx.html