<commit_before>import { store } from "./store";
import { update } from "./router";

let nextComponent = null

const component = function(componentProto)
{
	function Component(nodeName, key) {
		NodeData.call(this, nodeName, key)
	}

	const proto = Object.create(NodeData.prototype);

	for(let key in componentProto)
	{
		const param = Object.getOwnPropertyDescriptor(componentProto, key);
		if(param.get || param.set) {
			Object.defineProperty(proto, key, param);
		}
		else {
			proto[key] = componentProto[key];
		}
	}

	const states = proto.state
	for(let key in states)
	{
		Object.defineProperty(proto, "$" + key,
		{
			set(value) {
				this.setState(key, value)
			},
			get() {
				return this.$[key]
			}
		})
	}

	if(proto.state.value === undefined) {
		proto.state.value = null
	}

	Component.prototype = proto;
	Component.prototype.constructor = Component;

	return Component
}

function NodeData(nodeName, key)
{
	this.nodeName = nodeName
	this.attributes = Object.create(null)
	this.parentAttributes = null
	this.staticsApplied = false

	/**
	 * The key used to identify this node, used to preserve DOM nodes when they
	 * move within their parent.
	 * @const
	 */
	this.key = key;

	/**
	 * Keeps track of children within this node by their key.
	 * {!Object<string, !Element>}
	 */
	this.keyMap = Object.create(null);

	this.bindFuncs = Object.create(null)

	/**
	 * Whether or not the keyMap is currently valid.
	 * @type {boolean}
	 */
	this.keyMapValid = true;

	/**
	 * The node name for this node.
	 * @const {string}
	 */
	
	const currState = {}
	for(let key in this.state) {
		currState[key] = this.state[key]
	}

	this.$ = currState;
}

NodeData.prototype =
{
	state: {
		value: null
	},

	remove()
	{
		const bindings = this.attributes.bind
		if(bindings)
		{
			if(typeof bindings === "string") {
				store.unwatch(bindings, this.bindFuncs.value)
			}
			else
			{
				for(let key in bindings) {
					store.unwatch(bindings[key], this.bindFuncs[key])
				}
			}

			this.bindFuncs = null
		}
	},

	setState(state, value)
	{
		if(this.$[state] === value) { return }

		if(this.attributes.bind)
		{
			if(typeof this.attributes.bind === "string")
			{
				if(state === "value") {
					store.set(this.attributes.bind, value, true)<commit_msg>Add support for component unount<commit_after>import { store } from "./store";
import { update } from "./router";

let nextComponent = null

const component = function(componentProto)
{
	function Component(nodeName, key) {
		NodeData.call(this, nodeName, key)
	}

	const proto = Object.create(NodeData.prototype);

	for(let key in componentProto)
	{
		const param = Object.getOwnPropertyDescriptor(componentProto, key);
		if(param.get || param.set) {
			Object.defineProperty(proto, key, param);
		}
		else {
			proto[key] = componentProto[key];
		}
	}

	const states = proto.state
	for(let key in states)
	{
		Object.defineProperty(proto, "$" + key,
		{
			set(value) {
				this.setState(key, value)
			},
			get() {
				return this.$[key]
			}
		})
	}

	if(proto.state.value === undefined) {
		proto.state.value = null
	}

	Component.prototype = proto;
	Component.prototype.constructor = Component;

	return Component
}

function NodeData(nodeName, key)
{
	this.nodeName = nodeName
	this.attributes = Object.create(null)
	this.parentAttributes = null
	this.staticsApplied = false

	/**
	 * The key used to identify this node, used to preserve DOM nodes when they
	 * move within their parent.
	 * @const
	 */
	this.key = key;

	/**
	 * Keeps track of children within this node by their key.
	 * {!Object<string, !Element>}
	 */
	this.keyMap = Object.create(null);

	this.bindFuncs = Object.create(null)

	/**
	 * Whether or not the keyMap is currently valid.
	 * @type {boolean}
	 */
	this.keyMapValid = true;

	/**
	 * The node name for this node.
	 * @const {string}
	 */
	
	const currState = {}
	for(let key in this.state) {
		currState[key] = this.state[key]
	}

	this.$ = currState;
}

NodeData.prototype =
{
	state: {
		value: null
	},

	unmount: null,

	remove()
	{
		if(this.unmount) {
			this.unmount()
		}

		const bindings = this.attributes.bind
		if(bindings)
		{
			if(typeof bindings === "string") {
				store.unwatch(bindings, this.bindFuncs.value)
			}
			else
			{
				for(let key in bindings) {
					store.unwatch(bindings[key], this.bindFuncs[key])
				}
			}

			this.bindFuncs = null
		}
	},

	setState(state, value)
	{
		if(this.$[state] === value) { return }

		if(this.attributes.bind)
		{
			if(typeof this.attributes.bind === "string")
			{
				if(state === "value") {
					store.set(this.attributes.bind, value, true)
{'fraction_non_alphanumeric': 0.1409366869037294, 'fraction_numerical': 0.0, 'mean_word_length': 3.189827429609446, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3257442', 'n_tokens_mistral': 1785, 'n_tokens_neox': 1571, 'n_words': 365}