<commit_before>/*jshint esnext:true*/

import {mix, createFactory, extendFactory} from 'js/oop';
import createWidget from 'js/widget';

// region Button extends WidgetP
export const createButton = extendFactory(createWidget, {
	ATTRS: {
		disabled: {
			value: false,
			setter: newVal => Boolean(newVal)
		},
		
		label: {
			value: '',
			validator: newVal => typeof newVal === 'string'
		}
	},
	
	NODE_TEMPLATE: '<button type="button"></button>',
	
	CLASS: 'button',
	
	_enhance () {
		this.set('disabled', this.node.disabled);
		this.set('label', this.node.innerHTML);
	},
	
	_render () {
		this._setLabel();
		this._setDisabled();
	},
	
	_bindUI () {
		this._registerSubscriptions(
			this.after('disabledChange', this._setDisabled),
			this.after('labelChange', this._setLabel)
		);
	},
	
	_setDisabled () {
		this.node.disabled = this.get('disabled');
	},
	
	_setLabel () {
		this.node.innerHTML = this.get('label');
	}
});
// endregion

// region ToggleButton extends Button
export const createToggleButton = extendFactory(createButton, {
	ATTRS: {
		pressed: {
			value: false,
			setter: newVal => Boolean(newVal)
		}
	},
	
	CLASS: 'toggleButton',
	
	toggle (pressed = !this.get('pressed')) {
		this.set('pressed', pressed);
	},
	
	_enhance () {
		this.set('pressed', this.node.classList.contains('pressed'));	// read state from DOM
	},
	
	_render () {
		createButton.prototype._render.apply(this, arguments);
		
		this._setPressed();		// sync state to DOM
	},
	
	_bindUI () {
		this._registerSubscriptions(
			this.after('pressedChange', this._setPressed)
		);
		
		this._registerListener('click', () => {this.toggle();});	// anonymous function so toggle doesn't get event argument
	},
	
	_setPressed () {
		this.node.classList.toggle('pressed', this.get('pressed'));
	}
});
// endregion<commit_msg>fixed two bugs in ToggleButton: methods didn't call parent method<commit_after>/*jshint esnext:true*/

import {mix, createFactory, extendFactory} from 'js/oop';
import createWidget from 'js/widget';

// region Button extends WidgetP
export const createButton = extendFactory(createWidget, {
	ATTRS: {
		disabled: {
			value: false,
			setter: newVal => Boolean(newVal)
		},
		
		label: {
			value: '',
			validator: newVal => typeof newVal === 'string'
		}
	},
	
	NODE_TEMPLATE: '<button type="button"></button>',
	
	CLASS: 'button',
	
	_enhance () {
		this.set('disabled', this.node.disabled);
		this.set('label', this.node.innerHTML);
	},
	
	_render () {
		this._setLabel();
		this._setDisabled();
	},
	
	_bindUI () {
		this._registerSubscriptions(
			this.after('disabledChange', this._setDisabled),
			this.after('labelChange', this._setLabel)
		);
	},
	
	_setDisabled () {
		this.node.disabled = this.get('disabled');
	},
	
	_setLabel () {
		this.node.innerHTML = this.get('label');
	}
});
// endregion

// region ToggleButton extends Button
export const createToggleButton = extendFactory(createButton, {
	ATTRS: {
		pressed: {
			value: false,
			setter: newVal => Boolean(newVal)
		}
	},
	
	CLASS: 'toggleButton',
	
	toggle (pressed = !this.get('pressed')) {
		this.set('pressed', pressed);
	},
	
	_enhance () {
		createButton.prototype._enhance.apply(this, arguments);
		
		this.set('pressed', this.node.classList.contains('pressed'));	// read state from DOM
	},
	
	_render () {
		createButton.prototype._render.apply(this, arguments);
		
		this._setPressed();		// sync state to DOM
	},
	
	_bindUI () {
		createButton.prototype._bindUI.apply(this, arguments);
		
		this._registerSubscriptions(
			this.after('pressedChange', this._setPressed)
		);
		
		this._registerListener('click', () => {this.toggle();});	// anonymous function so toggle doesn't get event argument
	},
	
	_setPressed () {
		this.node.classList.toggle('pressed', this.get('pressed'));
	}
});
// endregion
{'fraction_non_alphanumeric': 0.16504086475085683, 'fraction_numerical': 0.0, 'mean_word_length': 3.901808785529716, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '6491681', 'n_tokens_mistral': 1371, 'n_tokens_neox': 1219, 'n_words': 242}