<commit_before>// Wraps Tizen module "CallHistory".

define(['Ti/_/lang', 'Tizen/_/CallHistory/CallHistoryEntry', 'Tizen/_/WebAPIError', 'Ti/_/Evented'], function(lang, CallHistoryEntry, WebAPIError, Evented) {

	function onError (e, callback) {
		callback({
			code: e.code,
			success: false,
			error: e.type + ': ' + e.message
		});
	}

	function onSuccess (callback) {
		callback({
			code: 0,
			success: true
		});
	}

	return lang.mixProps(require.mix({}, Evented), {

			find: function(callback, filter /*AbstractFilter*/, sortMode /*SortMode*/, limit /*unsigned long*/, offset /*unsigned long*/) {
				tizen.callhistory.find(callback && function(entries) {
					var result = [],
						entriesCount = entries.length,
						i = 0;

					for (; i < entriesCount; i++) {
						result.push(new CallHistoryEntry(entries[i]));
					}

					callback({
						code: 0,
						success: true,
						entries: result
					});
				}, callback && function(e) {
					onError(e, callback);
				}, filter && filter._obj, sortMode && sortMode._obj, limit, offset);
			},

			remove: function(entry /*CallHistoryEntry*/) {
				tizen.callhistory.remove(entry._obj);
			},

			removeBatch: function(entries /*CallHistoryEntry*/, callback) {
				var i = 0,
					entriesCount = entries.length,
					result = [];

				for (; i < entriesCount; i++) {
					result.push(entries[i]._obj);
				}

				tizen.callhistory.removeBatch(result, callback && function () {
					onSuccess(callback);
				}, callback && function(e) {
					onError(e, callback);
				});
			},

			removeAll: function(callback) {
				tizen.callhistory.removeAll(callback && function () {
					onSuccess(callback);
				}, callback && function(e) {
					onError(e, callback);
				});
			},

			addChangeListener: function(observer /*CallHistoryChangeCallback*/) {
				var object = {
					onadded: function(entries) {
						var result = [],
							i = 0,
							entriesCount = entries.length;

						for (; i < entriesCount; i++) {
							result.push(new CallHistoryEntry(entries[i]));
						}

						observer.onadded(result);
					},
					onchange: function(entries) {
						var result = [],
							i = 0,
							entriesCount = entries.length;

						for (; i < entriesCount; i++) {
							result.push(new CallHistoryEntry(entries[i]));
						}

						observer.onchange(result);
					}
				};

				return tizen.callhistory.addChangeListener(object);
			},

			removeChangeListener: function(handle /*long*/) {
				tizen.callhistory.removeChangeListener(handle);
			}
<commit_msg>Added new events implementation for Tizen.CallHistory<commit_after>// Wraps Tizen module "CallHistory".

define(['Ti/_/lang', 'Tizen/_/CallHistory/CallHistoryEntry', 'Tizen/_/WebAPIError', 'Ti/_/Evented'], function(lang, CallHistoryEntry, WebAPIError, Evented) {

	function onError (e, callback) {
		callback({
			code: e.code,
			success: false,
			error: e.type + ': ' + e.message
		});
	}

	function onSuccess (callback) {
		callback({
			code: 0,
			success: true
		});
	}

	var listening;

	return lang.mixProps(require.mix({}, Evented), {

			find: function(callback, filter /*AbstractFilter*/, sortMode /*SortMode*/, limit /*unsigned long*/, offset /*unsigned long*/) {
				tizen.callhistory.find(callback && function(entries) {
					var result = [],
						entriesCount = entries.length,
						i = 0;

					for (; i < entriesCount; i++) {
						result.push(new CallHistoryEntry(entries[i]));
					}

					callback({
						code: 0,
						success: true,
						entries: result
					});
				}, callback && function(e) {
					onError(e, callback);
				}, filter && filter._obj, sortMode && sortMode._obj, limit, offset);
			},

			remove: function(entry /*CallHistoryEntry*/) {
				tizen.callhistory.remove(entry._obj);
			},

			removeBatch: function(entries /*CallHistoryEntry*/, callback) {
				var i = 0,
					entriesCount = entries.length,
					result = [];

				for (; i < entriesCount; i++) {
					result.push(entries[i]._obj);
				}

				tizen.callhistory.removeBatch(result, callback && function () {
					onSuccess(callback);
				}, callback && function(e) {
					onError(e, callback);
				});
			},

			removeAll: function(callback) {
				tizen.callhistory.removeAll(callback && function () {
					onSuccess(callback);
				}, callback && function(e) {
					onError(e, callback);
				});
			},

			addEventListener: function (event) {
				var self = this;

				Evented.prototype.addEventListener.apply(this, arguments);

				if (!listening) {
					listening = true;

					tizen.callhistory.addChangeListener({
						onadded: function (entries) {
							var i = 0,
								entriesCount = entries.length,
								result = [];

							for (; i < entriesCount; i++) {
								result.push(new CallHistoryEntry(entries[i]));
							}

							self.fireEvent('itemsadded', {
								items: result
							});
						},
						onchanged: function (entries) {
							var result = [],
								i = 0,
								entriesCount = entries.length;

							for (; i < entriesCount; i++) {
								result.push(new CallHistoryEntry(entries[i]));
							}

							self.fireEvent('itemschanged', {
								items: result
							});
						}
					});
				}
			}

{'fraction_non_alphanumeric': 0.1526407428903076, 'fraction_numerical': 0.0023215322112594312, 'mean_word_length': 2.6823361823361824, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, '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': '3856668', 'n_tokens_mistral': 2201, 'n_tokens_neox': 1562, 'n_words': 327}