<commit_before>
// TODO : remove dependancy, include functions
var _ = require('lib/underscore');


/*
 * Expose `Watcher`
 */

exports.Watcher = Watcher;


var JSS_PROPERTIES = [
		// 'backgroundColor', 'backgroundDisableColor', 'borderColor', 'backgroundDisabledImage', 'backgroundFocusedColor',
		// 'backgroundFocusedImage', 'backgroundImage', 'backgroundLeftCap', 'backgroundPaddingBottom', 'backgroundPaddingLeft', 
		// 'backgroundPaddingRight', 'backgroundPaddingTop', 'backgroundRepeat', 'backgroundSelectedColor', 'backgroundSelectedImage', 
		// 'backgroundTopCap', 'borderColor', 'borderWidth', 'borderRadius', 'bottom', 'color', 'font', 'height', 'highlightedColor', 
		// 'left', 'minimumFontSize', 'opacity', 'right', 'shadowColor', 'shadowOffset', 'textAlign', 'top', 
		// 'verticalAlign', 'wordWrap', 'zIndex'
		'backgroundColor', 'borderColor', 'borderWidth', 'color', 'font', 'layout', 'top', 'bottom', 'left', 'right', 'height', 'width',
		'text', 'opacity', 'z-index'
	];

// Default style dictionnary for properties that doesn't consider undefined to reset the value.
var RESET_STYLE = {
	backgroundColor: 'transparent',
	borderColor: 'transparent',
	borderWidth: 0,
	font: {},
};


var TiObject = (function () {
	
	function handleLayout (object, callback) {
		try {
			if (!isAndroid()) {
				object.startLayout();
				callback();
				object.finishLayout();
			} else {
				callback();
			}
		} catch (ex) {
			Ti.API.error(ex);
		}
	}
	
	var tableUtil = {
		
		sections: function (table, fn) {
			_.each(table.data || [], fn)
		},

		rows: function (section, fn) {
			_.each(section.rows || [], fn);
		}
	};
	
	
	return {

		getResetStyle: function () {
			var self = this
				, style = {};
			_.each(JSS_PROPERTIES, function (property) {
				// Do not reset a property that is already reseted to avoid the reset of default Titanium layout.
				if (hasOwnProperty(self, property) && self[property] !== RESET_STYLE[property] && self[property] !== undefined) {
					style[property] = RESET_STYLE[property] ? RESET_STYLE[property] : 'RESET';
				}
			});
			return style;
		},

		getViewHierarchy: function () {
			var children = []
				, type = this.toString();

			// Handle TableView
			if (this.data) {
				tableUtil.sections(this, function (section) {
					children.push(section);
					tableUtil.rows(section, function (row) {
						children.push(row);
					});
				});

			// Handle Navigation group.
			} else if (type === '[object TiUIiPhoneNavigationGroup]') {
				children = [this.window];

			// Handle other components which are accessible with .getChildren().
			} else {
				// On Android, window children are accessible with win._children and win.children on IOS
				if (isAndroid() && type === '[object TiBaseWindow]') {
					children = this._children;
				} else {
					children = this.children;
				}
			}
			return _.compact(children);
		},

		update: function (style) {
			var self = this;
			
			handleLayout(this, function () {
				Ti.API.log('--------------------' + self.toString() + '--------------------');
				for (key in style) {
					if (hasOwnProperty(self, key) && _.include(JSS_PROPERTIES, key)) {
						if (self.frozenCss && _.include(self.frozenCss, key)) {
							Ti.API.log('[frozen] ' + key + ': ' + self[key]); // Do not update frozen property
						} else if (style[key] === 'RESET') {
							Ti.API.log('[reset]  ' + key + ': ' + self[key]);
							self[key] = RESET_STYLE[key]; // set default style value or undefined if not exists
						} else if (self[key] !== style[key]) {
							Ti.API.log('[update] ' + key + ': ' + self[key] + ' to ' + style[key]);
							self[key] = style[key];
						}
					} else {
						Ti.API.log('[warning]  property ' + key + ' not supported');
					}
				}
				Ti.API.log('-------------------------------------------------------\n');
			});
		}
		
	};
}());


