<commit_before>// Make sure u use EMPTY_OBJ from 'inferno', otherwise it'll be a different reference
import { EMPTY_OBJ, createVNode, options, VNode, Props } from 'inferno';
import VNodeFlags from 'inferno-vnode-flags';
import {
	ERROR_MSG,
	isArray,
	isBrowser,
	isFunction,
	isInvalid,
	isNullOrUndef,
	isStringOrNumber,
	Lifecycle,
	NO_OP,
	throwError,
	combineFrom,
	isUndefined
} from 'inferno-shared';

let noOp = ERROR_MSG;

if (process.env.NODE_ENV !== 'production') {
	noOp = 'Inferno Error: Can only update a mounted or mounting component. This usually means you called setState() or forceUpdate() on an unmounted component. This is a no-op.';
}

const componentCallbackQueue: Map<any, Function[]> = new Map();

export interface ComponentLifecycle<P, S> {
	componentDidMount?(): void;
	componentWillMount?(): void;
	componentWillReceiveProps?(nextProps: P, nextContext: any): void;
	shouldComponentUpdate?(nextProps: P, nextState: S, nextContext: any): boolean;
	componentWillUpdate?(nextProps: P, nextState: S, nextContext: any): void;
	componentDidUpdate?(prevProps: P, prevState: S, prevContext: any): void;
	componentWillUnmount?(): void;
}

// when a components root VNode is also a component, we can run into issues
// this will recursively look for vNode.parentNode if the VNode is a component
function updateParentComponentVNodes(vNode: VNode, dom: Element) {
	if (vNode.flags & VNodeFlags.Component) {
		const parentVNode = vNode.parentVNode;

		if (parentVNode) {
			parentVNode.dom = dom;
			updateParentComponentVNodes(parentVNode, dom);
		}
	}
}

const resolvedPromise = Promise.resolve();

function addToQueue(component: Component<any, any>, force: boolean, callback?: Function): void {
	// TODO this function needs to be revised and improved on
	let queue: any = componentCallbackQueue.get(component);

	if (!queue) {
		queue = [];
		componentCallbackQueue.set(component, queue);
		resolvedPromise.then(() => {
			componentCallbackQueue.delete(component);
			applyState(component, force, () => {
				for (let i = 0, len = queue.length; i < len; i++) {
					queue[i]();
				}
			});
		});
	}
	if (callback) {
		queue.push(
			callback
		);
	}
}

function queueStateChanges<P, S>(component: Component<P, S>, newState, callback: Function, sync: boolean): void {
	if (isFunction(newState)) {
		newState = newState(component.state, component.props, component.context);
	}
	for (let stateKey in newState) {
		component._pendingState[stateKey] = newState[stateKey];
	}
	if (!component._pendingSetState && isBrowser && !(sync && component._blockRender)) {
		if (sync || component._blockRender) {
			component._pendingSetState = true;
			applyState(component, false, callback);
		} else {
			addToQueue(component, false, callback);
		}
	} else {
		const pending = component._pendingState;
		const state = component.state;

		for (const key in pending) {
			state[key] = pending[key];
		}
		component._pendingState = {};
	}
}

function applyState<P, S>(component: Component<P, S>, force: boolean, callback: Function): void {
	if ((!component._deferSetState || force) && !component._blockRender && !component._unmounted) {
		component._pendingSetState = false;
		const pendingState = component._pendingState;
		const prevState = component.state;
		const nextState = combineFrom(prevState, pendingState) as S;
		const props = component.props as P;
		const context = component.context;<commit_msg>added missing code form last night<commit_after>// Make sure u use EMPTY_OBJ from 'inferno', otherwise it'll be a different reference
import { EMPTY_OBJ, createVNode, options, VNode, Props } from 'inferno';
import VNodeFlags from 'inferno-vnode-flags';
import {
	ERROR_MSG,
	isArray,
	isBrowser,
	isFunction,
	isInvalid,
	isNullOrUndef,
	isStringOrNumber,
	Lifecycle,
	NO_OP,
	throwError,
	combineFrom,
	isUndefined
} from 'inferno-shared';

let noOp = ERROR_MSG;

if (process.env.NODE_ENV !== 'production') {
	noOp = 'Inferno Error: Can only update a mounted or mounting component. This usually means you called setState() or forceUpdate() on an unmounted component. This is a no-op.';
}

const componentCallbackQueue: Map<any, Function[]> = new Map();

export interface ComponentLifecycle<P, S> {
	componentDidMount?(): void;
	componentWillMount?(): void;
	componentWillReceiveProps?(nextProps: P, nextContext: any): void;
	shouldComponentUpdate?(nextProps: P, nextState: S, nextContext: any): boolean;
	componentWillUpdate?(nextProps: P, nextState: S, nextContext: any): void;
	componentDidUpdate?(prevProps: P, prevState: S, prevContext: any): void;
	componentWillUnmount?(): void;
}

// when a components root VNode is also a component, we can run into issues
// this will recursively look for vNode.parentNode if the VNode is a component
function updateParentComponentVNodes(vNode: VNode, dom: Element) {
	if (vNode.flags & VNodeFlags.Component) {
		const parentVNode = vNode.parentVNode;

		if (parentVNode) {
			parentVNode.dom = dom;
			updateParentComponentVNodes(parentVNode, dom);
		}
	}
}

const resolvedPromise = Promise.resolve();

function addToQueue(component: Component<any, any>, force: boolean, callback?: Function): void {
	// TODO this function needs to be revised and improved on
	let queue: any = componentCallbackQueue.get(component);

	if (!queue) {
		queue = [];
		componentCallbackQueue.set(component, queue);
		resolvedPromise.then(() => {
			componentCallbackQueue.delete(component);
			component._updating = true;
			applyState(component, force, () => {
				for (let i = 0, len = queue.length; i < len; i++) {
					queue[i]();
				}
			});
			component._updating = false;
		});
	}
	if (callback) {
		queue.push(
			callback
		);
	}
}

function queueStateChanges<P, S>(component: Component<P, S>, newState, callback: Function, sync: boolean): void {
	if (isFunction(newState)) {
		newState = newState(component.state, component.props, component.context);
	}
	for (let stateKey in newState) {
		component._pendingState[stateKey] = newState[stateKey];
	}
	if (!component._pendingSetState && isBrowser && !(sync && component._blockRender)) {
		if ((sync || component._blockRender) && !component._updating) {
			component._pendingSetState = true;
			component._updating = true;
			applyState(component, false, callback);
			component._updating = false;
		} else {
			addToQueue(component, false, callback);
		}
	} else {
		const pending = component._pendingState;
		const state = component.state;

		for (const key in pending) {
			state[key] = pending[key];
		}
		component._pendingState = {};
	}
}

function applyState<P, S>(component: Component<P, S>, force: boolean, callback: Function): void {
	if ((!component._deferSetState || force) && !component._blockRender && !component._unmounted) {
		component._pendingSetState = false;
		const pendingState = component._pendingState;
		const prevState = component.state;
		const nextState = combineFrom(prevState, pendingState) as S;
		const props = component.props as P;
		const context = component.context;
{'fraction_non_alphanumeric': 0.12158489486482621, 'fraction_numerical': 0.00028608210556429694, 'mean_word_length': 4.890480202190396, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, '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': '3616365', 'n_tokens_mistral': 2283, 'n_tokens_neox': 2145, 'n_words': 615}