<commit_before>//
//  RxViewModel.swift
//  RxViewModel
//
//  Created by <NAME> on 7/14/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

// Native Frameworks
import Foundation

// Dependencies
import RxSwift
import RxCocoa

/**
Implements behaviors that drive the UI, and/or adapts a domain model to be 
user-presentable.
*/
public class RxViewModel: NSObject {
  // MARK: Constants
  let ThrottleTime: NSTimeInterval = 2
  
  // MARK: Properties
  /// Scope dispose to avoid leaking
//  internal var dispose: ScopedDispose? = nil
  var disposeBag = DisposeBag()
  
  /// The subject for active «signals»
  private var activeSubject: ReplaySubject<RxViewModel>?
  
  /// The subject for the inactive «signals»
  private var inactiveSubject: ReplaySubject<RxViewModel>?
  
  /// Underlying variable that we'll listen to for changes
  private dynamic var _active: Bool = false
  
  /// Public «active» variable
  public dynamic var active: Bool {
    get { return _active }
    set {
      // Skip KVO notifications when the property hasn't actually changed. This is
      // especially important because self.active can have very expensive
      // observers attached.
      if newValue == _active { return }
      
      _active = newValue
    }
  }
  
  // MARK: Life cycle
  
  /**
  Initializes a `RxViewModel` a attaches to observe changes in the `active` flag.
  */
  public override init() {
    super.init()
    
    let observable = self.rx_observe("_active") as Observable<Bool?>
    /// Start observing changes on our underlying `_active` property.
    observable.subscribeNext { active in
        /// If we have an active subject and the flag is true send ourselves
        /// as the next value in the stream to the active subject; else send
        /// ourselves to the inactive one.
        if let actSub = self.activeSubject
          where active == true {
            sendNext(actSub, self)
        } else if let inactSub = self.inactiveSubject
          where active == false {
            sendNext(inactSub, self)
        }
    }.addDisposableTo(disposeBag)
  }
  
  deinit {
//    self.disposeBag = nil
  }
  
  /**
  Rx `Observable` for the `active` flag. (when it becomes `true`).
  
  Will send messages only to *new* & *different* values.
  */
  public var didBecomeActive: Observable<RxViewModel> {
    get {
      return deferred { [weak self] () -> Observable<RxViewModel> in
        if let weakSelf = self
          where weakSelf.activeSubject == nil {
            weakSelf.activeSubject = ReplaySubject.create(bufferSize: 1)<commit_msg>Fix 2 missing warnings about deprecated sendNext<commit_after>//
//  RxViewModel.swift
//  RxViewModel
//
//  Created by <NAME> on 7/14/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

// Native Frameworks
import Foundation

// Dependencies
import RxSwift
import RxCocoa

/**
Implements behaviors that drive the UI, and/or adapts a domain model to be 
user-presentable.
*/
public class RxViewModel: NSObject {
  // MARK: Constants
  let ThrottleTime: NSTimeInterval = 2
  
  // MARK: Properties
  /// Scope dispose to avoid leaking
//  internal var dispose: ScopedDispose? = nil
  var disposeBag = DisposeBag()
  
  /// The subject for active «signals»
  private var activeSubject: ReplaySubject<RxViewModel>?
  
  /// The subject for the inactive «signals»
  private var inactiveSubject: ReplaySubject<RxViewModel>?
  
  /// Underlying variable that we'll listen to for changes
  private dynamic var _active: Bool = false
  
  /// Public «active» variable
  public dynamic var active: Bool {
    get { return _active }
    set {
      // Skip KVO notifications when the property hasn't actually changed. This is
      // especially important because self.active can have very expensive
      // observers attached.
      if newValue == _active { return }
      
      _active = newValue
    }
  }
  
  // MARK: Life cycle
  
  /**
  Initializes a `RxViewModel` a attaches to observe changes in the `active` flag.
  */
  public override init() {
    super.init()
    
    let observable = self.rx_observe("_active") as Observable<Bool?>
    /// Start observing changes on our underlying `_active` property.
    observable.subscribeNext { active in
        /// If we have an active subject and the flag is true send ourselves
        /// as the next value in the stream to the active subject; else send
        /// ourselves to the inactive one.
        if let actSub = self.activeSubject
          where active == true {
            actSub.on(.Next(self))
        } else if let inactSub = self.inactiveSubject
          where active == false {
            inactSub.on(.Next(self))
        }
    }.addDisposableTo(disposeBag)
  }
  
  deinit {
//    self.disposeBag = nil
  }
  
  /**
  Rx `Observable` for the `active` flag. (when it becomes `true`).
  
  Will send messages only to *new* & *different* values.
  */
  public var didBecomeActive: Observable<RxViewModel> {
    get {
      return deferred { [weak self] () -> Observable<RxViewModel> in
        if let weakSelf = self
          where weakSelf.activeSubject == nil {
            weakSelf.activeSubject = ReplaySubject.create(bufferSize: 1)
{'fraction_non_alphanumeric': 0.09208245039491428, 'fraction_numerical': 0.0044307455210942015, 'mean_word_length': 2.529571719918423, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6586148', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1450, 'n_words': 541}