- get: function(gameId, callback)
- {
- // corr games identifiers are integers
- if (Number.isInteger(gameId) || !isNaN(parseInt(gameId)))
- {
- ajax("/games", "GET", {gid:gameId}, res => {
- let game = res.game;
- game.moves.forEach(m => {
- m.squares = JSON.parse(m.squares);
- });
- callback(game);
- });
- }
- else //local game
- {
- dbOperation((db) => {
- let objectStore = db.transaction('games').objectStore('games');
- objectStore.get(gameId).onsuccess = function(event) {
- callback(event.target.result);
- }
- });
- }
- },
-
- getCurrent: function(callback)
- {
- dbOperation((db) => {
- let objectStore = db.transaction('games').objectStore('games');
- objectStore.get("*").onsuccess = function(event) {
+ get: function(gameId, callback) {
+ // Local game
+ dbOperation((err,db) => {
+ let objectStore = db.transaction("games").objectStore("games");
+ objectStore.get(gameId).onsuccess = function(event) {
+ // event.target.result is null if game not found