couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [17/27] fauxton commit: updated refs/heads/master to 0ca35da
Date Tue, 31 May 2016 07:58:45 GMT
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/documents/index-editor/actions.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/index-editor/actions.js b/app/addons/documents/index-editor/actions.js
index 01e3cf6..48d1c21 100644
--- a/app/addons/documents/index-editor/actions.js
+++ b/app/addons/documents/index-editor/actions.js
@@ -10,291 +10,286 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-define([
-  '../../../app',
-  '../../../core/api',
-  '../resources',
-  './actiontypes',
-  '../index-results/actions',
-  '../sidebar/actions',
-  '../sidebar/actiontypes'
-],
-function (app, FauxtonAPI, Documents, ActionTypes, IndexResultsActions, SidebarActions, SidebarActionTypes) {
-
-
-  function selectReduceChanged (reduceOption) {
-    FauxtonAPI.dispatch({
-      type: ActionTypes.SELECT_REDUCE_CHANGE,
-      reduceSelectedOption: reduceOption
-    });
-  }
-
-  function changeViewName (name) {
-    FauxtonAPI.dispatch({
-      type: ActionTypes.VIEW_NAME_CHANGE,
-      name: name
-    });
-  }
-
-  function editIndex (options) {
-    FauxtonAPI.dispatch({
-      type: ActionTypes.EDIT_INDEX,
-      options: options
-    });
+import app from "../../../app";
+import FauxtonAPI from "../../../core/api";
+import Documents from "../resources";
+import ActionTypes from "./actiontypes";
+import IndexResultsActions from "../index-results/actions";
+import SidebarActions from "../sidebar/actions";
+import SidebarActionTypes from "../sidebar/actiontypes";
+
+
+function selectReduceChanged (reduceOption) {
+  FauxtonAPI.dispatch({
+    type: ActionTypes.SELECT_REDUCE_CHANGE,
+    reduceSelectedOption: reduceOption
+  });
+}
+
+function changeViewName (name) {
+  FauxtonAPI.dispatch({
+    type: ActionTypes.VIEW_NAME_CHANGE,
+    name: name
+  });
+}
+
+function editIndex (options) {
+  FauxtonAPI.dispatch({
+    type: ActionTypes.EDIT_INDEX,
+    options: options
+  });
+}
+
+function clearIndex () {
+  FauxtonAPI.dispatch({ type: ActionTypes.CLEAR_INDEX });
+}
+
+function fetchDesignDocsBeforeEdit (options) {
+  options.designDocs.fetch({reset: true}).then(function () {
+    this.editIndex(options);
+  }.bind(this));
+}
+
+function saveView (viewInfo) {
+  var designDoc = viewInfo.designDoc;
+  designDoc.setDdocView(viewInfo.viewName, viewInfo.map, viewInfo.reduce);
+
+  FauxtonAPI.addNotification({
+    msg: 'Saving View...',
+    type: 'info',
+    clear: true
+  });
+
+  // if the view name just changed and it's in the SAME design doc, remove the old one before saving the doc
+  if (viewInfo.originalDesignDocName === viewInfo.designDocId && viewInfo.originalViewName !== viewInfo.viewName) {
+    designDoc.removeDdocView(viewInfo.originalViewName);
   }
 
-  function clearIndex () {
-    FauxtonAPI.dispatch({ type: ActionTypes.CLEAR_INDEX });
-  }
-
-  function fetchDesignDocsBeforeEdit (options) {
-    options.designDocs.fetch({reset: true}).then(function () {
-      this.editIndex(options);
-    }.bind(this));
-  }
-
-  function saveView (viewInfo) {
-    var designDoc = viewInfo.designDoc;
-    designDoc.setDdocView(viewInfo.viewName, viewInfo.map, viewInfo.reduce);
-
+  designDoc.save().then(function () {
     FauxtonAPI.addNotification({
-      msg: 'Saving View...',
-      type: 'info',
+      msg: 'View Saved.',
+      type: 'success',
       clear: true
     });
 
-    // if the view name just changed and it's in the SAME design doc, remove the old one before saving the doc
-    if (viewInfo.originalDesignDocName === viewInfo.designDocId && viewInfo.originalViewName !== viewInfo.viewName) {
-      designDoc.removeDdocView(viewInfo.originalViewName);
-    }
-
-    designDoc.save().then(function () {
-      FauxtonAPI.addNotification({
-        msg: 'View Saved.',
-        type: 'success',
-        clear: true
+    // if the user just saved the view to a different design doc, remove the view from the old design doc and
+    // delete if it's empty
+    if (viewInfo.originalDesignDocName !== viewInfo.designDocId) {
+      var oldDesignDoc = findDesignDoc(viewInfo.designDocs, viewInfo.originalDesignDocName);
+      safeDeleteIndex(oldDesignDoc, viewInfo.designDocs, 'views', viewInfo.originalViewName, {
+        onSuccess: function () {
+          SidebarActions.updateDesignDocs(viewInfo.designDocs);
+        }
       });
+    }
 
-      // if the user just saved the view to a different design doc, remove the view from the old design doc and
-      // delete if it's empty
-      if (viewInfo.originalDesignDocName !== viewInfo.designDocId) {
-        var oldDesignDoc = findDesignDoc(viewInfo.designDocs, viewInfo.originalDesignDocName);
-        safeDeleteIndex(oldDesignDoc, viewInfo.designDocs, 'views', viewInfo.originalViewName, {
-          onSuccess: function () {
-            SidebarActions.updateDesignDocs(viewInfo.designDocs);
-          }
-        });
-      }
-
-      if (viewInfo.designDocId === 'new-doc') {
-        addDesignDoc(designDoc);
-      }
-
-      FauxtonAPI.dispatch({ type: ActionTypes.VIEW_SAVED });
-      var fragment = FauxtonAPI.urls('view', 'showView', viewInfo.database.safeID(), designDoc.safeID(), app.utils.safeURLName(viewInfo.viewName));
-      FauxtonAPI.navigate(fragment, { trigger: true });
-    });
-  }
-
-  function addDesignDoc (designDoc) {
-    FauxtonAPI.dispatch({
-      type: ActionTypes.VIEW_ADD_DESIGN_DOC,
-      designDoc: designDoc.toJSON()
-    });
-  }
-
-  function deleteView (options) {
-
-    function onSuccess () {
+    if (viewInfo.designDocId === 'new-doc') {
+      addDesignDoc(designDoc);
+    }
 
-      // if the user was on the index that was just deleted, redirect them back to all docs
-      if (options.isOnIndex) {
-        var url = FauxtonAPI.urls('allDocs', 'app', options.database.safeID(), '?limit=' + FauxtonAPI.constants.DATABASES.DOCUMENT_LIMIT);
-        FauxtonAPI.navigate(url);
-      }
+    FauxtonAPI.dispatch({ type: ActionTypes.VIEW_SAVED });
+    var fragment = FauxtonAPI.urls('view', 'showView', viewInfo.database.safeID(), designDoc.safeID(), app.utils.safeURLName(viewInfo.viewName));
+    FauxtonAPI.navigate(fragment, { trigger: true });
+  });
+}
 
-      SidebarActions.updateDesignDocs(options.designDocs);
+function addDesignDoc (designDoc) {
+  FauxtonAPI.dispatch({
+    type: ActionTypes.VIEW_ADD_DESIGN_DOC,
+    designDoc: designDoc.toJSON()
+  });
+}
 
-      FauxtonAPI.addNotification({
-        msg: 'The <code>' + _.escape(options.indexName) + '</code> view has been deleted.',
-        type: 'info',
-        escape: false,
-        clear: true
-      });
-      FauxtonAPI.dispatch({ type: SidebarActionTypes.SIDEBAR_HIDE_DELETE_INDEX_MODAL });
-    }
+function deleteView (options) {
 
-    safeDeleteIndex(options.designDoc, options.designDocs, 'views', options.indexName, { onSuccess: onSuccess });
-  }
+  function onSuccess () {
 
-  function cloneView (params) {
-    var targetDesignDoc = getDesignDoc(params.designDocs, params.targetDesignDocName, params.newDesignDocName, params.database);
-    var indexes = targetDesignDoc.get('views');
-    if (indexes && _.has(indexes, params.newIndexName)) {
-      FauxtonAPI.addNotification({
-        msg: 'That index name is already used in this design doc. Please enter a new name.',
-        type: 'error',
-        clear: true
-      });
-      return;
+    // if the user was on the index that was just deleted, redirect them back to all docs
+    if (options.isOnIndex) {
+      var url = FauxtonAPI.urls('allDocs', 'app', options.database.safeID(), '?limit=' + FauxtonAPI.constants.DATABASES.DOCUMENT_LIMIT);
+      FauxtonAPI.navigate(url);
     }
-    if (!indexes) {
-      indexes = {};
-    }
-    var sourceDesignDoc = findDesignDoc(params.designDocs, '_design/' + params.sourceDesignDocName);
-    var sourceDesignDocJSON = sourceDesignDoc.toJSON();
 
-    // this sets whatever content is in the source index into the target design doc under the new index name
-    indexes[params.newIndexName] = sourceDesignDocJSON.views[params.sourceIndexName];
-    targetDesignDoc.set({ views: indexes });
+    SidebarActions.updateDesignDocs(options.designDocs);
 
-    targetDesignDoc.save().then(function () {
-      params.onComplete();
-      FauxtonAPI.addNotification({
-        msg: 'The index has been cloned.',
-        type: 'success',
-        clear: true
-      });
-      SidebarActions.updateDesignDocs(params.designDocs);
-    },
-    function (xhr) {
-      params.onComplete();
-      var responseText = JSON.parse(xhr.responseText).reason;
-      FauxtonAPI.addNotification({
-        msg: 'Clone failed: ' + responseText,
-        type: 'error',
-        clear: true
-      });
+    FauxtonAPI.addNotification({
+      msg: 'The <code>' + _.escape(options.indexName) + '</code> view has been deleted.',
+      type: 'info',
+      escape: false,
+      clear: true
     });
+    FauxtonAPI.dispatch({ type: SidebarActionTypes.SIDEBAR_HIDE_DELETE_INDEX_MODAL });
   }
 
-  function gotoEditViewPage (databaseName, designDocName, indexName) {
-    FauxtonAPI.navigate('#' + FauxtonAPI.urls('view', 'edit', databaseName, designDocName, indexName));
-  }
+  safeDeleteIndex(options.designDoc, options.designDocs, 'views', options.indexName, { onSuccess: onSuccess });
+}
 
-  function updateMapCode (code) {
-    FauxtonAPI.dispatch({
-      type: ActionTypes.VIEW_UPDATE_MAP_CODE,
-      code: code
+function cloneView (params) {
+  var targetDesignDoc = getDesignDoc(params.designDocs, params.targetDesignDocName, params.newDesignDocName, params.database);
+  var indexes = targetDesignDoc.get('views');
+  if (indexes && _.has(indexes, params.newIndexName)) {
+    FauxtonAPI.addNotification({
+      msg: 'That index name is already used in this design doc. Please enter a new name.',
+      type: 'error',
+      clear: true
     });
+    return;
   }
-
-  function updateReduceCode (code) {
-    FauxtonAPI.dispatch({
-      type: ActionTypes.VIEW_UPDATE_REDUCE_CODE,
-      code: code
-    });
+  if (!indexes) {
+    indexes = {};
   }
+  var sourceDesignDoc = findDesignDoc(params.designDocs, '_design/' + params.sourceDesignDocName);
+  var sourceDesignDocJSON = sourceDesignDoc.toJSON();
 
-  function selectDesignDoc (designDoc) {
-    FauxtonAPI.dispatch({
-      type: ActionTypes.DESIGN_DOC_CHANGE,
-      options: {
-        value: designDoc
-      }
-    });
-  }
+  // this sets whatever content is in the source index into the target design doc under the new index name
+  indexes[params.newIndexName] = sourceDesignDocJSON.views[params.sourceIndexName];
+  targetDesignDoc.set({ views: indexes });
 
-  function updateNewDesignDocName (designDocName) {
-    FauxtonAPI.dispatch({
-      type: ActionTypes.DESIGN_DOC_NEW_NAME_UPDATED,
-      options: {
-        value: designDocName
-      }
+  targetDesignDoc.save().then(function () {
+    params.onComplete();
+    FauxtonAPI.addNotification({
+      msg: 'The index has been cloned.',
+      type: 'success',
+      clear: true
     });
-  }
-
-  // safely deletes an index of any type. It only deletes the actual design doc if there are no
-  // other indexes of any type left in the doc
-  function safeDeleteIndex (designDoc, designDocs, indexPropName, indexName, options) {
-    var opts = _.extend({
-      onSuccess: function () { },
-      onError: function (xhr) {
-        var responseText = JSON.parse(xhr.responseText).reason;
-        FauxtonAPI.addNotification({
-          msg: 'Delete failed: ' + responseText,
-          type: 'error',
-          clear: true
-        });
-      }
-    }, options);
-
-    var indexes = designDoc.get(indexPropName) || {};
-    delete indexes[indexName];
-    var newIndexes = {};
-    newIndexes[indexPropName] = indexes;
-    designDoc.set(newIndexes);
-
-    // we either save the design doc with the now-removed index, or we remove it altogether if there are no indexes
-    // of any type left in the design doc
-    var indexTypePropNames = FauxtonAPI.getIndexTypePropNames();
-    var hasRemainingIndex = _.some(indexTypePropNames, function (propName) {
-      return designDoc.get(propName) && _.keys(designDoc.get(propName)).length > 0;
+    SidebarActions.updateDesignDocs(params.designDocs);
+  },
+  function (xhr) {
+    params.onComplete();
+    var responseText = JSON.parse(xhr.responseText).reason;
+    FauxtonAPI.addNotification({
+      msg: 'Clone failed: ' + responseText,
+      type: 'error',
+      clear: true
     });
-
-    var promise;
-    var deleteDesignDoc = false;
-    if (hasRemainingIndex) {
-      promise = designDoc.save();
-    } else {
-      promise = designDoc.destroy();
-      deleteDesignDoc = true;
+  });
+}
+
+function gotoEditViewPage (databaseName, designDocName, indexName) {
+  FauxtonAPI.navigate('#' + FauxtonAPI.urls('view', 'edit', databaseName, designDocName, indexName));
+}
+
+function updateMapCode (code) {
+  FauxtonAPI.dispatch({
+    type: ActionTypes.VIEW_UPDATE_MAP_CODE,
+    code: code
+  });
+}
+
+function updateReduceCode (code) {
+  FauxtonAPI.dispatch({
+    type: ActionTypes.VIEW_UPDATE_REDUCE_CODE,
+    code: code
+  });
+}
+
+function selectDesignDoc (designDoc) {
+  FauxtonAPI.dispatch({
+    type: ActionTypes.DESIGN_DOC_CHANGE,
+    options: {
+      value: designDoc
+    }
+  });
+}
+
+function updateNewDesignDocName (designDocName) {
+  FauxtonAPI.dispatch({
+    type: ActionTypes.DESIGN_DOC_NEW_NAME_UPDATED,
+    options: {
+      value: designDocName
+    }
+  });
+}
+
+// safely deletes an index of any type. It only deletes the actual design doc if there are no
+// other indexes of any type left in the doc
+function safeDeleteIndex (designDoc, designDocs, indexPropName, indexName, options) {
+  var opts = _.extend({
+    onSuccess: function () { },
+    onError: function (xhr) {
+      var responseText = JSON.parse(xhr.responseText).reason;
+      FauxtonAPI.addNotification({
+        msg: 'Delete failed: ' + responseText,
+        type: 'error',
+        clear: true
+      });
     }
-    promise.then(function () {
-      if (deleteDesignDoc) {
-        designDocs.remove(designDoc.id);
-      }
-      opts.onSuccess();
-    }, opts.onError);
+  }, options);
+
+  var indexes = designDoc.get(indexPropName) || {};
+  delete indexes[indexName];
+  var newIndexes = {};
+  newIndexes[indexPropName] = indexes;
+  designDoc.set(newIndexes);
+
+  // we either save the design doc with the now-removed index, or we remove it altogether if there are no indexes
+  // of any type left in the design doc
+  var indexTypePropNames = FauxtonAPI.getIndexTypePropNames();
+  var hasRemainingIndex = _.some(indexTypePropNames, function (propName) {
+    return designDoc.get(propName) && _.keys(designDoc.get(propName)).length > 0;
+  });
+
+  var promise;
+  var deleteDesignDoc = false;
+  if (hasRemainingIndex) {
+    promise = designDoc.save();
+  } else {
+    promise = designDoc.destroy();
+    deleteDesignDoc = true;
   }
+  promise.then(function () {
+    if (deleteDesignDoc) {
+      designDocs.remove(designDoc.id);
+    }
+    opts.onSuccess();
+  }, opts.onError);
+}
 
 
 
-  // ---- helpers ----
+// ---- helpers ----
 
-  function findDesignDoc (designDocs, designDocName) {
-    return designDocs.find(function (doc) {
-      return doc.id === designDocName;
-    }).dDocModel();
-  }
+function findDesignDoc (designDocs, designDocName) {
+  return designDocs.find(function (doc) {
+    return doc.id === designDocName;
+  }).dDocModel();
+}
 
-  function getDesignDoc (designDocs, targetDesignDocName, newDesignDocName, database) {
-    if (targetDesignDocName === 'new-doc') {
-      var doc = {
-        "_id": "_design/" + newDesignDocName,
-        "views": {},
-        "language": "javascript"
-      };
-      return new Documents.Doc(doc, { database: database });
-    }
-
-    var foundDoc = designDocs.find(function (ddoc) {
-      return ddoc.id === targetDesignDocName;
-    });
-    return (!foundDoc) ? null : foundDoc.dDocModel();
+function getDesignDoc (designDocs, targetDesignDocName, newDesignDocName, database) {
+  if (targetDesignDocName === 'new-doc') {
+    var doc = {
+      "_id": "_design/" + newDesignDocName,
+      "views": {},
+      "language": "javascript"
+    };
+    return new Documents.Doc(doc, { database: database });
   }
 
-
-  return {
-    helpers: {
-      findDesignDoc: findDesignDoc,
-      getDesignDoc: getDesignDoc
-    },
-    safeDeleteIndex: safeDeleteIndex,
-    selectReduceChanged: selectReduceChanged,
-    changeViewName: changeViewName,
-    editIndex: editIndex,
-    clearIndex: clearIndex,
-    fetchDesignDocsBeforeEdit: fetchDesignDocsBeforeEdit,
-    saveView: saveView,
-    addDesignDoc: addDesignDoc,
-    deleteView: deleteView,
-    cloneView: cloneView,
-    gotoEditViewPage: gotoEditViewPage,
-    updateMapCode: updateMapCode,
-    updateReduceCode: updateReduceCode,
-    selectDesignDoc: selectDesignDoc,
-    updateNewDesignDocName: updateNewDesignDocName
-  };
-
-});
+  var foundDoc = designDocs.find(function (ddoc) {
+    return ddoc.id === targetDesignDocName;
+  });
+  return (!foundDoc) ? null : foundDoc.dDocModel();
+}
+
+
+export default {
+  helpers: {
+    findDesignDoc: findDesignDoc,
+    getDesignDoc: getDesignDoc
+  },
+  safeDeleteIndex: safeDeleteIndex,
+  selectReduceChanged: selectReduceChanged,
+  changeViewName: changeViewName,
+  editIndex: editIndex,
+  clearIndex: clearIndex,
+  fetchDesignDocsBeforeEdit: fetchDesignDocsBeforeEdit,
+  saveView: saveView,
+  addDesignDoc: addDesignDoc,
+  deleteView: deleteView,
+  cloneView: cloneView,
+  gotoEditViewPage: gotoEditViewPage,
+  updateMapCode: updateMapCode,
+  updateReduceCode: updateReduceCode,
+  selectDesignDoc: selectDesignDoc,
+  updateNewDesignDocName: updateNewDesignDocName
+};

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/documents/index-editor/actiontypes.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/index-editor/actiontypes.js b/app/addons/documents/index-editor/actiontypes.js
index d4c1fa1..920bd9f 100644
--- a/app/addons/documents/index-editor/actiontypes.js
+++ b/app/addons/documents/index-editor/actiontypes.js
@@ -10,20 +10,18 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-define([], function () {
-  return {
-    CLEAR_INDEX: 'CLEAR_INDEX',
-    EDIT_INDEX: 'EDIT_INDEX',
-    EDIT_NEW_INDEX: 'EDIT_NEW_INDEX',
-    SELECT_REDUCE_CHANGE: 'SELECT_REDUCE_CHANGE',
-    VIEW_SAVED: 'VIEW_SAVED',
-    VIEW_CREATED: 'VIEW_CREATED',
-    DESIGN_DOC_CHANGE: 'DESIGN_DOC_CHANGE',
-    DESIGN_DOC_NEW_NAME_UPDATED: 'DESIGN_DOC_NEW_NAME_UPDATED',
-    NEW_DESIGN_DOC: 'NEW_DESIGN_DOC',
-    VIEW_NAME_CHANGE: 'VIEW_NAME_CHANGE',
-    VIEW_ADD_DESIGN_DOC: 'VIEW_ADD_DESIGN_DOC',
-    VIEW_UPDATE_MAP_CODE: 'VIEW_UPDATE_MAP_CODE',
-    VIEW_UPDATE_REDUCE_CODE: 'VIEW_UPDATE_REDUCE_CODE'
-  };
-});
+export default {
+  CLEAR_INDEX: 'CLEAR_INDEX',
+  EDIT_INDEX: 'EDIT_INDEX',
+  EDIT_NEW_INDEX: 'EDIT_NEW_INDEX',
+  SELECT_REDUCE_CHANGE: 'SELECT_REDUCE_CHANGE',
+  VIEW_SAVED: 'VIEW_SAVED',
+  VIEW_CREATED: 'VIEW_CREATED',
+  DESIGN_DOC_CHANGE: 'DESIGN_DOC_CHANGE',
+  DESIGN_DOC_NEW_NAME_UPDATED: 'DESIGN_DOC_NEW_NAME_UPDATED',
+  NEW_DESIGN_DOC: 'NEW_DESIGN_DOC',
+  VIEW_NAME_CHANGE: 'VIEW_NAME_CHANGE',
+  VIEW_ADD_DESIGN_DOC: 'VIEW_ADD_DESIGN_DOC',
+  VIEW_UPDATE_MAP_CODE: 'VIEW_UPDATE_MAP_CODE',
+  VIEW_UPDATE_REDUCE_CODE: 'VIEW_UPDATE_REDUCE_CODE'
+};

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/documents/index-editor/components.react.jsx
----------------------------------------------------------------------
diff --git a/app/addons/documents/index-editor/components.react.jsx b/app/addons/documents/index-editor/components.react.jsx
index dba5fb8..ff01e3a 100644
--- a/app/addons/documents/index-editor/components.react.jsx
+++ b/app/addons/documents/index-editor/components.react.jsx
@@ -10,390 +10,384 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-define([
-  '../../../app',
-  '../../../core/api',
-  'react',
-  'react-dom',
-  './stores',
-  './actions',
-  '../../fauxton/components',
-  '../../components/react-components.react'
-],
-
-function (app, FauxtonAPI, React, ReactDOM, Stores, Actions, Components, ReactComponents) {
-
-  var store = Stores.indexEditorStore;
-  var getDocUrl = app.helpers.getDocUrl;
-  var StyledSelect = ReactComponents.StyledSelect;
-  var CodeEditorPanel = ReactComponents.CodeEditorPanel;
-  var ConfirmButton = ReactComponents.ConfirmButton;
-  var LoadLines = ReactComponents.LoadLines;
-
-
-  var DesignDocSelector = React.createClass({
-    propTypes: {
-      designDocList: React.PropTypes.array.isRequired,
-      onSelectDesignDoc: React.PropTypes.func.isRequired,
-      onChangeNewDesignDocName: React.PropTypes.func.isRequired,
-      selectedDesignDocName: React.PropTypes.string.isRequired,
-      newDesignDocName: React.PropTypes.string.isRequired,
-      designDocLabel: React.PropTypes.string,
-      docURL: React.PropTypes.string
-    },
-
-    getDefaultProps: function () {
-      return {
-        designDocLabel: 'Design Document'
-      };
-    },
-
-    validate: function () {
-      if (this.props.selectedDesignDocName === 'new-doc' && this.props.newDesignDocName === '') {
-        FauxtonAPI.addNotification({
-          msg: 'Please name your design doc.',
-          type: 'error'
-        });
-        ReactDOM.findDOMNode(this.refs.newDesignDoc).focus();
-        return false;
-      }
-      return true;
-    },
-
-    getDocList: function () {
-      return _.map(this.props.designDocList, function (designDoc) {
-        return (<option key={designDoc} value={designDoc}>{designDoc}</option>);
+import app from "../../../app";
+import FauxtonAPI from "../../../core/api";
+import React from "react";
+import ReactDOM from "react-dom";
+import Stores from "./stores";
+import Actions from "./actions";
+import Components from "../../fauxton/components";
+import ReactComponents from "../../components/react-components.react";
+
+var store = Stores.indexEditorStore;
+var getDocUrl = app.helpers.getDocUrl;
+var StyledSelect = ReactComponents.StyledSelect;
+var CodeEditorPanel = ReactComponents.CodeEditorPanel;
+var ConfirmButton = ReactComponents.ConfirmButton;
+var LoadLines = ReactComponents.LoadLines;
+
+
+var DesignDocSelector = React.createClass({
+  propTypes: {
+    designDocList: React.PropTypes.array.isRequired,
+    onSelectDesignDoc: React.PropTypes.func.isRequired,
+    onChangeNewDesignDocName: React.PropTypes.func.isRequired,
+    selectedDesignDocName: React.PropTypes.string.isRequired,
+    newDesignDocName: React.PropTypes.string.isRequired,
+    designDocLabel: React.PropTypes.string,
+    docURL: React.PropTypes.string
+  },
+
+  getDefaultProps: function () {
+    return {
+      designDocLabel: 'Design Document'
+    };
+  },
+
+  validate: function () {
+    if (this.props.selectedDesignDocName === 'new-doc' && this.props.newDesignDocName === '') {
+      FauxtonAPI.addNotification({
+        msg: 'Please name your design doc.',
+        type: 'error'
       });
-    },
-
-    selectDesignDoc: function (e) {
-      this.props.onSelectDesignDoc(e.target.value);
-    },
-
-    updateDesignDocName: function (e) {
-      this.props.onChangeNewDesignDocName(e.target.value);
-    },
-
-    getNewDDocField: function () {
-      if (this.props.selectedDesignDocName !== 'new-doc') {
-        return;
-      }
-      return (
-        <div id="new-ddoc-section" className="span5">
-          <label className="control-label" htmlFor="new-ddoc">_design/</label>
-          <div className="controls">
-            <input type="text" ref="newDesignDoc" id="new-ddoc" placeholder="newDesignDoc"
-               onChange={this.updateDesignDocName}/>
-          </div>
+      ReactDOM.findDOMNode(this.refs.newDesignDoc).focus();
+      return false;
+    }
+    return true;
+  },
+
+  getDocList: function () {
+    return _.map(this.props.designDocList, function (designDoc) {
+      return (<option key={designDoc} value={designDoc}>{designDoc}</option>);
+    });
+  },
+
+  selectDesignDoc: function (e) {
+    this.props.onSelectDesignDoc(e.target.value);
+  },
+
+  updateDesignDocName: function (e) {
+    this.props.onChangeNewDesignDocName(e.target.value);
+  },
+
+  getNewDDocField: function () {
+    if (this.props.selectedDesignDocName !== 'new-doc') {
+      return;
+    }
+    return (
+      <div id="new-ddoc-section" className="span5">
+        <label className="control-label" htmlFor="new-ddoc">_design/</label>
+        <div className="controls">
+          <input type="text" ref="newDesignDoc" id="new-ddoc" placeholder="newDesignDoc"
+             onChange={this.updateDesignDocName}/>
         </div>
-      );
-    },
-
-    getDocLink: function () {
-      if (!this.props.docLink) {
-        return null;
-      }
-      return (
-        <a className="help-link" data-bypass="true" href={this.props.docLink} target="_blank">
-          <i className="icon-question-sign" />
-        </a>
-      );
-    },
+      </div>
+    );
+  },
 
-    render: function () {
-      return (
-        <div className="design-doc-group control-group">
-          <div className="span3">
-            <label htmlFor="ddoc">{this.props.designDocLabel}
-              {this.getDocLink()}
+  getDocLink: function () {
+    if (!this.props.docLink) {
+      return null;
+    }
+    return (
+      <a className="help-link" data-bypass="true" href={this.props.docLink} target="_blank">
+        <i className="icon-question-sign" />
+      </a>
+    );
+  },
+
+  render: function () {
+    return (
+      <div className="design-doc-group control-group">
+        <div className="span3">
+          <label htmlFor="ddoc">{this.props.designDocLabel}
+            {this.getDocLink()}
+          </label>
+          <div className="styled-select">
+            <label htmlFor="js-backup-list-select">
+              <i className="fonticon-down-dir" />
+              <select id="ddoc" onChange={this.selectDesignDoc} value={this.props.selectedDesignDocName}>
+                <optgroup label="Select a document">
+                  <option value="new-doc">New document</option>
+                  {this.getDocList()}
+                </optgroup>
+              </select>
             </label>
-            <div className="styled-select">
-              <label htmlFor="js-backup-list-select">
-                <i className="fonticon-down-dir" />
-                <select id="ddoc" onChange={this.selectDesignDoc} value={this.props.selectedDesignDocName}>
-                  <optgroup label="Select a document">
-                    <option value="new-doc">New document</option>
-                    {this.getDocList()}
-                  </optgroup>
-                </select>
-              </label>
-            </div>
           </div>
-          {this.getNewDDocField()}
         </div>
-      );
+        {this.getNewDDocField()}
+      </div>
+    );
+  }
+});
+
+
+var ReduceEditor = React.createClass({
+
+  getStoreState: function () {
+    return {
+      reduce: store.getReduce(),
+      reduceOptions: store.reduceOptions(),
+      reduceSelectedOption: store.reduceSelectedOption(),
+      hasCustomReduce: store.hasCustomReduce(),
+      hasReduce: store.hasReduce()
+    };
+  },
+
+  getInitialState: function () {
+    return this.getStoreState();
+  },
+
+  getOptionsList: function () {
+    return _.map(this.state.reduceOptions, function (reduce, i) {
+      return <option key={i} value={reduce}>{reduce}</option>;
+    }, this);
+  },
+
+  getReduceValue: function () {
+    if (!this.state.hasReduce) {
+      return null;
     }
-  });
-
-
-  var ReduceEditor = React.createClass({
-
-    getStoreState: function () {
-      return {
-        reduce: store.getReduce(),
-        reduceOptions: store.reduceOptions(),
-        reduceSelectedOption: store.reduceSelectedOption(),
-        hasCustomReduce: store.hasCustomReduce(),
-        hasReduce: store.hasReduce()
-      };
-    },
-
-    getInitialState: function () {
-      return this.getStoreState();
-    },
-
-    getOptionsList: function () {
-      return _.map(this.state.reduceOptions, function (reduce, i) {
-        return <option key={i} value={reduce}>{reduce}</option>;
-      }, this);
-    },
-
-    getReduceValue: function () {
-      if (!this.state.hasReduce) {
-        return null;
-      }
-
-      if (!this.state.hasCustomReduce) {
-        return this.state.reduce;
-      }
-
-      return this.refs.reduceEditor.getValue();
-    },
-
-    getEditor: function () {
-      return this.refs.reduceEditor.getEditor();
-    },
-
-    render: function () {
-      var reduceOptions = this.getOptionsList(),
-          customReduceSection;
-
-      if (this.state.hasCustomReduce) {
-        customReduceSection = <CodeEditorPanel
-          ref='reduceEditor'
-          id='reduce-function'
-          title={'Custom Reduce function'}
-          defaultCode={this.state.reduce}
-          allowZenMode={false}
-          blur={this.updateReduceCode}
-        />;
-      }
 
-      return (
-        <div>
-          <div className="control-group">
-            <label htmlFor="reduce-function-selector">
-              <span>Reduce (optional)</span>
-              <a
-                className="help-link"
-                data-bypass="true"
-                href={getDocUrl('REDUCE_FUNCS')}
-                target="_blank"
-              >
-                <i className="icon-question-sign"></i>
-              </a>
-            </label>
-            <StyledSelect
-              selectContent={reduceOptions}
-              selectChange={this.selectChange}
-              selectId="reduce-function-selector"
-              selectValue={this.state.reduceSelectedOption} />
-          </div>
+    if (!this.state.hasCustomReduce) {
+      return this.state.reduce;
+    }
+
+    return this.refs.reduceEditor.getValue();
+  },
+
+  getEditor: function () {
+    return this.refs.reduceEditor.getEditor();
+  },
+
+  render: function () {
+    var reduceOptions = this.getOptionsList(),
+        customReduceSection;
+
+    if (this.state.hasCustomReduce) {
+      customReduceSection = <CodeEditorPanel
+        ref='reduceEditor'
+        id='reduce-function'
+        title={'Custom Reduce function'}
+        defaultCode={this.state.reduce}
+        allowZenMode={false}
+        blur={this.updateReduceCode}
+      />;
+    }
 
-          {customReduceSection}
+    return (
+      <div>
+        <div className="control-group">
+          <label htmlFor="reduce-function-selector">
+            <span>Reduce (optional)</span>
+            <a
+              className="help-link"
+              data-bypass="true"
+              href={getDocUrl('REDUCE_FUNCS')}
+              target="_blank"
+            >
+              <i className="icon-question-sign"></i>
+            </a>
+          </label>
+          <StyledSelect
+            selectContent={reduceOptions}
+            selectChange={this.selectChange}
+            selectId="reduce-function-selector"
+            selectValue={this.state.reduceSelectedOption} />
         </div>
-      );
-    },
 
-    updateReduceCode: function (code) {
-      Actions.updateReduceCode(code);
-    },
+        {customReduceSection}
+      </div>
+    );
+  },
 
-    selectChange: function (event) {
-      Actions.selectReduceChanged(event.target.value);
-    },
+  updateReduceCode: function (code) {
+    Actions.updateReduceCode(code);
+  },
 
-    onChange: function () {
-      if (this.isMounted()) {
-        this.setState(this.getStoreState());
-      }
-    },
+  selectChange: function (event) {
+    Actions.selectReduceChanged(event.target.value);
+  },
+
+  onChange: function () {
+    if (this.isMounted()) {
+      this.setState(this.getStoreState());
+    }
+  },
+
+  componentDidMount: function () {
+    store.on('change', this.onChange, this);
+  },
+
+  componentWillUnmount: function () {
+    store.off('change', this.onChange);
+  }
+});
 
-    componentDidMount: function () {
-      store.on('change', this.onChange, this);
-    },
 
-    componentWillUnmount: function () {
-      store.off('change', this.onChange);
+var EditorController = React.createClass({
+
+  getStoreState: function () {
+    return {
+      database: store.getDatabase(),
+      isNewView: store.isNewView(),
+      viewName: store.getViewName(),
+      designDocs: store.getDesignDocs(),
+      designDocList: store.getAvailableDesignDocs(),
+      originalViewName: store.getOriginalViewName(),
+      originalDesignDocName: store.getOriginalDesignDocName(),
+      newDesignDoc: store.isNewDesignDoc(),
+      designDocId: store.getDesignDocId(),
+      newDesignDocName: store.getNewDesignDocName(),
+      saveDesignDoc: store.getSaveDesignDoc(),
+      map: store.getMap(),
+      isLoading: store.isLoading()
+    };
+  },
+
+  getInitialState: function () {
+    return this.getStoreState();
+  },
+
+  onChange: function () {
+    if (this.isMounted()) {
+      this.setState(this.getStoreState());
     }
-  });
-
-
-  var EditorController = React.createClass({
-
-    getStoreState: function () {
-      return {
-        database: store.getDatabase(),
-        isNewView: store.isNewView(),
-        viewName: store.getViewName(),
-        designDocs: store.getDesignDocs(),
-        designDocList: store.getAvailableDesignDocs(),
-        originalViewName: store.getOriginalViewName(),
-        originalDesignDocName: store.getOriginalDesignDocName(),
-        newDesignDoc: store.isNewDesignDoc(),
-        designDocId: store.getDesignDocId(),
-        newDesignDocName: store.getNewDesignDocName(),
-        saveDesignDoc: store.getSaveDesignDoc(),
-        map: store.getMap(),
-        isLoading: store.isLoading()
-      };
-    },
-
-    getInitialState: function () {
-      return this.getStoreState();
-    },
-
-    onChange: function () {
-      if (this.isMounted()) {
-        this.setState(this.getStoreState());
-      }
-    },
-
-    componentDidMount: function () {
-      store.on('change', this.onChange, this);
-    },
-
-    componentWillUnmount: function () {
-      store.off('change', this.onChange);
-    },
-
-    // the code editor is a standalone component, so if the user goes from one edit view page to another, we need to
-    // force an update of the editor panel
-    componentDidUpdate: function (prevProps, prevState) {
-      if (this.state.map !== prevState.map && this.refs.mapEditor) {
-        this.refs.mapEditor.update();
-      }
-    },
-
-    hasErrors: function () {
-      var mapEditorErrors = this.refs.mapEditor.getEditor().hasErrors();
-      var customReduceErrors = (store.hasCustomReduce()) ? this.refs.reduceEditor.getEditor().hasErrors() : false;
-      return mapEditorErrors || customReduceErrors;
-    },
-
-    saveView: function (e) {
-      e.preventDefault();
-
-      if (!this.refs.designDocSelector.validate()) {
-        return;
-      }
-
-      if (this.hasErrors()) {
-        FauxtonAPI.addNotification({
-          msg: 'Please fix the Javascript errors and try again.',
-          type: 'error',
-          clear: true
-        });
-        return;
-      }
-
-      Actions.saveView({
-        database: this.state.database,
-        newView: this.state.isNewView,
-        viewName: this.state.viewName,
-        designDoc: this.state.saveDesignDoc,
-        designDocId: this.state.designDocId,
-        newDesignDoc: this.state.newDesignDoc,
-        originalViewName: this.state.originalViewName,
-        originalDesignDocName: this.state.originalDesignDocName,
-        map: this.refs.mapEditor.getValue(),
-        reduce: this.refs.reduceEditor.getReduceValue(),
-        designDocs: this.state.designDocs
-      });
-    },
+  },
 
-    viewChange: function (e) {
-      Actions.changeViewName(e.target.value);
-    },
+  componentDidMount: function () {
+    store.on('change', this.onChange, this);
+  },
 
-    updateMapCode: function (code) {
-      Actions.updateMapCode(code);
-    },
+  componentWillUnmount: function () {
+    store.off('change', this.onChange);
+  },
 
-    render: function () {
-      if (this.state.isLoading) {
-        return (
-          <div className="define-view">
-            <LoadLines />
-          </div>
-        );
-      }
+  // the code editor is a standalone component, so if the user goes from one edit view page to another, we need to
+  // force an update of the editor panel
+  componentDidUpdate: function (prevProps, prevState) {
+    if (this.state.map !== prevState.map && this.refs.mapEditor) {
+      this.refs.mapEditor.update();
+    }
+  },
+
+  hasErrors: function () {
+    var mapEditorErrors = this.refs.mapEditor.getEditor().hasErrors();
+    var customReduceErrors = (store.hasCustomReduce()) ? this.refs.reduceEditor.getEditor().hasErrors() : false;
+    return mapEditorErrors || customReduceErrors;
+  },
 
-      var pageHeader = (this.state.isNewView) ? 'New View' : 'Edit View';
-      var btnLabel = (this.state.isNewView) ? 'Create Document and Build Index' : 'Save Document and Build Index';
+  saveView: function (e) {
+    e.preventDefault();
 
-      var cancelLink = '#' + FauxtonAPI.urls('view', 'showView', this.state.database.id, this.state.designDocId, this.state.viewName);
+    if (!this.refs.designDocSelector.validate()) {
+      return;
+    }
+
+    if (this.hasErrors()) {
+      FauxtonAPI.addNotification({
+        msg: 'Please fix the Javascript errors and try again.',
+        type: 'error',
+        clear: true
+      });
+      return;
+    }
+
+    Actions.saveView({
+      database: this.state.database,
+      newView: this.state.isNewView,
+      viewName: this.state.viewName,
+      designDoc: this.state.saveDesignDoc,
+      designDocId: this.state.designDocId,
+      newDesignDoc: this.state.newDesignDoc,
+      originalViewName: this.state.originalViewName,
+      originalDesignDocName: this.state.originalDesignDocName,
+      map: this.refs.mapEditor.getValue(),
+      reduce: this.refs.reduceEditor.getReduceValue(),
+      designDocs: this.state.designDocs
+    });
+  },
+
+  viewChange: function (e) {
+    Actions.changeViewName(e.target.value);
+  },
+
+  updateMapCode: function (code) {
+    Actions.updateMapCode(code);
+  },
+
+  render: function () {
+    if (this.state.isLoading) {
       return (
         <div className="define-view">
-          <form className="form-horizontal view-query-save" onSubmit={this.saveView}>
-            <h3 className="simple-header">{pageHeader}</h3>
-
-            <div className="new-ddoc-section">
-              <DesignDocSelector
-                ref="designDocSelector"
-                designDocList={this.state.designDocList}
-                selectedDesignDocName={this.state.designDocId}
-                newDesignDocName={this.state.newDesignDocName}
-                onSelectDesignDoc={Actions.selectDesignDoc}
-                onChangeNewDesignDocName={Actions.updateNewDesignDocName}
-                docLink={getDocUrl('DESIGN_DOCS')} />
-            </div>
-
-            <div className="control-group">
-              <label htmlFor="index-name">
-                <span>Index name</span>
-                <a
-                  className="help-link"
-                  data-bypass="true"
-                  href={getDocUrl('VIEW_FUNCS')}
-                  target="_blank">
-                  <i className="icon-question-sign"></i>
-                </a>
-              </label>
-              <input
-                type="text"
-                id="index-name"
-                value={this.state.viewName}
-                onChange={this.viewChange}
-                placeholder="Index name" />
-            </div>
-            <CodeEditorPanel
-              id={'map-function'}
-              ref="mapEditor"
-              title={"Map function"}
-              docLink={getDocUrl('MAP_FUNCS')}
-              blur={this.updateMapCode}
-              allowZenMode={false}
-              defaultCode={this.state.map} />
-            <ReduceEditor ref="reduceEditor" />
-            <div className="padded-box">
-              <div className="control-group">
-                <ConfirmButton id="save-view" text={btnLabel} />
-                <a href={cancelLink} className="index-cancel-link">Cancel</a>
-              </div>
-            </div>
-          </form>
+          <LoadLines />
         </div>
       );
     }
-  });
-
 
-  return {
-    EditorController: EditorController,
-    ReduceEditor: ReduceEditor,
-    DesignDocSelector: DesignDocSelector,
-    StyledSelect: StyledSelect
-  };
+    var pageHeader = (this.state.isNewView) ? 'New View' : 'Edit View';
+    var btnLabel = (this.state.isNewView) ? 'Create Document and Build Index' : 'Save Document and Build Index';
+
+    var cancelLink = '#' + FauxtonAPI.urls('view', 'showView', this.state.database.id, this.state.designDocId, this.state.viewName);
+    return (
+      <div className="define-view">
+        <form className="form-horizontal view-query-save" onSubmit={this.saveView}>
+          <h3 className="simple-header">{pageHeader}</h3>
+
+          <div className="new-ddoc-section">
+            <DesignDocSelector
+              ref="designDocSelector"
+              designDocList={this.state.designDocList}
+              selectedDesignDocName={this.state.designDocId}
+              newDesignDocName={this.state.newDesignDocName}
+              onSelectDesignDoc={Actions.selectDesignDoc}
+              onChangeNewDesignDocName={Actions.updateNewDesignDocName}
+              docLink={getDocUrl('DESIGN_DOCS')} />
+          </div>
 
+          <div className="control-group">
+            <label htmlFor="index-name">
+              <span>Index name</span>
+              <a
+                className="help-link"
+                data-bypass="true"
+                href={getDocUrl('VIEW_FUNCS')}
+                target="_blank">
+                <i className="icon-question-sign"></i>
+              </a>
+            </label>
+            <input
+              type="text"
+              id="index-name"
+              value={this.state.viewName}
+              onChange={this.viewChange}
+              placeholder="Index name" />
+          </div>
+          <CodeEditorPanel
+            id={'map-function'}
+            ref="mapEditor"
+            title={"Map function"}
+            docLink={getDocUrl('MAP_FUNCS')}
+            blur={this.updateMapCode}
+            allowZenMode={false}
+            defaultCode={this.state.map} />
+          <ReduceEditor ref="reduceEditor" />
+          <div className="padded-box">
+            <div className="control-group">
+              <ConfirmButton id="save-view" text={btnLabel} />
+              <a href={cancelLink} className="index-cancel-link">Cancel</a>
+            </div>
+          </div>
+        </form>
+      </div>
+    );
+  }
 });
+
+
+export default {
+  EditorController: EditorController,
+  ReduceEditor: ReduceEditor,
+  DesignDocSelector: DesignDocSelector,
+  StyledSelect: StyledSelect
+};

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/documents/index-editor/stores.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/index-editor/stores.js b/app/addons/documents/index-editor/stores.js
index e5071db..b327d74 100644
--- a/app/addons/documents/index-editor/stores.js
+++ b/app/addons/documents/index-editor/stores.js
@@ -10,261 +10,255 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-define([
-  '../../../core/api',
-  './actiontypes',
-  '../resources'
-],
+import FauxtonAPI from "../../../core/api";
+import ActionTypes from "./actiontypes";
+import Resources from "../resources";
+var Stores = {};
+
+Stores.IndexEditorStore = FauxtonAPI.Store.extend({
+
+  defaultMap: 'function (doc) {\n  emit(doc._id, 1);\n}',
+  defaultReduce: 'function (keys, values, rereduce) {\n  if (rereduce) {\n    return sum(values);\n  } else {\n    return values.length;\n  }\n}',
+
+  initialize: function () {
+    this.reset();
+  },
+
+  reset: function () {
+    this._designDocs = [];
+    this._isLoading = true;
+    this._view = { reduce: '', map: this.defaultMap };
+    this._database = { id: '0' };
+  },
+
+  editIndex: function (options) {
+    this._database = options.database;
+    this._newView = options.newView;
+    this._viewName = options.viewName || 'viewName';
+    this._newDesignDoc = options.newDesignDoc || false;
+    this._newDesignDocName = '';
+    this._designDocs = options.designDocs;
+    this._designDocId = options.designDocId;
+    this._originalViewName = this._viewName;
+    this._originalDesignDocName = options.designDocId;
+    this.setView();
+
+    this._isLoading = false;
+  },
+
+  isLoading: function () {
+    return this._isLoading;
+  },
+
+  setView: function () {
+    if (this._newView || this._newDesignDoc) {
+      this._view = { reduce: '', map: this.defaultMap };
+    } else {
+      this._view = this.getDesignDoc().get('views')[this._viewName];
+    }
+  },
+
+  getDatabase: function () {
+    return this._database;
+  },
+
+  getMap: function () {
+    return this._view.map;
+  },
+
+  setMap: function (map) {
+    this._view.map = map;
+  },
+
+  getReduce: function () {
+    return this._view.reduce;
+  },
+
+  setReduce: function (reduce) {
+    this._view.reduce = reduce;
+  },
+
+  getDesignDoc: function () {
+    return this._designDocs.find(function (ddoc) {
+      return this._designDocId == ddoc.id;
+    }, this).dDocModel();
+  },
+
+  getDesignDocs: function () {
+    return this._designDocs;
+  },
+
+  // returns a simple array of design doc IDs. Omits mango docs
+  getAvailableDesignDocs: function () {
+    var availableDocs = this.getDesignDocs().filter(function (doc) {
+      return !doc.isMangoDoc();
+    });
+    return _.map(availableDocs, function (doc) {
+      return doc.id;
+    });
+  },
+
+  getDesignDocId: function () {
+    return this._designDocId;
+  },
+
+  setDesignDocId: function (designDocId) {
+    this._designDocId = designDocId;
+  },
+
+  isNewDesignDoc: function () {
+    return this._newDesignDoc;
+  },
+
+  isNewView: function () {
+    return this._newView;
+  },
+
+  getViewName: function () {
+    return this._viewName;
+  },
+
+  setViewName: function (name) {
+    this._viewName = name;
+  },
+
+  hasCustomReduce: function () {
+    if (!this.hasReduce()) {
+      return false;
+    }
+    return !_.contains(this.builtInReduces(), this.getReduce());
+  },
 
-function (FauxtonAPI, ActionTypes, Resources) {
-  var Stores = {};
+  hasReduce: function () {
+    if (!this.getReduce()) {
+      return false;
+    }
+    return true;
+  },
 
-  Stores.IndexEditorStore = FauxtonAPI.Store.extend({
+  getOriginalViewName: function () {
+    return this._originalViewName;
+  },
 
-    defaultMap: 'function (doc) {\n  emit(doc._id, 1);\n}',
-    defaultReduce: 'function (keys, values, rereduce) {\n  if (rereduce) {\n    return sum(values);\n  } else {\n    return values.length;\n  }\n}',
+  getOriginalDesignDocName: function () {
+    return this._originalDesignDocName;
+  },
 
-    initialize: function () {
-      this.reset();
-    },
+  builtInReduces: function () {
+    return ['_sum', '_count', '_stats'];
+  },
 
-    reset: function () {
-      this._designDocs = [];
-      this._isLoading = true;
-      this._view = { reduce: '', map: this.defaultMap };
-      this._database = { id: '0' };
-    },
-
-    editIndex: function (options) {
-      this._database = options.database;
-      this._newView = options.newView;
-      this._viewName = options.viewName || 'viewName';
-      this._newDesignDoc = options.newDesignDoc || false;
-      this._newDesignDocName = '';
-      this._designDocs = options.designDocs;
-      this._designDocId = options.designDocId;
-      this._originalViewName = this._viewName;
-      this._originalDesignDocName = options.designDocId;
-      this.setView();
-
-      this._isLoading = false;
-    },
-
-    isLoading: function () {
-      return this._isLoading;
-    },
-
-    setView: function () {
-      if (this._newView || this._newDesignDoc) {
-        this._view = { reduce: '', map: this.defaultMap };
-      } else {
-        this._view = this.getDesignDoc().get('views')[this._viewName];
-      }
-    },
-
-    getDatabase: function () {
-      return this._database;
-    },
-
-    getMap: function () {
-      return this._view.map;
-    },
-
-    setMap: function (map) {
-      this._view.map = map;
-    },
-
-    getReduce: function () {
-      return this._view.reduce;
-    },
-
-    setReduce: function (reduce) {
-      this._view.reduce = reduce;
-    },
-
-    getDesignDoc: function () {
-      return this._designDocs.find(function (ddoc) {
-        return this._designDocId == ddoc.id;
-      }, this).dDocModel();
-    },
-
-    getDesignDocs: function () {
-      return this._designDocs;
-    },
-
-    // returns a simple array of design doc IDs. Omits mango docs
-    getAvailableDesignDocs: function () {
-      var availableDocs = this.getDesignDocs().filter(function (doc) {
-        return !doc.isMangoDoc();
-      });
-      return _.map(availableDocs, function (doc) {
-        return doc.id;
-      });
-    },
-
-    getDesignDocId: function () {
-      return this._designDocId;
-    },
-
-    setDesignDocId: function (designDocId) {
-      this._designDocId = designDocId;
-    },
-
-    isNewDesignDoc: function () {
-      return this._newDesignDoc;
-    },
-
-    isNewView: function () {
-      return this._newView;
-    },
-
-    getViewName: function () {
-      return this._viewName;
-    },
-
-    setViewName: function (name) {
-      this._viewName = name;
-    },
-
-    hasCustomReduce: function () {
-      if (!this.hasReduce()) {
-        return false;
-      }
-      return !_.contains(this.builtInReduces(), this.getReduce());
-    },
-
-    hasReduce: function () {
-      if (!this.getReduce()) {
-        return false;
-      }
-      return true;
-    },
-
-    getOriginalViewName: function () {
-      return this._originalViewName;
-    },
-
-    getOriginalDesignDocName: function () {
-      return this._originalDesignDocName;
-    },
-
-    builtInReduces: function () {
-      return ['_sum', '_count', '_stats'];
-    },
-
-    reduceSelectedOption: function () {
-      if (!this.hasReduce()) {
-        return 'NONE';
-      }
-      if (this.hasCustomReduce()) {
-        return 'CUSTOM';
-      }
-      return this.getReduce();
-    },
-
-    reduceOptions: function () {
-      return this.builtInReduces().concat(['CUSTOM', 'NONE']);
-    },
-
-    updateReduceFromSelect: function (selectedReduce) {
-      if (selectedReduce === 'NONE') {
-        this.setReduce(null);
-        return;
-      }
-      if (selectedReduce === 'CUSTOM') {
-        this.setReduce(this.defaultReduce);
-        return;
-      }
-      this.setReduce(selectedReduce);
-    },
-
-    addDesignDoc: function (designDoc) {
-      this._designDocs.add(designDoc, { merge: true });
-      this._designDocId = designDoc._id;
-    },
-
-    getNewDesignDocName: function () {
-      return this._newDesignDocName;
-    },
-
-    getSaveDesignDoc: function () {
-      if (this._designDocId === 'new-doc') {
-        var doc = {
-          _id: '_design/' + this._newDesignDocName,
-          views: {},
-          language: 'javascript'
-        };
-        return new Resources.Doc(doc, { database: this._database });
-      }
-
-      var foundDoc = this._designDocs.find(function (ddoc) {
-        return ddoc.id === this._designDocId;
-      }.bind(this));
-
-      return (!foundDoc) ? null : foundDoc.dDocModel();
-    },
-
-    dispatch: function (action) {
-      switch (action.type) {
-        case ActionTypes.CLEAR_INDEX:
-          this.reset();
-        break;
-
-        case ActionTypes.EDIT_INDEX:
-          this.editIndex(action.options);
-        break;
-
-        case ActionTypes.VIEW_NAME_CHANGE:
-          this.setViewName(action.name);
-        break;
-
-        case ActionTypes.EDIT_NEW_INDEX:
-          this.editIndex(action.options);
-        break;
-
-        case ActionTypes.SELECT_REDUCE_CHANGE:
-          this.updateReduceFromSelect(action.reduceSelectedOption);
-        break;
-
-        case ActionTypes.DESIGN_DOC_CHANGE:
-          this.setDesignDocId(action.options.value);
-        break;
-
-        case ActionTypes.VIEW_SAVED:
-        break;
-
-        case ActionTypes.VIEW_CREATED:
-        break;
-
-        case ActionTypes.VIEW_ADD_DESIGN_DOC:
-          this.addDesignDoc(action.designDoc);
-          this.setView();
-        break;
-
-        case ActionTypes.VIEW_UPDATE_MAP_CODE:
-          this.setMap(action.code);
-        break;
-
-        case ActionTypes.VIEW_UPDATE_REDUCE_CODE:
-          this.setReduce(action.code);
-        break;
-
-        case ActionTypes.DESIGN_DOC_NEW_NAME_UPDATED:
-          this._newDesignDocName = action.options.value;
-        break;
-
-        default:
-        return;
-      }
-
-      this.triggerChange();
+  reduceSelectedOption: function () {
+    if (!this.hasReduce()) {
+      return 'NONE';
+    }
+    if (this.hasCustomReduce()) {
+      return 'CUSTOM';
+    }
+    return this.getReduce();
+  },
+
+  reduceOptions: function () {
+    return this.builtInReduces().concat(['CUSTOM', 'NONE']);
+  },
+
+  updateReduceFromSelect: function (selectedReduce) {
+    if (selectedReduce === 'NONE') {
+      this.setReduce(null);
+      return;
+    }
+    if (selectedReduce === 'CUSTOM') {
+      this.setReduce(this.defaultReduce);
+      return;
+    }
+    this.setReduce(selectedReduce);
+  },
+
+  addDesignDoc: function (designDoc) {
+    this._designDocs.add(designDoc, { merge: true });
+    this._designDocId = designDoc._id;
+  },
+
+  getNewDesignDocName: function () {
+    return this._newDesignDocName;
+  },
+
+  getSaveDesignDoc: function () {
+    if (this._designDocId === 'new-doc') {
+      var doc = {
+        _id: '_design/' + this._newDesignDocName,
+        views: {},
+        language: 'javascript'
+      };
+      return new Resources.Doc(doc, { database: this._database });
     }
 
-  });
+    var foundDoc = this._designDocs.find(function (ddoc) {
+      return ddoc.id === this._designDocId;
+    }.bind(this));
+
+    return (!foundDoc) ? null : foundDoc.dDocModel();
+  },
+
+  dispatch: function (action) {
+    switch (action.type) {
+      case ActionTypes.CLEAR_INDEX:
+        this.reset();
+      break;
+
+      case ActionTypes.EDIT_INDEX:
+        this.editIndex(action.options);
+      break;
 
-  Stores.indexEditorStore = new Stores.IndexEditorStore();
-  Stores.indexEditorStore.dispatchToken = FauxtonAPI.dispatcher.register(Stores.indexEditorStore.dispatch);
+      case ActionTypes.VIEW_NAME_CHANGE:
+        this.setViewName(action.name);
+      break;
 
-  return Stores;
+      case ActionTypes.EDIT_NEW_INDEX:
+        this.editIndex(action.options);
+      break;
+
+      case ActionTypes.SELECT_REDUCE_CHANGE:
+        this.updateReduceFromSelect(action.reduceSelectedOption);
+      break;
+
+      case ActionTypes.DESIGN_DOC_CHANGE:
+        this.setDesignDocId(action.options.value);
+      break;
+
+      case ActionTypes.VIEW_SAVED:
+      break;
+
+      case ActionTypes.VIEW_CREATED:
+      break;
+
+      case ActionTypes.VIEW_ADD_DESIGN_DOC:
+        this.addDesignDoc(action.designDoc);
+        this.setView();
+      break;
+
+      case ActionTypes.VIEW_UPDATE_MAP_CODE:
+        this.setMap(action.code);
+      break;
+
+      case ActionTypes.VIEW_UPDATE_REDUCE_CODE:
+        this.setReduce(action.code);
+      break;
+
+      case ActionTypes.DESIGN_DOC_NEW_NAME_UPDATED:
+        this._newDesignDocName = action.options.value;
+      break;
+
+      default:
+      return;
+    }
+
+    this.triggerChange();
+  }
 
 });
+
+Stores.indexEditorStore = new Stores.IndexEditorStore();
+Stores.indexEditorStore.dispatchToken = FauxtonAPI.dispatcher.register(Stores.indexEditorStore.dispatch);
+
+export default Stores;

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/documents/index-editor/tests/actionsSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/index-editor/tests/actionsSpec.js b/app/addons/documents/index-editor/tests/actionsSpec.js
index 16e2eee..be13898 100644
--- a/app/addons/documents/index-editor/tests/actionsSpec.js
+++ b/app/addons/documents/index-editor/tests/actionsSpec.js
@@ -10,133 +10,129 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-define([
-  '../../../../core/api',
-  '../actions',
-  '../../resources',
-  '../actiontypes',
-  '../stores',
-  '../../../../../test/mocha/testUtils',
-  '../../index-results/actions',
-  'sinon',
-  '../../../documents/base'
-], function (FauxtonAPI, Actions, Documents, ActionTypes, Stores, testUtils, IndexResultsActions, sinon) {
-  var assert = testUtils.assert;
-  var restore = testUtils.restore;
-
-  FauxtonAPI.router = new FauxtonAPI.Router([]);
-
-
-  describe('Index Editor Actions', function () {
-
-    describe('delete view', function () {
-      var designDocs, database, designDoc, designDocCollection, designDocId, viewName;
-      beforeEach(function () {
-        database = {
-          safeID: function () { return 'safeid';}
-        };
-
-        viewName = 'test-view';
-        designDocId = '_design/test-doc';
-        designDocCollection = new Documents.AllDocs([{
-          _id: designDocId,
-          _rev: '1-231',
-          views: {
-              'test-view': {
-                map: 'function () {};'
-              },
-              'test-view2': {
-                map: 'function () {};'
-              }
+import FauxtonAPI from "../../../../core/api";
+import Actions from "../actions";
+import Documents from "../../resources";
+import ActionTypes from "../actiontypes";
+import Stores from "../stores";
+import testUtils from "../../../../../test/mocha/testUtils";
+import IndexResultsActions from "../../index-results/actions";
+import sinon from "sinon";
+import "../../../documents/base";
+var assert = testUtils.assert;
+var restore = testUtils.restore;
+
+FauxtonAPI.router = new FauxtonAPI.Router([]);
+
+
+describe('Index Editor Actions', function () {
+
+  describe('delete view', function () {
+    var designDocs, database, designDoc, designDocCollection, designDocId, viewName;
+    beforeEach(function () {
+      database = {
+        safeID: function () { return 'safeid';}
+      };
+
+      viewName = 'test-view';
+      designDocId = '_design/test-doc';
+      designDocCollection = new Documents.AllDocs([{
+        _id: designDocId,
+        _rev: '1-231',
+        views: {
+            'test-view': {
+              map: 'function () {};'
+            },
+            'test-view2': {
+              map: 'function () {};'
             }
-          }], {
-          params: { limit: 10 },
-          database: database
-        });
-        designDocs = designDocCollection.models;
-        designDoc = _.first(designDocs);
+          }
+        }], {
+        params: { limit: 10 },
+        database: database
       });
+      designDocs = designDocCollection.models;
+      designDoc = _.first(designDocs);
+    });
 
-      afterEach(function () {
-        restore(FauxtonAPI.navigate);
-        restore(FauxtonAPI.triggerRouteEvent);
-      });
+    afterEach(function () {
+      restore(FauxtonAPI.navigate);
+      restore(FauxtonAPI.triggerRouteEvent);
+    });
 
-      it('saves design doc if has other views', function () {
-        designDoc.save = function () {
-          var promise = $.Deferred();
-          promise.resolve();
-          return promise;
-        };
-        var saveSpy = sinon.spy(designDoc, 'save');
-        designDocs.fetch = function () {
-          var promise = $.Deferred();
-          promise.resolve();
-          return promise;
-        };
-
-        Actions.deleteView({
-          indexName: viewName,
-          database: database,
-          designDocs: designDocs,
-          designDoc: designDoc
-        });
-
-        assert.ok(saveSpy.calledOnce);
+    it('saves design doc if has other views', function () {
+      designDoc.save = function () {
+        var promise = $.Deferred();
+        promise.resolve();
+        return promise;
+      };
+      var saveSpy = sinon.spy(designDoc, 'save');
+      designDocs.fetch = function () {
+        var promise = $.Deferred();
+        promise.resolve();
+        return promise;
+      };
+
+      Actions.deleteView({
+        indexName: viewName,
+        database: database,
+        designDocs: designDocs,
+        designDoc: designDoc
       });
 
-      it('deletes design doc if has no other views', function () {
-        designDoc.removeDdocView('test-view2');
-
-        designDoc.destroy = function () {
-          var promise = $.Deferred();
-          promise.resolve();
-          return promise;
-        };
-        var destroySpy = sinon.spy(designDoc, 'destroy');
-        designDocs.remove = function () {};
-        designDocs.fetch = function () {
-          var promise = $.Deferred();
-          promise.resolve();
-          return promise;
-        };
-
-        Actions.deleteView({
-          indexName: viewName,
-          database: database,
-          designDocs: designDocs,
-          designDoc: designDoc
-        });
-
-        assert.ok(destroySpy.calledOnce);
+      assert.ok(saveSpy.calledOnce);
+    });
+
+    it('deletes design doc if has no other views', function () {
+      designDoc.removeDdocView('test-view2');
+
+      designDoc.destroy = function () {
+        var promise = $.Deferred();
+        promise.resolve();
+        return promise;
+      };
+      var destroySpy = sinon.spy(designDoc, 'destroy');
+      designDocs.remove = function () {};
+      designDocs.fetch = function () {
+        var promise = $.Deferred();
+        promise.resolve();
+        return promise;
+      };
+
+      Actions.deleteView({
+        indexName: viewName,
+        database: database,
+        designDocs: designDocs,
+        designDoc: designDoc
       });
 
-      it('navigates to all docs if was on view', function () {
-        var spy = sinon.spy(FauxtonAPI, 'navigate');
-
-        designDoc.save = function () {
-          var promise = $.Deferred();
-          promise.resolve();
-          return promise;
-        };
-        designDocs.fetch = function () {
-          var promise = $.Deferred();
-          promise.resolve();
-          return promise;
-        };
-        Actions.deleteView({
-          indexName: viewName,
-          database: database,
-          designDocs: designDocs,
-          designDoc: designDoc,
-          isOnIndex: true
-        });
-
-        assert.ok(spy.getCall(0).args[0].match(/_all_docs/));
-        assert.ok(spy.calledOnce);
+      assert.ok(destroySpy.calledOnce);
+    });
+
+    it('navigates to all docs if was on view', function () {
+      var spy = sinon.spy(FauxtonAPI, 'navigate');
+
+      designDoc.save = function () {
+        var promise = $.Deferred();
+        promise.resolve();
+        return promise;
+      };
+      designDocs.fetch = function () {
+        var promise = $.Deferred();
+        promise.resolve();
+        return promise;
+      };
+      Actions.deleteView({
+        indexName: viewName,
+        database: database,
+        designDocs: designDocs,
+        designDoc: designDoc,
+        isOnIndex: true
       });
 
+      assert.ok(spy.getCall(0).args[0].match(/_all_docs/));
+      assert.ok(spy.calledOnce);
     });
-  });
 
+  });
 });

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/documents/index-editor/tests/storesSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/index-editor/tests/storesSpec.js b/app/addons/documents/index-editor/tests/storesSpec.js
index bdd8dc9..a77fa52 100644
--- a/app/addons/documents/index-editor/tests/storesSpec.js
+++ b/app/addons/documents/index-editor/tests/storesSpec.js
@@ -10,259 +10,131 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-define([
-  '../../../../core/api',
-  '../stores',
-  '../actiontypes',
-  '../../../documents/resources',
-  '../../../../../test/mocha/testUtils',
-], function (FauxtonAPI, Stores, ActionTypes, Documents, testUtils) {
-  var assert = testUtils.assert;
-  var store;
-  var dispatchToken;
-
-  describe('IndexEditorStore', function () {
-
-    beforeEach(function () {
-      store = new Stores.IndexEditorStore();
-      dispatchToken = FauxtonAPI.dispatcher.register(store.dispatch);
-    });
-
-    afterEach(function () {
-      FauxtonAPI.dispatcher.unregister(dispatchToken);
-    });
+import FauxtonAPI from "../../../../core/api";
+import Stores from "../stores";
+import ActionTypes from "../actiontypes";
+import Documents from "../../../documents/resources";
+import testUtils from "../../../../../test/mocha/testUtils";
+var assert = testUtils.assert;
+var store;
+var dispatchToken;
+
+describe('IndexEditorStore', function () {
+
+  beforeEach(function () {
+    store = new Stores.IndexEditorStore();
+    dispatchToken = FauxtonAPI.dispatcher.register(store.dispatch);
+  });
 
-    describe('map editor', function () {
+  afterEach(function () {
+    FauxtonAPI.dispatcher.unregister(dispatchToken);
+  });
 
-      describe('new view', function () {
+  describe('map editor', function () {
 
-        beforeEach(function () {
+    describe('new view', function () {
 
-          FauxtonAPI.dispatch({
-            type: ActionTypes.EDIT_NEW_INDEX,
-            options: {
-              newView: true
-            }
-          });
-        });
+      beforeEach(function () {
 
-        it('returns default map', function () {
-          assert.equal(store.getMap(), 'function (doc) {\n  emit(doc._id, 1);\n}');
+        FauxtonAPI.dispatch({
+          type: ActionTypes.EDIT_NEW_INDEX,
+          options: {
+            newView: true
+          }
         });
       });
 
+      it('returns default map', function () {
+        assert.equal(store.getMap(), 'function (doc) {\n  emit(doc._id, 1);\n}');
+      });
     });
 
-    describe('reduce editor', function () {
-
-      describe('has custom reduce', function () {
-
-        it('is false for no reduce', function () {
-          var designDoc = {
-            _id: '_design/test-doc',
-            views: {
-              'test-view': {
-                map: 'function () {};'
-              }
-            }
-          };
-
-          var designDocs = new Documents.AllDocs([designDoc], {
-            params: { limit: 10 },
-            database: {
-              safeID: function () { return 'id';}
-            }
-          });
-
-          FauxtonAPI.dispatch({
-            type: ActionTypes.EDIT_NEW_INDEX,
-            options: {
-              newView: false,
-              viewName: 'test-view',
-              designDocs: designDocs,
-              designDocId: designDoc._id
-            }
-          });
+  });
 
-          assert.notOk(store.hasCustomReduce());
-        });
+  describe('reduce editor', function () {
 
-        it('is false for built in reduce', function () {
-          var designDoc = {
-            _id: '_design/test-doc',
-            views: {
-              'test-view': {
-                map: 'function () {};',
-                reduce: '_sum'
-              }
-            }
-          };
+    describe('has custom reduce', function () {
 
-          var designDocs = new Documents.AllDocs([designDoc], {
-            params: { limit: 10 },
-            database: {
-              safeID: function () { return 'id';}
-            }
-          });
-          FauxtonAPI.dispatch({
-            type: ActionTypes.EDIT_NEW_INDEX,
-            options: {
-              newView: false,
-              viewName: 'test-view',
-              designDocs: designDocs,
-              designDocId: designDoc._id
+      it('is false for no reduce', function () {
+        var designDoc = {
+          _id: '_design/test-doc',
+          views: {
+            'test-view': {
+              map: 'function () {};'
             }
-          });
+          }
+        };
 
-          assert.notOk(store.hasCustomReduce());
+        var designDocs = new Documents.AllDocs([designDoc], {
+          params: { limit: 10 },
+          database: {
+            safeID: function () { return 'id';}
+          }
         });
 
-        it('is true for custom reduce', function () {
-          var designDoc = {
-            _id: '_design/test-doc',
-            views: {
-              'test-view': {
-                map: 'function () {};',
-                reduce: 'function (reduce) { reduce(); }'
-              }
-            }
-          };
-
-          var designDocs = new Documents.AllDocs([designDoc], {
-            params: { limit: 10 },
-            database: {
-              safeID: function () { return 'id';}
-            }
-          });
-
-          FauxtonAPI.dispatch({
-            type: ActionTypes.EDIT_NEW_INDEX,
-            options: {
-              newView: false,
-              viewName: 'test-view',
-              designDocs: designDocs,
-              designDocId: designDoc._id
-            }
-          });
-
-          assert.ok(store.hasCustomReduce());
+        FauxtonAPI.dispatch({
+          type: ActionTypes.EDIT_NEW_INDEX,
+          options: {
+            newView: false,
+            viewName: 'test-view',
+            designDocs: designDocs,
+            designDocId: designDoc._id
+          }
         });
 
+        assert.notOk(store.hasCustomReduce());
       });
 
-      //show default reduce
-      describe('SELECT_REDUCE_CHANGE', function () {
-
-        beforeEach(function () {
-          var designDoc = {
-            _id: '_design/test-doc',
-            views: {
-              'test-view': {
-                map: 'function () {};'
-              }
-            }
-          };
-
-          var designDocs = new Documents.AllDocs([designDoc], {
-            params: { limit: 10 },
-            database: {
-              safeID: function () { return 'id';}
-            }
-          });
-
-          FauxtonAPI.dispatch({
-            type: ActionTypes.EDIT_NEW_INDEX,
-            options: {
-              newView: false,
-              viewName: 'test-view',
-              designDocs: designDocs,
-              designDocId: designDoc._id
+      it('is false for built in reduce', function () {
+        var designDoc = {
+          _id: '_design/test-doc',
+          views: {
+            'test-view': {
+              map: 'function () {};',
+              reduce: '_sum'
             }
-          });
-        });
+          }
+        };
 
-        it('NONE returns null reduce', function () {
-          FauxtonAPI.dispatch({
-            type: ActionTypes.SELECT_REDUCE_CHANGE,
-            reduceSelectedOption: 'NONE'
-          });
-          assert.ok(_.isNull(store.getReduce()));
+        var designDocs = new Documents.AllDocs([designDoc], {
+          params: { limit: 10 },
+          database: {
+            safeID: function () { return 'id';}
+          }
         });
-
-        it('builtin returns bultin reduce', function () {
-          FauxtonAPI.dispatch({
-            type: ActionTypes.SELECT_REDUCE_CHANGE,
-            reduceSelectedOption: '_sum'
-          });
-          assert.equal(store.getReduce(), '_sum');
+        FauxtonAPI.dispatch({
+          type: ActionTypes.EDIT_NEW_INDEX,
+          options: {
+            newView: false,
+            viewName: 'test-view',
+            designDocs: designDocs,
+            designDocId: designDoc._id
+          }
         });
 
-        it('custom returns custom reduce', function () {
-          FauxtonAPI.dispatch({
-            type: ActionTypes.SELECT_REDUCE_CHANGE,
-            reduceSelectedOption: 'CUSTOM'
-          });
-          assert.equal(store.getReduce(), 'function (keys, values, rereduce) {\n  if (rereduce) {\n    return sum(values);\n  } else {\n    return values.length;\n  }\n}');
-        });
+        assert.notOk(store.hasCustomReduce());
       });
-    });
 
-
-    describe('design doc selector', function () {
-      var designDoc;
-
-      beforeEach(function () {
-        designDoc = {
+      it('is true for custom reduce', function () {
+        var designDoc = {
           _id: '_design/test-doc',
           views: {
             'test-view': {
-              map: 'boom'
-            }
-          }
-        };
-
-        var mangoDoc = {
-          "_id": "_design/123mango",
-          "id": "_design/123mango",
-          "key": "_design/123mango",
-          "value": {
-            "rev": "20-9e4bc8b76fd7d752d620bbe6e0ea9a80"
-          },
-          "doc": {
-            "_id": "_design/123mango",
-            "_rev": "20-9e4bc8b76fd7d752d620bbe6e0ea9a80",
-            "views": {
-              "test-view": {
-                "map": "function(doc) {\n  emit(doc._id, 2);\n}"
-              },
-              "new-view": {
-                "map": "function(doc) {\n  if (doc.class === \"mammal\" && doc.diet === \"herbivore\")\n    emit(doc._id, 1);\n}",
-                "reduce": "_sum"
-              }
-            },
-            "language": "query",
-            "indexes": {
-              "newSearch": {
-                "analyzer": "standard",
-                "index": "function(doc){\n index(\"default\", doc._id);\n}"
-              }
+              map: 'function () {};',
+              reduce: 'function (reduce) { reduce(); }'
             }
           }
         };
 
-        var designDocArray = _.map([designDoc, mangoDoc], function (doc) {
-          return Documents.Doc.prototype.parse(doc);
-        });
-
-        var designDocs = new Documents.AllDocs(designDocArray, {
+        var designDocs = new Documents.AllDocs([designDoc], {
           params: { limit: 10 },
           database: {
-            safeID: function () { return 'id'; }
+            safeID: function () { return 'id';}
           }
         });
 
         FauxtonAPI.dispatch({
-          type: ActionTypes.EDIT_INDEX,
+          type: ActionTypes.EDIT_NEW_INDEX,
           options: {
             newView: false,
             viewName: 'test-view',
@@ -270,73 +142,198 @@ define([
             designDocId: designDoc._id
           }
         });
-      });
 
-      afterEach(function () {
-        store.reset();
+        assert.ok(store.hasCustomReduce());
       });
 
-      it('DESIGN_DOC_CHANGE changes design doc id', function () {
-        var designDocId = 'another-one';
-        FauxtonAPI.dispatch({
-          type: ActionTypes.DESIGN_DOC_CHANGE,
-          options: {
-            value: designDocId
-          }
-        });
-        assert.equal(store.getDesignDocId(), designDocId);
-      });
-
-      it('only filters mango docs', function () {
-        var designDocs = store.getAvailableDesignDocs();
-        assert.equal(designDocs.length, 1);
-        assert.equal(designDocs[0], '_design/test-doc');
-      });
     });
 
-    describe('EDIT_INDEX', function () {
-      var designDoc, designDocs;
+    //show default reduce
+    describe('SELECT_REDUCE_CHANGE', function () {
 
       beforeEach(function () {
-        designDoc = {
+        var designDoc = {
           _id: '_design/test-doc',
           views: {
             'test-view': {
-              map: 'boom'
+              map: 'function () {};'
             }
           }
         };
 
-        designDocs = new Documents.AllDocs([designDoc], {
+        var designDocs = new Documents.AllDocs([designDoc], {
           params: { limit: 10 },
           database: {
             safeID: function () { return 'id';}
           }
         });
 
-      });
-
-      it('can set reduce for new design doc', function () {
         FauxtonAPI.dispatch({
-          type: ActionTypes.EDIT_INDEX,
+          type: ActionTypes.EDIT_NEW_INDEX,
           options: {
-            newView: true,
-            newDesignDoc: true,
+            newView: false,
             viewName: 'test-view',
             designDocs: designDocs,
-            designDocId: undefined
+            designDocId: designDoc._id
           }
         });
+      });
 
+      it('NONE returns null reduce', function () {
         FauxtonAPI.dispatch({
           type: ActionTypes.SELECT_REDUCE_CHANGE,
-          reduceSelectedOption: '_sum'
+          reduceSelectedOption: 'NONE'
         });
+        assert.ok(_.isNull(store.getReduce()));
+      });
 
+      it('builtin returns bultin reduce', function () {
+        FauxtonAPI.dispatch({
+          type: ActionTypes.SELECT_REDUCE_CHANGE,
+          reduceSelectedOption: '_sum'
+        });
         assert.equal(store.getReduce(), '_sum');
       });
 
+      it('custom returns custom reduce', function () {
+        FauxtonAPI.dispatch({
+          type: ActionTypes.SELECT_REDUCE_CHANGE,
+          reduceSelectedOption: 'CUSTOM'
+        });
+        assert.equal(store.getReduce(), 'function (keys, values, rereduce) {\n  if (rereduce) {\n    return sum(values);\n  } else {\n    return values.length;\n  }\n}');
+      });
+    });
+  });
+
+
+  describe('design doc selector', function () {
+    var designDoc;
+
+    beforeEach(function () {
+      designDoc = {
+        _id: '_design/test-doc',
+        views: {
+          'test-view': {
+            map: 'boom'
+          }
+        }
+      };
+
+      var mangoDoc = {
+        "_id": "_design/123mango",
+        "id": "_design/123mango",
+        "key": "_design/123mango",
+        "value": {
+          "rev": "20-9e4bc8b76fd7d752d620bbe6e0ea9a80"
+        },
+        "doc": {
+          "_id": "_design/123mango",
+          "_rev": "20-9e4bc8b76fd7d752d620bbe6e0ea9a80",
+          "views": {
+            "test-view": {
+              "map": "function(doc) {\n  emit(doc._id, 2);\n}"
+            },
+            "new-view": {
+              "map": "function(doc) {\n  if (doc.class === \"mammal\" && doc.diet === \"herbivore\")\n    emit(doc._id, 1);\n}",
+              "reduce": "_sum"
+            }
+          },
+          "language": "query",
+          "indexes": {
+            "newSearch": {
+              "analyzer": "standard",
+              "index": "function(doc){\n index(\"default\", doc._id);\n}"
+            }
+          }
+        }
+      };
+
+      var designDocArray = _.map([designDoc, mangoDoc], function (doc) {
+        return Documents.Doc.prototype.parse(doc);
+      });
+
+      var designDocs = new Documents.AllDocs(designDocArray, {
+        params: { limit: 10 },
+        database: {
+          safeID: function () { return 'id'; }
+        }
+      });
+
+      FauxtonAPI.dispatch({
+        type: ActionTypes.EDIT_INDEX,
+        options: {
+          newView: false,
+          viewName: 'test-view',
+          designDocs: designDocs,
+          designDocId: designDoc._id
+        }
+      });
+    });
+
+    afterEach(function () {
+      store.reset();
+    });
+
+    it('DESIGN_DOC_CHANGE changes design doc id', function () {
+      var designDocId = 'another-one';
+      FauxtonAPI.dispatch({
+        type: ActionTypes.DESIGN_DOC_CHANGE,
+        options: {
+          value: designDocId
+        }
+      });
+      assert.equal(store.getDesignDocId(), designDocId);
+    });
+
+    it('only filters mango docs', function () {
+      var designDocs = store.getAvailableDesignDocs();
+      assert.equal(designDocs.length, 1);
+      assert.equal(designDocs[0], '_design/test-doc');
+    });
+  });
+
+  describe('EDIT_INDEX', function () {
+    var designDoc, designDocs;
+
+    beforeEach(function () {
+      designDoc = {
+        _id: '_design/test-doc',
+        views: {
+          'test-view': {
+            map: 'boom'
+          }
+        }
+      };
+
+      designDocs = new Documents.AllDocs([designDoc], {
+        params: { limit: 10 },
+        database: {
+          safeID: function () { return 'id';}
+        }
+      });
+
+    });
+
+    it('can set reduce for new design doc', function () {
+      FauxtonAPI.dispatch({
+        type: ActionTypes.EDIT_INDEX,
+        options: {
+          newView: true,
+          newDesignDoc: true,
+          viewName: 'test-view',
+          designDocs: designDocs,
+          designDocId: undefined
+        }
+      });
+
+      FauxtonAPI.dispatch({
+        type: ActionTypes.SELECT_REDUCE_CHANGE,
+        reduceSelectedOption: '_sum'
+      });
+
+      assert.equal(store.getReduce(), '_sum');
     });
 
   });
+
 });


Mime
View raw message