<commit_before>//
//  RefreshableTableViewController.swift
//  RefreshableViewController
//
//  Created by <NAME> on 30/08/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit
import PromiseKit

// MARK: Refreshable table view controller

open class RefreshableTableViewController<Value>: UITableViewController, Refreshable {
    
    // MARK: Initializers
    
    public convenience init(style: UITableViewStyle, request: @autoclosure @escaping () -> Promise<Value>) {
        self.init(style: style)
        self.request = request
    }
    
    public convenience init(style: UITableViewStyle, value: Value) {
        self.init(style: style)
        self.state = .success(value)
    }
    
    // MARK: Public state
    
    public final var request: (() -> Promise<Value>)?
    
    public final var state: RefreshableState<Value> = .ready {
        didSet {
            refreshState()
        }
    }
    
    // MARK: Overrides
    
    override open func viewDidLoad() {
        super.viewDidLoad()
        
        if request != nil {
            refreshControl = UIRefreshControl()
            refreshControl?.addTarget(self, action: #selector(refresh), for: .valueChanged)
            refresh()
        } else {
            refreshState()
        }
    }
    
    // MARK: Refreshable
    
    @objc public final func refresh() {
        guard let request = request else {
            refreshState()
            return
        }
        
        self.state = .loading
        
        request().done { value in
            self.state = .success(value)
        }.always {
            self.refreshControl?.endRefreshing()
        }.catch { error in
            self.state = .failure(error)
        }
    }
    
    open func refreshState() {
        // This should be overridden in subclasses
    }
    
}<commit_msg>Fix PromiseKit warning<commit_after>//
//  RefreshableTableViewController.swift
//  RefreshableViewController
//
//  Created by <NAME> on 30/08/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit
import PromiseKit

// MARK: Refreshable table view controller

open class RefreshableTableViewController<Value>: UITableViewController, Refreshable {
    
    // MARK: Initializers
    
    public convenience init(style: UITableViewStyle, request: @autoclosure @escaping () -> Promise<Value>) {
        self.init(style: style)
        self.request = request
    }
    
    public convenience init(style: UITableViewStyle, value: Value) {
        self.init(style: style)
        self.state = .success(value)
    }
    
    // MARK: Public state
    
    public final var request: (() -> Promise<Value>)?
    
    public final var state: RefreshableState<Value> = .ready {
        didSet {
            refreshState()
        }
    }
    
    // MARK: Overrides
    
    override open func viewDidLoad() {
        super.viewDidLoad()
        
        if request != nil {
            refreshControl = UIRefreshControl()
            refreshControl?.addTarget(self, action: #selector(refresh), for: .valueChanged)
            refresh()
        } else {
            refreshState()
        }
    }
    
    // MARK: Refreshable
    
    @objc public final func refresh() {
        guard let request = request else {
            refreshState()
            return
        }
        
        self.state = .loading
        
        request().done { value in
            self.state = .success(value)
        }.ensure {
            self.refreshControl?.endRefreshing()
        }.catch { error in
            self.state = .failure(error)
        }
    }
    
    open func refreshState() {
        // This should be overridden in subclasses
    }
    
}
{'fraction_non_alphanumeric': 0.09954016770354342, 'fraction_numerical': 0.005409791723018664, 'mean_word_length': 1.812167300380228, 'pattern_counts': {'":': 0, '<': 15, '<?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': '3860201', 'n_tokens_mistral': 1050, 'n_tokens_neox': 994, 'n_words': 254}