Remove an unnecessary global.

This commit is contained in:
Andres Jaan Tack
2017-11-30 15:47:16 +02:00
parent b71255380c
commit fe3016a362

View File

@@ -8,10 +8,6 @@ $(function () {
//Our interface to the Sync service //Our interface to the Sync service
var syncClient; var syncClient;
//We're going to use a single Sync document, our simplest
//synchronisation primitive, for this demo
var syncDoc;
//Get an access token for the current user, passing a device ID //Get an access token for the current user, passing a device ID
//In browser-based apps, every tab is like its own unique device //In browser-based apps, every tab is like its own unique device
//synchronizing state -- so we'll use a random UUID to identify //synchronizing state -- so we'll use a random UUID to identify
@@ -28,10 +24,7 @@ $(function () {
//This code will create and/or open a Sync document //This code will create and/or open a Sync document
//Note the use of promises //Note the use of promises
syncClient.document('SyncGame').then(function(doc) { syncClient.document('SyncGame').then(function(syncDoc) {
//Lets store it in our global variable
syncDoc = doc;
//Initialize game board UI to current state (if it exists) //Initialize game board UI to current state (if it exists)
var data = syncDoc.get(); var data = syncDoc.get();
if (data.board) { if (data.board) {
@@ -42,24 +35,21 @@ $(function () {
//changes on this document, we can trigger our UI to update //changes on this document, we can trigger our UI to update
syncDoc.on('updated', updateUserInterface); syncDoc.on('updated', updateUserInterface);
//Whenever a board button is clicked, update that document.
$buttons.on('click', function (e) {
//Toggle the value: X, O, or empty
toggleCellValue($(e.target));
//Send updated document to Sync
//This should trigger "updated" events on other clients
var data = readGameBoardFromUserInterface();
syncDoc.set(data);
});
}); });
}); });
//Whenever a board button is clicked:
$buttons.on('click', function (e) {
//Toggle the value: X, O, or empty
toggleCellValue($(e.target));
//Update the document
var data = readGameBoardFromUserInterface();
//Send updated document to Sync
//This should trigger "updated" events on other clients
syncDoc.set(data);
});
//Toggle the value: X, O, or empty (  for UI) //Toggle the value: X, O, or empty (  for UI)
function toggleCellValue($cell) { function toggleCellValue($cell) {
var cellValue = $cell.html(); var cellValue = $cell.html();