You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2017/08/28 08:14:31 UTC

[couchdb-fauxton] branch master updated: Replace Flux (#972)

This is an automated email from the ASF dual-hosted git repository.

garren pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb-fauxton.git


The following commit(s) were added to refs/heads/master by this push:
     new f317466  Replace Flux (#972)
f317466 is described below

commit f317466af33c7bbb659b42e47cdc07eb4a27e601
Author: garren smith <ga...@gmail.com>
AuthorDate: Mon Aug 28 10:14:28 2017 +0200

    Replace Flux (#972)
    
    We don't use use a lot of Flux's functionlity, so we can replace it with
    a simple function that calls all stores with any messages.
---
 app/core/api.js        | 18 +++++++++---------
 app/core/dispatcher.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 package.json           |  1 -
 3 files changed, 56 insertions(+), 10 deletions(-)

diff --git a/app/core/api.js b/app/core/api.js
index 20c9f0d..d176576 100644
--- a/app/core/api.js
+++ b/app/core/api.js
@@ -16,7 +16,7 @@ import RouteObject from "./routeObject";
 import utils from "./utils";
 import Store from "./store";
 import constants from "../constants";
-import Flux from "flux";
+import dispatcher from "./dispatcher";
 import $ from "jquery";
 import Backbone from "backbone";
 import _ from "lodash";
@@ -28,19 +28,19 @@ Backbone.ajax = function () {
   };
 
 Object.assign(FauxtonAPI, {
-  Router: Router,
-  RouteObject: RouteObject,
-  utils: utils,
-  Store: Store,
-  Events: _.extend({}, Backbone.Events),
-  dispatcher: new Flux.Dispatcher(),
-  Promise: Promise
+  Router,
+  RouteObject,
+  utils,
+  Store,
+  dispatcher,
+  Promise,
+  Events: _.extend({}, Backbone.Events)
 });
 
 // Pass along all constants
 FauxtonAPI.constants = constants;
 
-FauxtonAPI.dispatch = _.bind(FauxtonAPI.dispatcher.dispatch, FauxtonAPI.dispatcher);
+FauxtonAPI.dispatch = dispatcher.dispatch;
 
 FauxtonAPI.navigate = function (url, _opts) {
   var options = _.extend({trigger: true}, _opts);
diff --git a/app/core/dispatcher.js b/app/core/dispatcher.js
new file mode 100644
index 0000000..e5b853d
--- /dev/null
+++ b/app/core/dispatcher.js
@@ -0,0 +1,47 @@
+// Licensed under the Apache License, Version 2.0 (the 'License'); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+import {findIndex} from 'lodash';
+
+const stores = [];
+let dispatchId = 0;
+
+export const register = (store) => {
+  if (typeof store !== "function") {
+    throw new Error("Store dispatch method must be a function");
+  }
+
+  dispatchId += 1;
+  stores.push(store);
+  store.dispatchId = dispatchId;
+  return dispatchId;
+};
+
+export const dispatch = (msg) => {
+  stores.forEach(store => store(msg));
+};
+
+export const unregister = (id) => {
+  const storeIndex = findIndex(stores, store => store.dispatchId === id);
+
+  if (storeIndex === -1) {
+    return;
+  }
+
+  stores.splice(storeIndex, 1);
+};
+
+export default {
+  register,
+  dispatch,
+  unregister
+};
diff --git a/package.json b/package.json
index 0350369..786426b 100644
--- a/package.json
+++ b/package.json
@@ -65,7 +65,6 @@
     "express": "^4.14.1",
     "extract-text-webpack-plugin": "~2.1.0",
     "file-loader": "^0.10.0",
-    "flux": "^3.1.0",
     "fs-extra": "^2.0.0",
     "grunt": "~1.0.1",
     "grunt-cli": "~1.2.0",

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <co...@couchdb.apache.org>'].