function TiCollection () {
	this.data   = [];
	this.styles = {};
	this.baseStyles = {};
}

// Freeze properties that was defined into javascript file
// We can detect these properties by iterate over each ti object and test if their styles correspond to the
// styles received on initialization.
TiCollection.prototype.freezeJsCss = function () {
	var self = this;
	Ti.API.log(this.baseStyles);
	this.styles = _.clone(this.baseStyles);
	Ti.API.log(this.baseStyles);
	
	_.each(this.data, function (object) {
		object.frozenCss = [];
		
		_.each(self.getStyle(object), function (value, property) {
			if (!hasOwnProperty(object, property)) { return; }
			
			var objectValue = object[property];
			if (objectValue !== value && objectValue !== undefined) {
				object.frozenCss.push(property);
				Ti.API.log('freeze : '+object+'.'+property);
			}
		});
	});
	
	return this;
} 

TiCollection.prototype.sync = function (windows) {
	var i = 0
		, self = this;
	
	this.data = _.clone(windows);
	
	// TODO : improve algorythme performance by implementing a memoizer on find children method
	for (i=0; i<this.data.length; i++) {
		this.data = _.union(this.data, TiObject.getViewHierarchy.apply(this.data[i]));
	}
	
	Ti.API.log(this.baseStyles);
	
	return this;
}

