<commit_before>/**
 * Created by 10177553 on 2017/3/15.
 */
import {Component, Input, Output, EventEmitter, OnInit} from '@angular/core';

@Component({
    selector: 'rdk-switch',
    templateUrl: './switch.html',
    styleUrls: ['./switch.scss']
})

export class RdkSwitch implements OnInit{
    private _checked: boolean = false;
    private _disabled: boolean = false;
    private _content: any;
    private _switchClass: {};

    @Input()
    public onLabel: any;
    @Input()
    public offLabel: any;
    @Input()
    public size: string = 'default';

    @Input()
    public get disabled(): boolean { return this._disabled; };
    public set disabled(value: boolean) {
        this._disabled = value;
        this._setSwitchClass();
    }

    @Input()
    public get checked(): boolean  { return this._checked};
    public set checked(value: boolean) {
        this._checked = value;

        this._setSwitchClass();
        this._setInnerValue();
    }
    @Output() public checkedChange = new EventEmitter<boolean>();

    /**
     * 对外暴露事件,
     * @type {EventEmitter<boolean>}
     */
    @Output() public change = this.checkedChange;

    private _switchClick() {
        if(!this.disabled) {
            this.checked = !this.checked;

            // 发出事件
            this.checkedChange.emit(this.checked);
        }
    }

    /**
     * 更新控件样式的方法
     */
    private _setSwitchClass() {
        this._switchClass = {
            'rdk-switch': 'true',
            'rdk-switch-small': this.size === 'small'? true : false,
            'rdk-switch-checked': this.checked,
            'rdk-switch-disabled': this.disabled
        }
    }

    /**
     * 设置选中和费选中的值.
     */
    private _setInnerValue() {
        this._content = this.checked ? this.onLabel : this.offLabel;
    }

    public ngOnInit() {
        this._setSwitchClass();
        this._setInnerValue();
    }
}
<commit_msg># 开关组件易于阅读重构.<commit_after>/**
 * Created by 10177553 on 2017/3/15.
 */
import {Component, Input, Output, EventEmitter, OnInit} from '@angular/core';

@Component({
    selector: 'rdk-switch',
    templateUrl: './switch.html',
    styleUrls: ['./switch.scss']
})

export class RdkSwitch implements OnInit{
    private _content: any; // 当前显示的内容.

    @Input()
    public onLabel: any;
    @Input()
    public offLabel: any;
    @Input()
    public size: string = 'default';

    private _checked: boolean = false;

    @Input()
    public get checked(): boolean  { return this._checked};
    public set checked(value: boolean) {
        this._checked = value;

        this._setSwitchClass();
        this._setInnerValue();
    }
    @Output() public checkedChange = new EventEmitter<boolean>();

    /**
     * 对外暴露事件,
     * @type {EventEmitter<boolean>}
     */
    @Output() public change = this.checkedChange;

    private _disabled: boolean = false;
    @Input()
    public get disabled(): boolean { return this._disabled; };
    public set disabled(value: boolean) {
        this._disabled = value;
        this._setSwitchClass();
    }

    private _switchClick() {
        if(!this.disabled) {
            this.checked = !this.checked;

            // 发出事件
            this.checkedChange.emit(this.checked);
        }
    }

    private _switchClass: {};

    /**
     * 更新控件样式的方法
     */
    private _setSwitchClass() {
        this._switchClass = {
            'rdk-switch': 'true',
            'rdk-switch-small': this.size === 'small'? true : false,
            'rdk-switch-checked': this.checked,
            'rdk-switch-disabled': this.disabled
        }
    }

    /**
     * 设置选中和费选中的值.
     */
    private _setInnerValue() {
        this._content = this.checked ? this.onLabel : this.offLabel;
    }

    public ngOnInit() {
        this._setSwitchClass();
        this._setInnerValue();
    }
}

{'fraction_non_alphanumeric': 0.13727034120734907, 'fraction_numerical': 0.007874015748031496, 'mean_word_length': 2.181135225375626, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1061631', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1194, 'n_words': 254}