summaryrefslogtreecommitdiff
path: root/frontend/src/models/players.js
diff options
context:
space:
mode:
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