<commit_before>import { formatValue, toNumber } from '../../../util';

/**
 * 异步延迟函数
 * @param   {Function}  func
 * @param   {Number}    delay
 * @return  {TimeoutId}
 */
function debounceDelay (func, delay) {
	return setTimeout(function () {
		func.call(func);
	}, toNumber(delay));
}

export default {
	/**
	 * 绑定 text 变化事件
	 */
	bind: function () {
		var lazy = this.lazy;
		var number = this.number;
		var debounce = this.debounce;
		var directive = this.directive;

		// 解决中文输入时 input 事件在未选择词组时的触发问题
		// https://developer.mozilla.org/zh-CN/docs/Web/Events/compositionstart
		var composeLock;
		this.on('compositionstart', function () {
			composeLock = true;
		});
		this.on('compositionend', function () {
			composeLock = false;
		});

		var self = this;
		// input 事件(实时触发)
		this.on('input', function () {
			if (!composeLock && !lazy) {
				let value = this.value;

				if (debounce) {
					debounceDelay(function () {
						self.onDebounce = true;
						directive.set(formatValue(value, number));
					}, debounce);
				} else {
					directive.set(formatValue(value, number));
				}
			}
		});

		// change 事件(失去焦点触发)
		this.on('change', function () {
			directive.set(formatValue(this.value, number));
		});
	},

	/**
	 * 更新 text 值
	 * @param   {String}  value
	 */
	update: function (value) {
		var el = this.el;
		if (el.value !== value && !this.onDebounce) {
			el.value = value;
		}
	}
}<commit_msg>Fixed: v-model text chinese input cannot update when compositionend.<commit_after>import { formatValue, toNumber } from '../../../util';

/**
 * 异步延迟函数
 * @param   {Function}  func
 * @param   {Number}    delay
 * @return  {TimeoutId}
 */
function debounceDelay (func, delay) {
	return setTimeout(function () {
		func.call(func);
	}, toNumber(delay));
}

export default {
	/**
	 * 绑定 text 变化事件
	 */
	bind: function () {
		var self = this;
		var lazy = this.lazy;
		var number = this.number;
		var debounce = this.debounce;
		var directive = this.directive;

		/**
		 * 表单值变化设置数据值
		 * @param  {String}  value  [表单值]
		 */
		function setModelValue (value) {
			if (debounce) {
				debounceDelay(function () {
					self.onDebounce = true;
					directive.set(formatValue(value, number));
				}, debounce);
			} else {
				directive.set(formatValue(value, number));
			}
		}

		// 解决中文输入时 input 事件在未选择词组时的触发问题
		// https://developer.mozilla.org/zh-CN/docs/Web/Events/compositionstart
		var composeLock;

		this.on('compositionstart', function () {
			composeLock = true;
		});

		this.on('compositionend', function () {
			composeLock = false;
			if (!lazy) {
				setModelValue(this.value);
			}
		});

		// input 事件(实时触发)
		this.on('input', function () {
			if (!composeLock && !lazy) {
				setModelValue(this.value);
			}
		});

		// change 事件(失去焦点触发)
		this.on('change', function () {
			directive.set(formatValue(this.value, number));
		});
	},

	/**
	 * 更新 text 值
	 * @param   {String}  value
	 */
	update: function (value) {
		var el = this.el;
		if (el.value !== value && !this.onDebounce) {
			el.value = value;
		}
	}
}
{'fraction_non_alphanumeric': 0.16606379480434066, 'fraction_numerical': 0.0, 'mean_word_length': 2.850632911392405, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7372218', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1162, 'n_words': 224}