From 0ec7c4d1eedd33bb00153fbd88b3b09a0090d4c2 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Sun, 2 Dec 2018 19:48:59 +0100 Subject: [PATCH] Make the update function in session module an async construct that waits until the state of the game has been updated --- src/session.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/session.js b/src/session.js index 6b3ae24..58c6b5e 100644 --- a/src/session.js +++ b/src/session.js @@ -1,4 +1,4 @@ -function Session() { +function Session(async) { var game = JSON.parse(localStorage.getItem('game')); var options = JSON.parse(localStorage.getItem('options')) || defaultOptions(); @@ -6,15 +6,24 @@ function Session() { getOptions: getOptions, getGame: getGame, save: save, - setOptions: setOptions + setOptions: setOptions, + update: update }; function getGame() { return game; } - function update(state) { - game = state; + function update() { + return async.bind( + messaging.receive(function(message) { + return message.tag == "Game"; + }), + function(message) { + game = message.contents; + return async.wrap(); + } + ); } function save() {