{"size": 545, "ext": "js", "max_stars_repo_path": "src/helpers/createObservable.js", "max_stars_repo_name": "trezy-studios/js13k-2020", "max_stars_repo_stars_event_min_datetime": "2020-10-02T10:03:38.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-02T10:03:38.000Z", "max_issues_repo_path": "src/helpers/createObservable.js", "max_issues_repo_name": "trezy-studios/js13k-2020", "max_issues_repo_issues_event_min_datetime": "2020-08-13T21:13:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T09:48:16.000Z", "max_forks_repo_path": "src/helpers/createObservable.js", "max_forks_repo_name": "trezy-studios/js13k-2020", "max_forks_repo_forks_event_min_datetime": "2020-09-13T14:55:20.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-13T14:55:20.000Z"}
{"max_stars_count": 1, "max_issues_count": 29, "max_forks_count": 1, "avg_line_length": 18.1666666667, "max_line_length": 76, "alphanum_fraction": 0.6458715596}
export function createObservable(objectToObserve) {
	let eventTarget = new EventTarget

	return new Proxy(objectToObserve, {
		get (object, key) {
			if (key === 'on') {
				return eventTarget.on.bind(eventTarget)
			}

			return object[key]
		},

		set (object, key, value) {
			let eventOptions = {
				detail: {
					key,
					value,
				},
			}

			object[key] = value

			eventTarget.dispatchEvent(new CustomEvent(`change:${key}`, eventOptions))
			eventTarget.dispatchEvent(new CustomEvent('change', eventOptions))

			return 1
		},
	})
}