TiCollection.prototype.refreshAll = function (css) {
	var self = this;
	this.styles = css;
	
	_.each(this.data, function (object) {
		self.refresh(object);
	});<commit_msg>add log to fix bug on frozen properties<commit_after>
// TODO : remove dependancy, include functions
var _ = require('lib/underscore');


/*
 * Expose `Watcher`
 */

exports.Watcher = Watcher;


var JSS_PROPERTIES = [
		// 'backgroundColor', 'backgroundDisableColor', 'borderColor', 'backgroundDisabledImage', 'backgroundFocusedColor',
		// 'backgroundFocusedImage', 'backgroundImage', 'backgroundLeftCap', 'backgroundPaddingBottom', 'backgroundPaddingLeft', 
		// 'backgroundPaddingRight', 'backgroundPaddingTop', 'backgroundRepeat', 'backgroundSelectedColor', 'backgroundSelectedImage', 
		// 'backgroundTopCap', 'borderColor', 'borderWidth', 'borderRadius', 'bottom', 'color', 'font', 'height', 'highlightedColor', 
		// 'left', 'minimumFontSize', 'opacity', 'right', 'shadowColor', 'shadowOffset', 'textAlign', 'top', 
		// 'verticalAlign', 'wordWrap', 'zIndex'
		'backgroundColor', 'borderColor', 'borderWidth', 'color', 'font', 'layout', 'top', 'bottom', 'left', 'right', 'height', 'width',
		'text', 'opacity', 'z-index'
	];

// Default style dictionnary for properties that doesn't consider undefined to reset the value.
var RESET_STYLE = {
	backgroundColor: 'transparent',
	borderColor: 'transparent',
	borderWidth: 0,
	font: {},
};


var TiObject = (function () {
	
	function handleLayout (object, callback) {
		try {
			if (!isAndroid()) {
				object.startLayout();
				callback();
				object.finishLayout();
			} else {
				callback();
			}
		} catch (ex) {
			Ti.API.error(ex);
		}
	}
	
	var tableUtil = {
		
		sections: function (table, fn) {
			_.each(table.data || [], fn)
		},

		rows: function (section, fn) {
			_.each(section.rows || [], fn);
		}
	};
	
	
	return {

		getResetStyle: function () {
			var self = this
				, style = {};
			_.each(JSS_PROPERTIES, function (property) {
				// Do not reset a property that is already reseted to avoid the reset of default Titanium layout.
				if (hasOwnProperty(self, property) && self[property] !== RESET_STYLE[property] && self[property] !== undefined) {
					style[property] = RESET_STYLE[property] ? RESET_STYLE[property] : 'RESET';
				}
			});
			return style;
		},

		getViewHierarchy: function () {
			var children = []
				, type = this.toString();

			// Handle TableView
			if (this.data) {
				tableUtil.sections(this, function (section) {
					children.push(section);
					tableUtil.rows(section, function (row) {
						children.push(row);
					});
				});

			// Handle Navigation group.
			} else if (type === '[object TiUIiPhoneNavigationGroup]') {
				children = [this.window];

			// Handle other components which are accessible with .getChildren().
			} else {
				// On Android, window children are accessible with win._children and win.children on IOS
				if (isAndroid() && type === '[object TiBaseWindow]') {
					children = this._children;
				} else {
					children = this.children;
				}
			}
			return _.compact(children);
		},

		update: function (style) {
			var self = this;
			
			handleLayout(this, function () {
				Ti.API.log('--------------------' + self.toString() + '--------------------');
				for (key in style) {
					if (hasOwnProperty(self, key) && _.include(JSS_PROPERTIES, key)) {
						if (self.frozenCss && _.include(self.frozenCss, key)) {
							Ti.API.log('[frozen] ' + key + ': ' + self[key]); // Do not update frozen property
						} else if (style[key] === 'RESET') {
							Ti.API.log('[reset]  ' + key + ': ' + self[key]);
							self[key] = RESET_STYLE[key]; // set default style value or undefined if not exists
						} else if (self[key] !== style[key]) {
							Ti.API.log('[update] ' + key + ': ' + self[key] + ' to ' + style[key]);
							self[key] = style[key];
						}
					} else {
						Ti.API.log('[warning]  property ' + key + ' not supported');
					}
				}
				Ti.API.log('-------------------------------------------------------\n');
			});
		}
		
	};
}());


function TiCollection () {
	this.data   = [];
	this.styles = {};
	this.baseStyles = {};
}

// Freeze properties that was defined into javascript file
// We can detect these properties by iterate over each ti object and test if their styles correspond to the
// styles received on initialization.
TiCollection.prototype.freezeJsCss = function () {
	var self = this;
	Ti.API.log(this.baseStyles);
	this.styles = _.clone(this.baseStyles);
	Ti.API.log(this.baseStyles);
	
	_.each(this.data, function (object) {
		object.frozenCss = [];
		
		_.each(self.getStyle(object), function (value, property) {
			if (!hasOwnProperty(object, property)) { return; }
			
			var objectValue = object[property];
			if (objectValue !== value && objectValue !== undefined) {
				object.frozenCss.push(property);
				Ti.API.log('freeze : '+object+'.'+property);
			}
		});
		
		Ti.API.log(object.frozenCss.length);
	});
	
	// WTF !!!!!!!!!!!!!!!!!!!
	_.each(this.data, function (obj) {
		Ti.API.log(obj.frozenCss.length);
	})
	
	return this;
} 

TiCollection.prototype.sync = function (windows) {
	var i = 0
		, self = this;
	
	this.data = _.clone(windows);
	
	// TODO : improve algorythme performance by implementing a memoizer on find children method
	for (i=0; i<this.data.length; i++) {
		this.data = _.union(this.data, TiObject.getViewHierarchy.apply(this.data[i]));
	}
	
	Ti.API.log(this.baseStyles);
	
	return this;
}

TiCollection.prototype.refreshAll = function (css) {
	var self = this;
	this.styles = css;
	
	_.each(this.data, function (object) {
		self.refresh(object);
	});
{'fraction_non_alphanumeric': 0.17970204841713222, 'fraction_numerical': 0.0005586592178770949, 'mean_word_length': 3.15995352439969, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1582027', 'n_tokens_mistral': 3995, 'n_tokens_neox': 3331, 'n_words': 813}