Skip to content

Commit

Permalink
Reduced emit calls
Browse files Browse the repository at this point in the history
  • Loading branch information
NotWoods committed Mar 19, 2017
1 parent d4f3151 commit 7f2d35c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,17 @@ function shouldPassThrough(node: StoryNode) {
return node.actions.some(action => action.message === PASS_THROUGH);
}

export function readStory(handler: Alexa.Handler) {
export function readStory(handler: Alexa.Handler, message = '') {
const story: StoryNode = handler.attributes.currentState;
if (!story) {
throw new Error('Invalid currentState!');
}

handler.emit(':tell', story.message);
message += story.message;

if (story.end_state) {
handler.emit(':tell', 'The game has ended');
message += 'The game has ended';
handler.emit(':tell', message);
return;
}

Expand All @@ -84,7 +85,8 @@ export function readStory(handler: Alexa.Handler) {
readStory(handler);
} else {
const askMessage = createActionsMessage(story.actions);
handler.emit(':ask', askMessage, askMessage);
message += askMessage;
handler.emit(':ask', message, askMessage);
}
}

Expand Down

0 comments on commit 7f2d35c

Please sign in to comment.