From e629411c75894993ab4488057a48852e21206d8c Mon Sep 17 00:00:00 2001 From: kt Date: Mon, 17 Jul 2017 22:48:57 +0800 Subject: [PATCH 1/2] observe function takes an object with methods instead, so a check for args type is object and adding args to observers --- lib/state-machine.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/state-machine.js b/lib/state-machine.js index b8b9e37..17f9617 100644 --- a/lib/state-machine.js +++ b/lib/state-machine.js @@ -474,6 +474,9 @@ mixin(JSM.prototype, { observer[args[0]] = args[1]; this.observers.push(observer); } + else if (typeof args === "object") { + this.observers.push(args); + } else { this.observers.push(args[0]); } From 2b3bf0a980086aa1999353c48efd188468c02a68 Mon Sep 17 00:00:00 2001 From: kt Date: Mon, 17 Jul 2017 22:50:57 +0800 Subject: [PATCH 2/2] Add missing comma separators for example code for adding objects with method declaration as observer --- docs/lifecycle-events.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/lifecycle-events.md b/docs/lifecycle-events.md index bb3381b..7b470ab 100644 --- a/docs/lifecycle-events.md +++ b/docs/lifecycle-events.md @@ -36,8 +36,8 @@ Multiple events can be observed using an observer object: ```javascript fsm.observe({ - onStep: function() { console.log('stepped'); } - onA: function() { console.log('entered state A'); } + onStep: function() { console.log('stepped'); }, + onA: function() { console.log('entered state A'); }, onB: function() { console.log('entered state B'); } }); ``` @@ -51,8 +51,8 @@ A state machine always observes its own lifecycle events: { name: 'step', from: 'A', to: 'B' } ], methods: { - onStep: function() { console.log('stepped'); } - onA: function() { console.log('entered state A'); } + onStep: function() { console.log('stepped'); }, + onA: function() { console.log('entered state A'); }, onB: function() { console.log('entered state B'); } } });