aboutsummaryrefslogtreecommitdiff
path: root/src/store
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-10-08 15:19:25 +0900
committerGitHub <noreply@github.com>2017-10-08 15:19:25 +0900
commit0183161145d36cbafb7dbd86ca3a1aac6faca43f (patch)
treeaed757bfb5f8789156439d1e1fdff4e221376aaa /src/store
parent0f54a203dba38acdd080a928cee95f875fe84706 (diff)
parent57f798044d32ba7f9dc10a34ac31ad5dbdbf56ae (diff)
Merge pull request #22 from ueokande/separate-domains
Refactor: Separate domains
Diffstat (limited to 'src/store')
-rw-r--r--src/store/index.js53
1 files changed, 0 insertions, 53 deletions
diff --git a/src/store/index.js b/src/store/index.js
deleted file mode 100644
index 2fafdf1..0000000
--- a/src/store/index.js
+++ /dev/null
@@ -1,53 +0,0 @@
-class Store {
- constructor(reducer, catcher) {
- this.reducer = reducer;
- this.catcher = catcher;
- this.subscribers = [];
- try {
- this.state = this.reducer(undefined, {});
- } catch (e) {
- catcher(e);
- }
- }
-
- dispatch(action, sender) {
- if (action instanceof Promise) {
- action.then((a) => {
- this.transitNext(a, sender);
- }).catch((e) => {
- this.catcher(e, sender);
- });
- } else {
- try {
- this.transitNext(action, sender);
- } catch (e) {
- this.catcher(e, sender);
- }
- }
- return action;
- }
-
- getState() {
- return this.state;
- }
-
- subscribe(callback) {
- this.subscribers.push(callback);
- }
-
- 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(sender));
- }
- }
-}
-
-const empty = () => {};
-
-const createStore = (reducer, catcher = empty) => {
- return new Store(reducer, catcher);
-};
-
-export { createStore };