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:
parent
938c4d9aaa
commit
0ec7c4d1ee
1 changed files with 13 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
||||||
function Session() {
|
function Session(async) {
|
||||||
var game = JSON.parse(localStorage.getItem('game'));
|
var game = JSON.parse(localStorage.getItem('game'));
|
||||||
var options = JSON.parse(localStorage.getItem('options')) || defaultOptions();
|
var options = JSON.parse(localStorage.getItem('options')) || defaultOptions();
|
||||||
|
|
||||||
|
@ -6,15 +6,24 @@ function Session() {
|
||||||
getOptions: getOptions,
|
getOptions: getOptions,
|
||||||
getGame: getGame,
|
getGame: getGame,
|
||||||
save: save,
|
save: save,
|
||||||
setOptions: setOptions
|
setOptions: setOptions,
|
||||||
|
update: update
|
||||||
};
|
};
|
||||||
|
|
||||||
function getGame() {
|
function getGame() {
|
||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
function update(state) {
|
function update() {
|
||||||
game = state;
|
return async.bind(
|
||||||
|
messaging.receive(function(message) {
|
||||||
|
return message.tag == "Game";
|
||||||
|
}),
|
||||||
|
function(message) {
|
||||||
|
game = message.contents;
|
||||||
|
return async.wrap();
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
|
|
Loading…
Reference in a new issue