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