<commit_before>
import destroy from '../lib/destroy'
import createState from '../lib/state'

const _pluginsSystem = [];
let _loadedSystem = false;


/**
 * @param {function}
 */
export function bindSystem(createInstance) {
	return function(plugin) {
		const pluginObj = {
			load(reload=false) {
				if (this.loaded===reload) {
					this.loaded = true;
					destroy(this);
					this.instance = createInstance(this, plugin);
				}
			},
			loaded: false,
			instance: undefined,
			pluginArguments: [createState()],
		};

		_pluginsSystem.push(pluginObj);
		_loadedSystem && pluginObj.load(false);

		return {
			plugins() { return []; },
			hotReload(_plugin) {
				plugin = _plugin;
				pluginObj.load(true);
			},
			willDispose() {
				pluginObj.loaded = false;
				destroy(pluginObj);

				if (_pluginsSystem.indexOf(pluginObj)!==-1) {
					_pluginsSystem.splice(_pluginsSystem.indexOf(pluginObj), 1);
				}
			},
		}
	}
}

<commit_msg>Fix loader/system instance which is handled inside createInstance<commit_after>
import destroy from '../lib/destroy'
import createState from '../lib/state'

const _pluginsSystem = [];
let _loadedSystem = false;


/**
 * @param {function}
 */
export function bindSystem(createInstance) {
	return function(plugin) {
		const pluginObj = {
			load(reload=false) {
				if (this.loaded===reload) {
					this.loaded = true;
					destroy(this);
					createInstance(this, plugin);
				}
			},
			loaded: false,
			instance: undefined,
			pluginArguments: [createState()],
		};

		_pluginsSystem.push(pluginObj);
		_loadedSystem && pluginObj.load(false);

		return {
			plugins() { return []; },
			hotReload(_plugin) {
				plugin = _plugin;
				pluginObj.load(true);
			},
			willDispose() {
				pluginObj.loaded = false;
				destroy(pluginObj);

				if (_pluginsSystem.indexOf(pluginObj)!==-1) {
					_pluginsSystem.splice(_pluginsSystem.indexOf(pluginObj), 1);
				}
			},
		}
	}
}


{'fraction_non_alphanumeric': 0.14457202505219208, 'fraction_numerical': 0.0020876826722338203, 'mean_word_length': 3.396788990825688, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6303788', 'n_tokens_mistral': 745, 'n_tokens_neox': 599, 'n_words': 118}