Remove 'itemMaker' parameter to Table instanciator since it all amounts to copying all the object passed
This commit is contained in:
parent
4ea3b57e1d
commit
d308d35069
5 changed files with 17 additions and 32 deletions
|
@ -43,21 +43,21 @@ function showGame(game) {
|
||||||
|
|
||||||
function gameProposal(game) {
|
function gameProposal(game) {
|
||||||
var properties = {
|
var properties = {
|
||||||
textContent: I18n.get('proposedGame')(game.yourTurn, game.vs.name),
|
textContent: I18n.get('proposedGame')(game.value.yourTurn, game.value.vs.name),
|
||||||
};
|
};
|
||||||
if(game.yourTurn) {
|
if(game.value.yourTurn) {
|
||||||
properties.onClick = answerDialog(game.vs.id);
|
properties.onClick = answerDialog(game.value.vs.id);
|
||||||
properties.class = 'clickable';
|
properties.class = 'clickable';
|
||||||
}
|
}
|
||||||
return [Dom.make('span', properties)];
|
return [Dom.make('span', properties)];
|
||||||
}
|
}
|
||||||
|
|
||||||
function pendingGame(game) {
|
function pendingGame(game) {
|
||||||
var status = players.get(game.vs.id) != undefined ? 'active' : 'inactive'
|
var status = players.get(game.value.vs.id) != undefined ? 'active' : 'inactive'
|
||||||
return [
|
return [
|
||||||
Dom.make('span', { textContent: status}),
|
Dom.make('span', { textContent: status}),
|
||||||
Dom.make('a', {
|
Dom.make('a', {
|
||||||
textContent: I18n.get('pendingGame')(game.yourTurn, game.vs.name),
|
textContent: I18n.get('pendingGame')(game.value.yourTurn, game.value.vs.name),
|
||||||
href: '/game/' + game.key
|
href: '/game/' + game.key
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
|
@ -34,8 +34,8 @@ function initDOM() {
|
||||||
|
|
||||||
function showPlayer(player) {
|
function showPlayer(player) {
|
||||||
return Dom.make('li', {
|
return Dom.make('li', {
|
||||||
textContent: player.name,
|
textContent: player.value,
|
||||||
onClick: function() {form.root.them.value = player.name; refresh();},
|
onClick: function() {form.root.them.value = player.value; refresh();},
|
||||||
class: 'clickable'
|
class: 'clickable'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ function refresh() {
|
||||||
var name = form.root.them.value;
|
var name = form.root.them.value;
|
||||||
them = null;
|
them = null;
|
||||||
var filtered = players.getAll(
|
var filtered = players.getAll(
|
||||||
function(player) {return player.name.match(name);}
|
function(player) {return player.value.match(name);}
|
||||||
);
|
);
|
||||||
list.refresh(filtered);
|
list.refresh(filtered);
|
||||||
var exact = filtered.find(exactMatch(name));
|
var exact = filtered.find(exactMatch(name));
|
||||||
|
@ -62,6 +62,6 @@ function refresh() {
|
||||||
|
|
||||||
function exactMatch(name) {
|
function exactMatch(name) {
|
||||||
return function(player) {
|
return function(player) {
|
||||||
return player.name === name;
|
return player.value === name;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
11
js/Games.js
11
js/Games.js
|
@ -5,7 +5,7 @@ import Session;
|
||||||
import Table;
|
import Table;
|
||||||
import Time;
|
import Time;
|
||||||
|
|
||||||
var entries = Table.make(makeEntry, 'date');
|
var entries = Table.make(function(o) {return o.value.date;});
|
||||||
initMessageHandlers();
|
initMessageHandlers();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -20,15 +20,6 @@ function entry(state) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeEntry(key, config) {
|
|
||||||
return {
|
|
||||||
key: key,
|
|
||||||
vs: config.vs,
|
|
||||||
yourTurn: config.yourTurn,
|
|
||||||
date: config.date
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function initMessageHandlers() {
|
function initMessageHandlers() {
|
||||||
Messaging.addEventListener(["Game"], function(o) {
|
Messaging.addEventListener(["Game"], function(o) {
|
||||||
var gameID = o.state.public.gameState.gameID;
|
var gameID = o.state.public.gameState.gameID;
|
||||||
|
|
11
js/Room.js
11
js/Room.js
|
@ -2,7 +2,7 @@ import Messaging;
|
||||||
import Session;
|
import Session;
|
||||||
import Table;
|
import Table;
|
||||||
|
|
||||||
var players = Table.make(player, 'name');
|
var players = Table.make(function(o) {return o.value});
|
||||||
initMessageHandlers();
|
initMessageHandlers();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -11,14 +11,7 @@ return {
|
||||||
};
|
};
|
||||||
|
|
||||||
function opponent(key) {
|
function opponent(key) {
|
||||||
return {id: key, name: players.get(key).name};
|
return {id: key, name: players.get(key)};
|
||||||
}
|
|
||||||
|
|
||||||
function player(key, name) {
|
|
||||||
return {
|
|
||||||
key: key,
|
|
||||||
name: name
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function initMessageHandlers() {
|
function initMessageHandlers() {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import of from UnitJS.Fun;
|
import of from UnitJS.Fun;
|
||||||
import {compare, of, proj} from UnitJS.Fun;
|
import {compare, of, proj} from UnitJS.Fun;
|
||||||
|
|
||||||
function Table(itemMaker, sortCriterion) {
|
function Table(sortCriterion) {
|
||||||
var items = {};
|
var items = {};
|
||||||
return {
|
return {
|
||||||
get: get,
|
get: get,
|
||||||
|
@ -17,13 +17,14 @@ function Table(itemMaker, sortCriterion) {
|
||||||
|
|
||||||
function getAll(criterion) {
|
function getAll(criterion) {
|
||||||
return Object.keys(items)
|
return Object.keys(items)
|
||||||
.map(of(items))
|
.map(function(key) {return {key: key, value: items[key]};})
|
||||||
.filter(criterion || function() {return true;})
|
.filter(criterion || function() {return true;})
|
||||||
.sort(compare(proj(sortCriterion)));
|
.sort(compare(sortCriterion));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function insert(key, value) {
|
function insert(key, value) {
|
||||||
items[key] = itemMaker(key, value);
|
items[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertAll(newItems) {
|
function insertAll(newItems) {
|
||||||
|
|
Loading…
Reference in a new issue