Skip to content

Difference between RACChannelTo and [channelTerminal subscribe:] #1473

@skywinder

Description

@skywinder

Here is examples of code:
_1_

RACChannelTerminal *channelTerminal = self.valueTextField.rac_newTextChannel;
RACChannelTerminal *channelTerminal2 = RACChannelTo(self.viewModel, value);
[channelTerminal subscribe:channelTerminal2];
[channelTerminal2 subscribe:channelTerminal];

[RACObserve(self.viewModel, value) subscribeNext:^(id x) {
    NSLog(@"x = %@", x);
}];

_2_

RACChannelTo(self.valueTextField, text)= RACChannelTo(self.viewModel, value);

[RACObserve(self.viewModel, value) subscribeNext:^(id x) {
    NSLog(@"x = %@", x);
}];

From description of RACChannelTo I supposed, that this 2 samples do the same.

But in second case logging is not working, when I start typing something in textField.

Can you clarify, what the difference between this 2 examples?

Activity

skywinder

skywinder commented on Aug 20, 2014

@skywinder
Author

@joshaber it's my typo. But it's only about initial values. (as I understood from #1023)
It does not explain, why I don't see any logging messages, when I typing in textField in 2nd example, (but in 1-st it works.)

joshaber

joshaber commented on Aug 20, 2014

@joshaber
Member

So I just noticed example 2 isn't using rac_newTextChannel. Is there a reason for that?

skywinder

skywinder commented on Aug 21, 2014

@skywinder
Author

Yes, thats it. I try to replace

RACChannelTerminal *channelTerminal = self.valueTextField.rac_newTextChannel; to
RACChannelTerminal *channelTerminal = RACChannelTo(self.uiTextField, text);
And it stop works too.

  1. I want to observe for self.valueTextField.text change. Why It not works in this way?

  2. Is there some one-line alternative for "example 1" to bind my viewModel value to UITextField text value?

Coneko

Coneko commented on Aug 21, 2014

@Coneko
Member

From description of RACChannelTo I supposed, that this 2 samples do the same.

They're not the same.

self.valueTextField.rac_newTextChannel sends values when you type in the text field, but not when you change the text in the text field from code.

RACChannelTo(self.uiTextField, text) sends values when you change the text in the text field from code, but not when you type in the text field.

skywinder

skywinder commented on Aug 21, 2014

@skywinder
Author

@Coneko got it, thanks!
So, if I want to observe changes from user's typing in UITextField - there is no shorter way than 4 lines to bind the value and textField?

Coneko

Coneko commented on Aug 21, 2014

@Coneko
Member

Yep.

shyboy2012

shyboy2012 commented on Nov 27, 2017

@shyboy2012

try RACChannelTo(self.viewModel, value) = self.valueTextField.rac_newTextChannel;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @joshaber@jspahrsummers@Coneko@skywinder@shyboy2012

        Issue actions

          Difference between RACChannelTo and [channelTerminal subscribe:] · Issue #1473 · ReactiveCocoa/ReactiveCocoa