<commit_before>import observer from 'observe-js';
const PathObserver = observer.PathObserver;
const ArrayObserver = observer.ArrayObserver;
const ObjectObserver = observer.ObjectObserver;

var deepGetter = function(obj, path){
	for (var i=0, path=path.split('.'), len=path.length; i<len; i++){
		obj = obj[path[i]];
	}
	return obj;
};

/**
 * @param {Object} comp react component
 * @param {Object} store object you use to store state in
 * @param {String} varName variable name that you have for the store in the component render function
 */
export default function observeStore(comp, store, varName){
	const renderString = comp.render.toString();
	const reg = new RegExp(varName + '\\S*\\b', 'ig');
	const storeAcessors = renderString.match(reg);
	if (storeAcessors) {
		const observers = storeAcessors.map((path) => {
			path = path.substr(varName.length + 1);
			var val = deepGetter(store, path);
			var observer;
			if (Array.isArray(val)) {
				observer = new ArrayObserver(val);
			} else if(typeof val === 'object'){
				observer = new 	ObjectObserver(val);
			} else {
				observer = new PathObserver(store, path);
			}
			observer.open(() => {
				comp.forceUpdate();
			});
			return observer;
		});

		var originalUnmount = comp.componentWillUnmount;
		comp.componentWillUnmount = function() {
			observers.forEach((observer)=>{
				observer.close();
			});<commit_msg>suing much better Path object to access paths on the store now<commit_after>import observe from 'observe-js';
const PathObserver = observe.PathObserver;
const ArrayObserver = observe.ArrayObserver;
const ObjectObserver = observe.ObjectObserver;
const Path = observe.Path;

/**
 * @param {Object} comp react component
 * @param {Object} store object you use to store state in
 * @param {String} varName variable name that you have for the store in the component render function
 */
export default function observeStore(comp, store, varName){
	const renderString = comp.render.toString();
	const reg = new RegExp(varName + '\\S*\\b', 'ig');
	const storeAcessors = renderString.match(reg);
	if (storeAcessors) {
		const observers = storeAcessors.map((path) => {
			path = path.substr(varName.length + 1);
			var pathObj = Path.get(path);
			var val = pathObj.getValueFrom(store);
			var observer;
			if (Array.isArray(val)) {
				observer = new ArrayObserver(val);
			} else if(typeof val === 'object'){
				observer = new 	ObjectObserver(val);
			} else {
				observer = new PathObserver(store, path);
			}
			observer.open(() => {
				comp.forceUpdate();
			});
			return observer;
		});

		var originalUnmount = comp.componentWillUnmount;
		comp.componentWillUnmount = function() {
			observers.forEach((observer)=>{
				observer.close();
			});
{'fraction_non_alphanumeric': 0.13233137829912023, 'fraction_numerical': 0.0010997067448680353, 'mean_word_length': 4.1783681214421255, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 9, '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': '4403016', 'n_tokens_mistral': 919, 'n_tokens_neox': 814, 'n_words': 239}