<commit_before>using Uno;
using Uno.Collections;
using Fuse.Scripting;

namespace Fuse.Reactive
{
	class ModuleInstance: DiagnosticSubject
	{
		readonly ThreadWorker _worker;
		readonly JavaScript _js;
		readonly Dictionary<string, object> _deps = new Dictionary<string, object>();

		// UI thread
		public ModuleInstance(ThreadWorker worker, JavaScript js)
		{
			for (var i = 0; i < js.Dependencies.Count; i++)
				_deps.Add(js.Dependencies[i].Name, worker.Unwrap(js.Dependencies[i].Value));

			_js = js;
			_worker = worker;
			_worker.Invoke(Evaluate);
		}

		// JS thread
		void Evaluate()
		{
			_js.ScriptModule.Dependencies = _deps;
			_dc = _worker.Reflect(EvaluateExports());
			UpdateManager.PostAction(SetDataContext);
		}

		object _dc;

		// UI thread
		void SetDataContext()
		{
			_js.SetDataContext(_dc);
		}

		ModuleResult _moduleResult;

		public void Dispose()
		{
			ClearDiagnostic();

			if (_moduleResult != null)
			{
				_moduleResult.Dispose();
				_moduleResult = null;<commit_msg>Fixes based on mortoray's feedback<commit_after>using Uno;
using Uno.Collections;
using Fuse.Scripting;

namespace Fuse.Reactive
{
	class ModuleInstance: DiagnosticSubject
	{
		readonly ThreadWorker _worker;
		readonly JavaScript _js;
		readonly Dictionary<string, object> _deps = new Dictionary<string, object>();

		// UI thread
		public ModuleInstance(ThreadWorker worker, JavaScript js)
		{
			for (var i = 0; i < js.Dependencies.Count; i++)
				_deps.Add(js.Dependencies[i].Name, worker.Unwrap(js.Dependencies[i].Value));

			_js = js;
			_worker = worker;
			_worker.Invoke(Evaluate);
		}

		// JS thread
		void Evaluate()
		{
			_js.ScriptModule.Dependencies = _deps;
			_dc = _worker.Reflect(EvaluateExports());
			UpdateManager.PostAction(SetDataContext);
		}

		object _dc;

		// UI thread
		void SetDataContext()
		{
			if (_moduleResult != null) // don't do this if we were disposed in the mean time
				_js.SetDataContext(_dc);
		}

		ModuleResult _moduleResult;

		public void Dispose()
		{
			ClearDiagnostic();

			if (_moduleResult != null)
			{
				_moduleResult.Dispose();
				_moduleResult = null;
{'fraction_non_alphanumeric': 0.1118421052631579, 'fraction_numerical': 0.0009398496240601503, 'mean_word_length': 3.720620842572062, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '3827410', 'n_tokens_mistral': 823, 'n_tokens_neox': 677, 'n_words': 163}