<commit_before>//  Copyright © 2017 <NAME>. All rights reserved.

import Foundation
import UIKit
import ReSwift
import RxSwift
import ReRxSwift

class SteppingUpViewController: UIViewController {
    let connection = Connection(store: store,
                                mapStateToProps: mapStateToProps,
                                mapDispatchToActions: mapDispatchToActions)
    @IBOutlet weak var slider: UISlider!
    @IBOutlet weak var textField: UITextField!
    @IBOutlet weak var progressView: UIProgressView!
    @IBOutlet weak var segmentedControl: UISegmentedControl!
    @IBOutlet weak var stepper: UIStepper!

    override func viewDidLoad() {
        super.viewDidLoad()
        connection.bind(\Props.value, to: slider.rx.value)
        connection.bind(\Props.value, to: textField.rx.text, mapping: { String($0) })
        connection.bind(\Props.value, to: progressView.rx.progress)
        connection.bind(\Props.value, to: stepper.rx.value, mapping: { Double($0) })
        connection.bind(\Props.stepSize, to: stepper.rx.stepValue, mapping: { Double($0) })
        connection.bind(\Props.stepSize, to: segmentedControl.rx.selectedSegmentIndex, mapping: { self.segmentIndex(for: $0) })
    }

    func segmentIndex(for stepSize: Float) -> Int {
        for index in 0 ..< segmentedControl.numberOfSegments {
            guard let title = segmentedControl.titleForSegment(at: index),
                  let segment = Float(title) else {
                continue
            }
            if stepSize == segment {
                return index
            }
        }
        return -1
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        connection.connect()
    }

    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        connection.disconnect()
    }
    
    @IBAction func sliderChanged() {
        actions.setValue(slider.value)
    }

    @IBAction func textChanged() {
        guard let text = textField.text, let newValue = Float(text) else {
            return
        }
        actions.setValue(newValue)
    }

    @IBAction func stepperChanged() {
        actions.setValue(Float(stepper.value))
    }

    @IBAction func selectedSegmentChanged() {
        guard segmentedControl.selectedSegmentIndex >= 0,
              let title = segmentedControl.titleForSegment(at: segmentedControl.selectedSegmentIndex),
              let newStepSize = Float(title) else {
            return
        }
        actions.setStepSize(newStepSize)
    }
}

extension SteppingUpViewController: Connectable {
    struct Props {
        let value: Float
        let stepSize: Float
    }
    struct Actions {
        let setValue: (Float) -> ()
        let setStepSize: (Float) -> ()
    }
}

private let mapStateToProps = { (appState: AppState) in
    return SteppingUpViewController.Props(value: appState.steppingUp.value,
                                          stepSize: appState.steppingUp.stepSize)
}

private let mapDispatchToActions = { (dispatch: @escaping DispatchFunction) in
    return SteppingUpViewController.Actions(
        setValue: { newValue in dispatch(SteppingUpSetValue(newValue: newValue)) },
        setStepSize: { newStepSize in
            dispatch(SteppingUpSetStepSize(newStepSize: newStepSize))
        }
    )
}
<commit_msg>Applied workaround pending PR https://github.com/ReactiveX/RxSwift/pull/1389<commit_after>//  Copyright © 2017 <NAME>. All rights reserved.

import Foundation
import UIKit
import ReSwift
import RxSwift
import ReRxSwift

class SteppingUpViewController: UIViewController {
    let connection = Connection(store: store,
                                mapStateToProps: mapStateToProps,
                                mapDispatchToActions: mapDispatchToActions)
    @IBOutlet weak var slider: UISlider!
    @IBOutlet weak var textField: UITextField!
    @IBOutlet weak var progressView: UIProgressView!
    @IBOutlet weak var segmentedControl: UISegmentedControl!
    @IBOutlet weak var stepper: UIStepper!

    override func viewDidLoad() {
        super.viewDidLoad()
        connection.bind(\Props.value, to: slider.rx.value)
        connection.bind(\Props.value, to: textField.rx.text, mapping: { String($0) })
        connection.bind(\Props.value, to: progressView.rx.progress)
        connection.bind(\Props.value, to: stepper.rx.value, mapping: { Double($0) })

        // Binding the stepper requires https://github.com/ReactiveX/RxSwift/pull/1389 to be merged.
        // Applying workaround: subscribe instead of bind.
        // connection.bind(\Props.stepSize, to: stepper.rx.stepValue, mapping: { Double($0) })
        connection.subscribe(\Props.stepSize) { self.stepper.stepValue = Double($0) }

        connection.bind(\Props.stepSize, to: segmentedControl.rx.selectedSegmentIndex, mapping: { self.segmentIndex(for: $0) })
    }

    func segmentIndex(for stepSize: Float) -> Int {
        for index in 0 ..< segmentedControl.numberOfSegments {
            guard let title = segmentedControl.titleForSegment(at: index),
                  let segment = Float(title) else {
                continue
            }
            if stepSize == segment {
                return index
            }
        }
        return -1
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        connection.connect()
    }

    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        connection.disconnect()
    }
    
    @IBAction func sliderChanged() {
        actions.setValue(slider.value)
    }

    @IBAction func textChanged() {
        guard let text = textField.text, let newValue = Float(text) else {
            return
        }
        actions.setValue(newValue)
    }

    @IBAction func stepperChanged() {
        actions.setValue(Float(stepper.value))
    }

    @IBAction func selectedSegmentChanged() {
        guard segmentedControl.selectedSegmentIndex >= 0,
              let title = segmentedControl.titleForSegment(at: segmentedControl.selectedSegmentIndex),
              let newStepSize = Float(title) else {
            return
        }
        actions.setStepSize(newStepSize)
    }
}

extension SteppingUpViewController: Connectable {
    struct Props {
        let value: Float
        let stepSize: Float
    }
    struct Actions {
        let setValue: (Float) -> ()
        let setStepSize: (Float) -> ()
    }
}

private let mapStateToProps = { (appState: AppState) in
    return SteppingUpViewController.Props(value: appState.steppingUp.value,
                                          stepSize: appState.steppingUp.stepSize)
}

private let mapDispatchToActions = { (dispatch: @escaping DispatchFunction) in
    return SteppingUpViewController.Actions(
        setValue: { newValue in dispatch(SteppingUpSetValue(newValue: newValue)) },
        setStepSize: { newStepSize in
            dispatch(SteppingUpSetStepSize(newStepSize: newStepSize))
        }
    )
}

{'fraction_non_alphanumeric': 0.09157924581797562, 'fraction_numerical': 0.004394669690955486, 'mean_word_length': 2.463426607756505, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7052394', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1898, 'n_words': 445}