<commit_before>//
//  Button+Observer.swift
//  NxEnabled
//
//  Created by <NAME> on 12/01/2017.
//  Copyright © 2017 Nikita. All rights reserved.
//

import UIKit.UIButton

private var observerTypeAssociationKey: UInt8 = 0

extension UIButton {
    
    /// Special object which observes text for all textable values
    
    fileprivate var observer: NUIObserver? {
        get { return objc_getAssociatedObject(self, &observerTypeAssociationKey) as! NUIObserver? }
        set { objc_setAssociatedObject(self, &observerTypeAssociationKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) }
    }
    
    /// Clears all observers from textable values, wich have been configured by `isEnabled` method.
    ///
    /// - note: Don't forget to call this method when you need to remove observers from `textableValue`s. Usually it's a `deinit` method.
    ///
    
    public func clearBag() {
        observer = nil
    }
}

// MARK: - NUIObserber1

extension UIButton {
    
    /// Setup `isEnabled` property binding with one textable value.
    ///
    /// - parameter textableValue:          Textable value for binding.
    /// - parameter configurationHandler:   Configuration handler within which you should configure `isEnabled` state by current textable value and return it.
    ///
    /// - note: You can pass not only UI elements such as `UITextView` and `UITextField`, for example.
    ///         But also any object which conforms to `Textable` protocol and is the successor of `NSObject`. 
    ///         Don't forget about `dynamic` for your property.
    ///
    
    public func isEnabled<T: NSObject>(by textableValue: T,
                                        configurationHandler: @escaping ConfigurationHandler1) where T: Textable {
        let inputs = [textableValue]
        observer = NUIObserver1(textableValues: inputs, configurationHandler: configurationHandler) { [unowned self] isEnabled in<commit_msg>Method documentation refactoring<commit_after>//
//  Button+Observer.swift
//  NxEnabled
//
//  Created by <NAME> on 12/01/2017.
//  Copyright © 2017 Nikita. All rights reserved.
//

import UIKit.UIButton

private var observerTypeAssociationKey: UInt8 = 0

extension UIButton {
    
    /// Special object which observes text for all textable values
    
    fileprivate var observer: NUIObserver? {
        get { return objc_getAssociatedObject(self, &observerTypeAssociationKey) as! NUIObserver? }
        set { objc_setAssociatedObject(self, &observerTypeAssociationKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) }
    }
    
    /// Clears all observers from textable values, which have been configured by `isEnabled` method.
    ///
    /// - note: Don't forget to call this method when you need to remove observers from `textableValue`s. Usually it's a `deinit` method.
    ///
    
    public func clearBag() {
        observer = nil
    }
}

// MARK: - NUIObserber1

extension UIButton {
    
    /// Setup `isEnabled` property binding with one textable value.
    ///
    /// - parameter textableValue:          Textable value for binding.
    /// - parameter configurationHandler:   Configuration handler within which you should configure `isEnabled` state by current textable value and return it.
    ///
    /// - note: You can pass not only UI elements such as `UITextView` and `UITextField`, for example.
    ///         But also any object which conforms to `Textable` protocol and is the successor of `NSObject`. 
    ///         Don't forget about `dynamic` for your property.
    ///
    
    public func isEnabled<T: NSObject>(by textableValue: T,
                                        configurationHandler: @escaping ConfigurationHandler1) where T: Textable {
        let inputs = [textableValue]
        observer = NUIObserver1(textableValues: inputs, configurationHandler: configurationHandler) { [unowned self] isEnabled in
{'fraction_non_alphanumeric': 0.08753861997940268, 'fraction_numerical': 0.008753861997940269, 'mean_word_length': 2.668555240793201, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '216732', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1035, 'n_words': 367}