Your IP : 18.226.186.153


Current Path : /var/www/www-root/data/www/info.monolith-realty.ru/bitrix/js/main/core/src/lib/event/
Upload File :
Current File : /var/www/www-root/data/www/info.monolith-realty.ru/bitrix/js/main/core/src/lib/event/ready.js

import Type from '../type';
import bindOnce from './bind-once';

let stack: Array<Function> = [];
/**
 * For compatibility only
 * @type {boolean}
 */
// eslint-disable-next-line
export let isReady = false;

export default function ready(handler: () => void)
{
	if (!Type.isFunction(handler))
	{
		return;
	}

	if (isReady)
	{
		handler();
	}
	else
	{
		stack.push(handler);
	}
}

bindOnce(document, 'DOMContentLoaded', () => {
	isReady = true;

	stack.forEach((handler: Function) => {
		handler();
	});

	stack = [];
});