Unverified Commit 4bc0827e authored by Robert Knight's avatar Robert Knight Committed by GitHub

Merge pull request #1316 from hypothesis/namespace-activity-module

Namespace the activity module
parents fee80c6d 146f5ddb
......@@ -9,69 +9,55 @@ const { actionTypes } = require('../util');
function init() {
return {
activity: {
/**
* The number of API requests that have started and not yet completed.
*/
activeApiRequests: 0,
/**
* The number of annotation fetches that have started and not yet completed.
*/
activeAnnotationFetches: 0,
},
/**
* The number of API requests that have started and not yet completed.
*/
activeApiRequests: 0,
/**
* The number of annotation fetches that have started and not yet completed.
*/
activeAnnotationFetches: 0,
};
}
const update = {
API_REQUEST_STARTED(state) {
const { activity } = state;
return {
activity: {
...activity,
activeApiRequests: activity.activeApiRequests + 1,
},
...state,
activeApiRequests: state.activeApiRequests + 1,
};
},
API_REQUEST_FINISHED(state) {
const { activity } = state;
if (activity.activeApiRequests === 0) {
if (state.activeApiRequests === 0) {
throw new Error(
'API_REQUEST_FINISHED action when no requests were active'
);
}
return {
activity: {
...activity,
activeApiRequests: activity.activeApiRequests - 1,
},
...state,
activeApiRequests: state.activeApiRequests - 1,
};
},
ANNOTATION_FETCH_STARTED(state) {
const { activity } = state;
return {
activity: {
...activity,
activeAnnotationFetches: activity.activeAnnotationFetches + 1,
},
...state,
activeAnnotationFetches: state.activeAnnotationFetches + 1,
};
},
ANNOTATION_FETCH_FINISHED(state) {
const { activity } = state;
if (activity.activeAnnotationFetches === 0) {
if (state.activeAnnotationFetches === 0) {
throw new Error(
'ANNOTATION_FETCH_FINISHED action when no annotation fetches were active'
);
}
return {
activity: {
...activity,
activeAnnotationFetches: activity.activeAnnotationFetches - 1,
},
...state,
activeAnnotationFetches: state.activeAnnotationFetches - 1,
};
},
};
......@@ -112,6 +98,7 @@ function isFetchingAnnotations(state) {
module.exports = {
init,
update,
namespace: 'activity',
actions: {
apiRequestStarted,
......
......@@ -57,7 +57,7 @@ describe('sidebar/store/modules/activity', () => {
});
it('defaults `activeAnnotationFetches` counter to zero', () => {
assert.equal(store.getState().activity.activeAnnotationFetches, 0);
assert.equal(store.getRootState().activity.activeAnnotationFetches, 0);
});
describe('annotationFetchFinished', () => {
......@@ -70,7 +70,7 @@ describe('sidebar/store/modules/activity', () => {
it('increments `activeAnnotationFetches` counter when a new annotation fetch is started', () => {
store.annotationFetchStarted();
assert.equal(store.getState().activity.activeAnnotationFetches, 1);
assert.equal(store.getRootState().activity.activeAnnotationFetches, 1);
});
});
......@@ -86,7 +86,7 @@ describe('sidebar/store/modules/activity', () => {
store.annotationFetchFinished();
assert.equal(store.getState().activity.activeAnnotationFetches, 0);
assert.equal(store.getRootState().activity.activeAnnotationFetches, 0);
});
});
......
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