aboutsummaryrefslogtreecommitdiff
path: root/src/store/index.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-09-16 22:24:27 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-09-16 22:24:27 +0900
commitbf75603e1514e64cd608fb90f4c47afeec5c37f9 (patch)
treefb353b51d4e855ada09fab2916f47738be77814e /src/store/index.js
parent27702ef40236ca055e63373b2ee81d399d124cca (diff)
propagate sender object
Diffstat (limited to 'src/store/index.js')
-rw-r--r--src/store/index.js16
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));
}
}
}