diff options
Diffstat (limited to 'src/store')
-rw-r--r-- | src/store/index.js | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/store/index.js b/src/store/index.js index 841fd17..a0a7791 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -6,16 +6,18 @@ class Store { this.subscribers = []; } - dispatch(action) { + dispatch(action, sender) { if (action instanceof Promise) { action.then((a) => { - this.transitNext(a); - }).catch(this.catcher) + this.transitNext(a, sender); + }).catch((e) => { + this.catcher(e, sender); + }); } else { try { - this.transitNext(action); + this.transitNext(action, sender); } catch (e) { - this.catcher(e); + this.catcher(e, sender); } } } @@ -28,11 +30,11 @@ class Store { this.subscribers.push(callback); } - transitNext(action) { + transitNext(action, sender) { let newState = this.reducer(this.state, action); if (JSON.stringify(this.state) !== JSON.stringify(newState)) { this.state = newState; - this.subscribers.forEach(f => f.call()) + this.subscribers.forEach(f => f(sender)); } } } |