<commit_before>//let utils = require('./utils')



window.Rectangle = window.Rectangle || {}

window.Rectangle.watchable = function Watchable(object) {

	let reactiveObj = Object.create(Watchable.prototype);

	Object.defineProperty(reactiveObj, '__despatch__', {
		value: () => {

		}
	})
	for (var key in object) {
		// if(object.hasOwnProperty(key)){
		let descriptor = {}
		if(utils.isFunction(object[key])){
			let boundFn = object[key].bind(reactiveObj);
			descriptor.value = (...args) => {

				boundFn(...args)
			}
		}
		Object.defineProperty(reactiveObj, key, {
			set: () => {

			}
		})
		// }
	}
}<commit_msg>added a few blueprint notes about listeners and reference release<commit_after>//let utils = require('./utils')



window.Rectangle = window.Rectangle || {}

window.Rectangle.watchable = function Watchable(object) {

	let reactiveObj;

	let blockDespatch = false;
	let listeners = new Set();
	let reference = new Set();
	let despatchChanges = function despatchChanges() {
		adaptStructChanges(reactiveObj, reference);
		// listeners.forEach
	}

	let closureFields = {
		set blockDespatch(val) { blockDespatch = val },
		get blockDespatch() { return blockDespatch; },
		listeners,
		despatchChanges,
	}
	reactiveObj = generateReactiveStub(closureFields)

	for (var key in object) {
		// if(object.hasOwnProperty(key)){
		animateField(reactiveObj, key, object[key])
		reference.add(key);
		// }
	}
}

function adaptStructChanges(currentObj, lastKnownKeySet) {
	let temporarySet = new Set();
	for(let key in currentObj) {
		if(lastKnownKeySet.has(key)) {
			temporarySet.add(key) ************ blah blah..
			2 settum test cheythittu mutually exclusive aayitollathokke address cheyyanam
		}
	}
}

function animateField(parent, fieldName, value, closureFields) {

	let descriptor = {}
	if (utils.isFunction(value)) {
		let boundFn = value.bind(parent);
		descriptor.value = (...args) => {
			if (closureFields.blockDespatch) return boundFn(...args);
			closureFields.blockDespatch = true;
			let result = boundFn(...args);
			closureFields.blockDespatch = false;
			closureFields.despatchChanges();
			return result;
		}
	}
	Object.defineProperty(parent, fieldName, {
		set: () => {

		}
	})
}

function generateReactiveStub(closureFields) {
	closureFields.blockDespatch = false;

	let reactiveObj = Object.create(Watchable.prototype);

	Object.defineProperty(reactiveObj, '_attachListener', {
		value: function _attachListener(listener) {
			if (utils.isFunction(listener)) 
				closureFields.listeners.add(listener);
		}
	})


	Object.defineProperty(reactiveObj, '_detachListener', {
		value: function _detachListener(listener) {
			if (utils.isFunction(listener)) 
				closureFields.listeners.delete(listener);
		}
	})


	Object.defineProperty(reactiveObj, '_destroy', {
		value: function _destroy(listener) {
			// loop through all children Watchables and call detach on them.
			// This is crusial to avoid trapping references to dead parents.
			// DO NOT DESTROY if there are listeners attached to this object.
			// Re-attach if any new operation happens on this Object or a new listener attaches.
			// This should be a temporary unlinked state.
			// ENSURE THAT ALL REFERENCES (outside of Rectangle) CALL THIS BEFORE CLEARING THEIR REFERENCES

		}
	})

	return reactiveObj;
}
{'fraction_non_alphanumeric': 0.12503784438389343, 'fraction_numerical': 0.0003027550711474417, 'mean_word_length': 4.075268817204301, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '1512033', 'n_tokens_mistral': 1141, 'n_tokens_neox': 1012, 'n_words': 243}