summaryrefslogtreecommitdiff
path: root/frontend/src/models/players.js
diff options
context:
space:
mode:
authorVictor Chabbert <chabbertvi@eisti.eu>2017-05-28 20:42:21 +0200
committerVictor Chabbert <chabbertvi@eisti.eu>2017-05-28 20:42:21 +0200
commit0bf423172ffb2e4030b521b0985d133cb5c61dd9 (patch)
tree0c24821770274a414f80b3092d5be54902c042d9 /frontend/src/models/players.js
parentFix proxy not working since CRA upgrade (diff)
downloadseven-wonders-0bf423172ffb2e4030b521b0985d133cb5c61dd9.tar.gz
seven-wonders-0bf423172ffb2e4030b521b0985d133cb5c61dd9.tar.bz2
seven-wonders-0bf423172ffb2e4030b521b0985d133cb5c61dd9.zip
Move to immutable with Records
Diffstat (limited to 'frontend/src/models/players.js')
-rw-r--r--frontend/src/models/players.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/frontend/src/models/players.js b/frontend/src/models/players.js
new file mode 100644
index 00000000..3df32c57
--- /dev/null
+++ b/frontend/src/models/players.js
@@ -0,0 +1,26 @@
+import { Record, Map } from 'immutable';
+
+const PlayerRecord = Record({
+ username: null,
+ displayName: null,
+ index: 0,
+ ready: false,
+});
+export class Player extends PlayerRecord {}
+
+const PlayersRecord = Record({
+ all: new Map(),
+ current: '',
+});
+export default class PlayerState extends PlayersRecord {
+ addPlayer(p) {
+ const player = new Player(p);
+ const playerMap = new Map({ [player.username]: player });
+ return this.addPlayers(playerMap).set('current', player.username);
+ }
+
+ addPlayers(p) {
+ const players = new Map(p);
+ return this.mergeIn(['all'], players.map(player => new Player(player)));
+ }
+}
bgstack15