Unverified Commit 2578fefd authored by Robert Knight's avatar Robert Knight Committed by GitHub

Merge pull request #694 from hypothesis/move-store

Move Redux modules and entry point to `store/` directory
parents 183a5524 b693fef0
......@@ -56,7 +56,7 @@ describe('sidebar.components.sidebar-content', function () {
before(function () {
angular.module('h', [])
.service('annotationUI', require('../../services/annotation-ui'))
.service('annotationUI', require('../../store'))
.component('sidebarContent', proxyquire('../sidebar-content',
noCallThru({
angular: angular,
......
......@@ -186,7 +186,6 @@ module.exports = angular.module('h', [
.service('analytics', require('./services/analytics'))
.service('annotationMapper', require('./services/annotation-mapper'))
.service('annotationUI', require('./services/annotation-ui'))
.service('api', require('./services/api'))
.service('apiRoutes', require('./services/api-routes'))
.service('auth', require('./services/oauth-auth'))
......@@ -209,6 +208,10 @@ module.exports = angular.module('h', [
.service('unicode', require('./services/unicode'))
.service('viewFilter', require('./services/view-filter'))
// Redux store
.service('annotationUI', require('./store'))
// Utilities
.value('Discovery', require('../shared/discovery'))
.value('ExcerptOverflowMonitor', require('./util/excerpt-overflow-monitor'))
.value('OAuthClient', require('./util/oauth-client'))
......
......@@ -21,7 +21,7 @@ describe('annotationMapper', function() {
};
angular.module('app', [])
.service('annotationMapper', require('../annotation-mapper'))
.service('annotationUI', require('../annotation-ui'))
.service('annotationUI', require('../../store'))
.value('api', fakeApi)
.value('settings', {});
angular.mock.module('app');
......
'use strict';
/**
* AnnotationUI is the central store of state for the sidebar application,
* managed using [Redux](http://redux.js.org/).
* Central store of state for the sidebar application, managed using
* [Redux](http://redux.js.org/).
*
* State management in Redux apps work as follows:
*
......@@ -36,16 +36,16 @@ var redux = require('redux');
// `.default` is needed because 'redux-thunk' is built as an ES2015 module
var thunk = require('redux-thunk').default;
var reducers = require('../reducers');
var annotationsReducer = require('../reducers/annotations');
var framesReducer = require('../reducers/frames');
var linksReducer = require('../reducers/links');
var selectionReducer = require('../reducers/selection');
var sessionReducer = require('../reducers/session');
var viewerReducer = require('../reducers/viewer');
var util = require('../reducers/util');
var modules = require('./modules');
var annotationsModule = require('./modules/annotations');
var framesModule = require('./modules/frames');
var linksModule = require('./modules/links');
var selectionModule = require('./modules/selection');
var sessionModule = require('./modules/session');
var viewerModule = require('./modules/viewer');
var debugMiddleware = require('../reducers/debug-middleware');
var debugMiddleware = require('./debug-middleware');
var util = require('./util');
/**
* Redux middleware which triggers an Angular change-detection cycle
......@@ -72,8 +72,11 @@ function angularDigestMiddleware($rootScope) {
};
}
/**
* Create the Redux store for the application.
*/
// @ngInject
module.exports = function ($rootScope, settings) {
function store($rootScope, settings) {
var enhancer = redux.applyMiddleware(
// The `thunk` middleware handles actions which are functions.
// This is used to implement actions which have side effects or are
......@@ -82,7 +85,7 @@ module.exports = function ($rootScope, settings) {
debugMiddleware,
angularDigestMiddleware.bind(null, $rootScope)
);
var store = redux.createStore(reducers.update, reducers.init(settings),
var store = redux.createStore(modules.update, modules.init(settings),
enhancer);
// Expose helper functions that create actions as methods of the
......@@ -94,12 +97,12 @@ module.exports = function ($rootScope, settings) {
// annotationUI.addAnnotations(annotations)
//
var actionCreators = redux.bindActionCreators(Object.assign({},
annotationsReducer.actions,
framesReducer.actions,
linksReducer.actions,
selectionReducer.actions,
sessionReducer.actions,
viewerReducer.actions
annotationsModule.actions,
framesModule.actions,
linksModule.actions,
selectionModule.actions,
sessionModule.actions,
viewerModule.actions
), store.dispatch);
// Expose selectors as methods of the `annotationUI` to make using them easier
......@@ -110,13 +113,15 @@ module.exports = function ($rootScope, settings) {
// You can use:
// annotationUI.isAnnotationSelected(id)
var selectors = util.bindSelectors(Object.assign({},
annotationsReducer.selectors,
framesReducer.selectors,
linksReducer.selectors,
selectionReducer.selectors,
sessionReducer.selectors,
viewerReducer.selectors
annotationsModule.selectors,
framesModule.selectors,
linksModule.selectors,
selectionModule.selectors,
sessionModule.selectors,
viewerModule.selectors
), store.getState);
return Object.assign(store, actionCreators, selectors);
};
}
module.exports = store;
......@@ -5,12 +5,12 @@
'use strict';
var arrayUtil = require('../util/array-util');
var metadata = require('../annotation-metadata');
var uiConstants = require('../ui-constants');
var arrayUtil = require('../../util/array-util');
var metadata = require('../../annotation-metadata');
var uiConstants = require('../../ui-constants');
var selection = require('./selection');
var util = require('./util');
var util = require('../util');
/**
* Return a copy of `current` with all matching annotations in `annotations`
......
'use strict';
var util = require('./util');
var util = require('../util');
function init() {
return {
......
......@@ -3,7 +3,7 @@
/**
* This module defines the main update function (or 'reducer' in Redux's
* terminology) that handles app state updates. For an overview of how state
* management in Redux works, see the comments at the top of `annotation-ui.js`
* management in Redux works, see the comments at the top of `store/index.js`
*
* Each sub-module in this folder defines:
*
......@@ -23,7 +23,7 @@ var links = require('./links');
var selection = require('./selection');
var session = require('./session');
var viewer = require('./viewer');
var util = require('./util');
var util = require('../util');
function init(settings) {
return Object.assign(
......
......@@ -12,11 +12,11 @@
var immutable = require('seamless-immutable');
var toSet = require('../util/array-util').toSet;
var uiConstants = require('../ui-constants');
var tabs = require('../tabs');
var toSet = require('../../util/array-util').toSet;
var uiConstants = require('../../ui-constants');
var tabs = require('../../tabs');
var util = require('./util');
var util = require('../util');
/**
......
'use strict';
var util = require('./util');
var util = require('../util');
function init() {
return {
......
......@@ -5,9 +5,9 @@ var redux = require('redux');
var thunk = require('redux-thunk').default;
var annotations = require('../annotations');
var fixtures = require('../../test/annotation-fixtures');
var util = require('../util');
var unroll = require('../../../shared/test/util').unroll;
var fixtures = require('../../../test/annotation-fixtures');
var util = require('../../util');
var unroll = require('../../../../shared/test/util').unroll;
var { actions, selectors } = annotations;
......
......@@ -2,8 +2,8 @@
var frames = require('../frames');
var session = require('../session');
var util = require('../util');
var unroll = require('../../../shared/test/util').unroll;
var util = require('../../util');
var unroll = require('../../../../shared/test/util').unroll;
var actions = frames.actions;
var update = util.createReducer(frames.update);
......
......@@ -2,7 +2,7 @@
var session = require('../session');
var util = require('../util');
var util = require('../../util');
var { init, actions, selectors } = session;
var update = util.createReducer(session.update);
......
......@@ -2,7 +2,7 @@
var viewer = require('../viewer');
var util = require('../util');
var util = require('../../util');
var { init, actions, selectors } = viewer;
var update = util.createReducer(viewer.update);
......
'use strict';
var util = require('./util');
var util = require('../util');
/**
* This module defines actions and state related to the display mode of the
......
......@@ -2,7 +2,7 @@
var immutable = require('seamless-immutable');
var annotationUIFactory = require('../annotation-ui');
var annotationUIFactory = require('../index');
var annotationFixtures = require('../../test/annotation-fixtures');
var metadata = require('../../annotation-metadata');
var unroll = require('../../../shared/test/util').unroll;
......
......@@ -44,7 +44,7 @@ describe('annotation threading', function () {
};
angular.module('app', [])
.service('annotationUI', require('../../services/annotation-ui'))
.service('annotationUI', require('../../store'))
.service('drafts', require('../../services/drafts'))
.service('rootThread', require('../../services/root-thread'))
.service('searchFilter', require('../../services/search-filter'))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment