<commit_before>'use strict';

var wordScramble = wordScramble || {};
wordScramble.uiService = (function(configuration, gameService)
{
	var uiService = {};

	uiService.submitLetter = function(letter, id)
	{
		if (gameService.getGameData().letters.indexOf(letter) === -1)
		{
			// not a valid letter
			return;
		}

		var wordAttemptContainer = document.querySelector("#wordAttempt");
		wordScramble.pubsub.unsubscribe("wordScramble/wordAttemptUpdated");
		wordScramble.pubsub.subscribe("wordScramble/wordAttemptUpdated", function(topic, data)
		{
			wordAttemptContainer.textContent = data.wordString;
		});

		// if it was the last letter submitted, go ahead and roll it back
		var previousAttempt = wordScramble.wordAttemptService.getPrevious();
		if (previousAttempt != null && previousAttempt.token == id)
		{
			wordScramble.wordAttemptService.removePrevious();
			return;
		}

		// if it was not the last letter submitted, but HAS been submitted,
		// it's just not valid
		var existing = wordScramble.wordAttemptService.getByToken(id);
		if (existing && existing.length > 0 && existing[0].token === id)
		{
			console.log("stopping!");
			return;
		}

		wordScramble.wordAttemptService.add(letter, id);
	}

	function provideFeedback(feedback)
	{
		document.addEventListener('animationend', function(evt)
		{
			document.querySelector("#gameContainer").classList.remove(feedback);
		}, false);
		document.addEventListener('webkitAnimationEnd', function(evt)
		{
			document.querySelector("#gameContainer").classList.remove(feedback);
		}, false);
		document.querySelector("#gameContainer").classList.add(feedback);
	}

	function snoop()
	{
		var pubListener = function(topic, data)
		{
			console.log("log: "+topic+" received with "+JSON.stringify(data));
		}
		wordScramble.pubsub.subscribeAll(pubListener);
	}

	function subscribe()
	{
		if (configuration.debug && configuration.debug === true)
		{
			snoop();
		}

		wordScramble.pubsub.subscribe("wordScramble/endGame", function()
		{
			gameService.clearGameCache();
		});
		wordScramble.pubsub.subscribe("wordScramble/startGame", function()
		{
			gameService.startGame();
		});
		wordScramble.pubsub.subscribe("wordScramble/submitWord", function()
		{
			gameService.submitWordAttempt(wordScramble.wordAttemptService.getWordString());
			wordScramble.wordAttemptService.clear();
		});
		wordScramble.pubsub.subscribe("wordScramble/clearWordAttempt", function()
		{
			wordScramble.wordAttemptService.clear();
		});
		wordScramble.pubsub.subscribe("wordScramble/submitLetter", function(topic, data)
		{
			var letter = data.letter;
			var token = data.token;
			uiService.submitLetter(letter, token);
		});
		wordScramble.pubsub.subscribe("wordScramble/gameReady", function()
		{<commit_msg>Remove call to snoop() to resolve issue #13<commit_after>'use strict';

var wordScramble = wordScramble || {};
wordScramble.uiService = (function(configuration, gameService)
{
	var uiService = {};

	uiService.submitLetter = function(letter, id)
	{
		if (gameService.getGameData().letters.indexOf(letter) === -1)
		{
			// not a valid letter
			return;
		}

		var wordAttemptContainer = document.querySelector("#wordAttempt");
		wordScramble.pubsub.unsubscribe("wordScramble/wordAttemptUpdated");
		wordScramble.pubsub.subscribe("wordScramble/wordAttemptUpdated", function(topic, data)
		{
			wordAttemptContainer.textContent = data.wordString;
		});

		// if it was the last letter submitted, go ahead and roll it back
		var previousAttempt = wordScramble.wordAttemptService.getPrevious();
		if (previousAttempt != null && previousAttempt.token == id)
		{
			wordScramble.wordAttemptService.removePrevious();
			return;
		}

		// if it was not the last letter submitted, but HAS been submitted,
		// it's just not valid
		var existing = wordScramble.wordAttemptService.getByToken(id);
		if (existing && existing.length > 0 && existing[0].token === id)
		{
			console.log("stopping!");
			return;
		}

		wordScramble.wordAttemptService.add(letter, id);
	}

	function provideFeedback(feedback)
	{
		document.addEventListener('animationend', function(evt)
		{
			document.querySelector("#gameContainer").classList.remove(feedback);
		}, false);
		document.addEventListener('webkitAnimationEnd', function(evt)
		{
			document.querySelector("#gameContainer").classList.remove(feedback);
		}, false);
		document.querySelector("#gameContainer").classList.add(feedback);
	}

	function snoop()
	{
		var pubListener = function(topic, data)
		{
			console.log("log: "+topic+" received with "+JSON.stringify(data));
		}
		wordScramble.pubsub.subscribeAll(pubListener);
	}

	function subscribe()
	{
		if (configuration.debug && configuration.debug === true)
		{
			//snoop();
		}

		wordScramble.pubsub.subscribe("wordScramble/endGame", function()
		{
			gameService.clearGameCache();
		});
		wordScramble.pubsub.subscribe("wordScramble/startGame", function()
		{
			gameService.startGame();
		});
		wordScramble.pubsub.subscribe("wordScramble/submitWord", function()
		{
			gameService.submitWordAttempt(wordScramble.wordAttemptService.getWordString());
			wordScramble.wordAttemptService.clear();
		});
		wordScramble.pubsub.subscribe("wordScramble/clearWordAttempt", function()
		{
			wordScramble.wordAttemptService.clear();
		});
		wordScramble.pubsub.subscribe("wordScramble/submitLetter", function(topic, data)
		{
			var letter = data.letter;
			var token = data.token;
			uiService.submitLetter(letter, token);
		});
		wordScramble.pubsub.subscribe("wordScramble/gameReady", function()
		{
{'fraction_non_alphanumeric': 0.13524738172625497, 'fraction_numerical': 0.001444564824846515, 'mean_word_length': 4.917735042735043, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6570359', 'n_tokens_mistral': 1944, 'n_tokens_neox': 1645, 'n_words': 283}