Giter Site home page Giter Site logo

Comments (4)

mdiep avatar mdiep commented on April 28, 2024

You only need to call the error's subscribeNext: once. It sounds like you're calling it multiple times. Can you share some code?

from reactiveobjc.

longjianjiang avatar longjianjiang commented on April 28, 2024

sure; the view like below picture;
simulator screen shot 2017 4 1 09 30 09

if the server send error like 403(cause my app don't be verified so the server limit the interface call times). And the user can did this sendBtn more times, so the errors subscribeBlock can be executed more times, as same as the command be executed more times too; Here is my code, so can i have some solution to avoid this kind of problem?

[[_sendBtn rac_signalForControlEvents:UIControlEventTouchDown] subscribeNext:^(id x) {
            
            [weakSelf.sendViewModel.sendCommand.executionSignals.switchToLatest subscribeNext:^(id x) {
                MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
                hud.mode = MBProgressHUDModeText;
                hud.labelText = @"已发送";
                [hud hide:YES afterDelay:1.0];

                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [self.view endEditing:YES];
                    [self dismissViewControllerAnimated:YES completion:nil];
                });
            }];
            
            
            [weakSelf.sendViewModel.sendCommand.errors subscribeNext:^(id x) {
                LJLog(@"()()()()"); // click more times the text will be loged more times
                MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
                hud.mode = MBProgressHUDModeText;
                hud.labelText = @"新浪服务器开小差了...";
                [hud hide:YES afterDelay:1.0];
            }];
            
            NSDictionary *dict = @{@"statusd":_textView.text};
            [self.sendViewModel.sendCommand execute:dict];
        }];

from reactiveobjc.

mdiep avatar mdiep commented on April 28, 2024

You shouldn't subscribe to errors or executionSignals every time the button is pressed. It should only happen once.

            [weakSelf.sendViewModel.sendCommand.executionSignals.switchToLatest subscribeNext:^(id x) {
                MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
                hud.mode = MBProgressHUDModeText;
                hud.labelText = @"已发送";
                [hud hide:YES afterDelay:1.0];

                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [self.view endEditing:YES];
                    [self dismissViewControllerAnimated:YES completion:nil];
                });
            }];
            
            
            [weakSelf.sendViewModel.sendCommand.errors subscribeNext:^(id x) {
                LJLog(@"()()()()"); // click more times the text will be loged more times
                MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
                hud.mode = MBProgressHUDModeText;
                hud.labelText = @"新浪服务器开小差了...";
                [hud hide:YES afterDelay:1.0];
            }];

[[_sendBtn rac_signalForControlEvents:UIControlEventTouchDown] subscribeNext:^(id x) {
            NSDictionary *dict = @{@"statusd":_textView.text};
            [self.sendViewModel.sendCommand execute:dict];
        }];

from reactiveobjc.

longjianjiang avatar longjianjiang commented on April 28, 2024

ok, thank you very much.

from reactiveobjc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.