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) {
|
||||
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) {
|
||||
properties.onClick = answerDialog(game.vs.id);
|
||||
if(game.value.yourTurn) {
|
||||
properties.onClick = answerDialog(game.value.vs.id);
|
||||
properties.class = 'clickable';
|
||||
}
|
||||
return [Dom.make('span', properties)];
|
||||
}
|
||||
|
||||
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 [
|
||||
Dom.make('span', { textContent: status}),
|
||||
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
|
||||
})
|
||||
];
|
||||
|
|
|
@ -34,8 +34,8 @@ function initDOM() {
|
|||
|
||||
function showPlayer(player) {
|
||||
return Dom.make('li', {
|
||||
textContent: player.name,
|
||||
onClick: function() {form.root.them.value = player.name; refresh();},
|
||||
textContent: player.value,
|
||||
onClick: function() {form.root.them.value = player.value; refresh();},
|
||||
class: 'clickable'
|
||||
});
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ function refresh() {
|
|||
var name = form.root.them.value;
|
||||
them = null;
|
||||
var filtered = players.getAll(
|
||||
function(player) {return player.name.match(name);}
|
||||
function(player) {return player.value.match(name);}
|
||||
);
|
||||
list.refresh(filtered);
|
||||
var exact = filtered.find(exactMatch(name));
|
||||
|
@ -62,6 +62,6 @@ function refresh() {
|
|||
|
||||
function exactMatch(name) {
|
||||
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 Time;
|
||||
|
||||
var entries = Table.make(makeEntry, 'date');
|
||||
var entries = Table.make(function(o) {return o.value.date;});
|
||||
initMessageHandlers();
|
||||
|
||||
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() {
|
||||
Messaging.addEventListener(["Game"], function(o) {
|
||||
var gameID = o.state.public.gameState.gameID;
|
||||
|
|
11
js/Room.js
11
js/Room.js
|
@ -2,7 +2,7 @@ import Messaging;
|
|||
import Session;
|
||||
import Table;
|
||||
|
||||
var players = Table.make(player, 'name');
|
||||
var players = Table.make(function(o) {return o.value});
|
||||
initMessageHandlers();
|
||||
|
||||
return {
|
||||
|
@ -11,14 +11,7 @@ return {
|
|||
};
|
||||
|
||||
function opponent(key) {
|
||||
return {id: key, name: players.get(key).name};
|
||||
}
|
||||
|
||||
function player(key, name) {
|
||||
return {
|
||||
key: key,
|
||||
name: name
|
||||
};
|
||||
return {id: key, name: players.get(key)};
|
||||
}
|
||||
|
||||
function initMessageHandlers() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import of from UnitJS.Fun;
|
||||
import {compare, of, proj} from UnitJS.Fun;
|
||||
|
||||
function Table(itemMaker, sortCriterion) {
|
||||
function Table(sortCriterion) {
|
||||
var items = {};
|
||||
return {
|
||||
get: get,
|
||||
|
@ -17,13 +17,14 @@ function Table(itemMaker, sortCriterion) {
|
|||
|
||||
function getAll(criterion) {
|
||||
return Object.keys(items)
|
||||
.map(of(items))
|
||||
.map(function(key) {return {key: key, value: items[key]};})
|
||||
.filter(criterion || function() {return true;})
|
||||
.sort(compare(proj(sortCriterion)));
|
||||
.sort(compare(sortCriterion));
|
||||
}
|
||||
|
||||
|
||||
function insert(key, value) {
|
||||
items[key] = itemMaker(key, value);
|
||||
items[key] = value;
|
||||
}
|
||||
|
||||
function insertAll(newItems) {
|
||||
|
|
Loading…
Reference in a new issue