Make the update function in session module an async construct that waits until the state of the game has been updated

This commit is contained in:
Tissevert 2018-12-02 19:48:59 +01:00
parent 938c4d9aaa
commit 0ec7c4d1ee

View file

@ -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() {