Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
d7a959c1
Unverified
Commit
d7a959c1
authored
Jul 01, 2019
by
Hannah Stepanek
Committed by
GitHub
Jul 01, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1215 from hypothesis/store-load-ann-state-in-store
Add loading of annotations state to store
parents
99209185
01f75dbc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
105 additions
and
0 deletions
+105
-0
activity.js
src/sidebar/store/modules/activity.js
+48
-0
activity-test.js
src/sidebar/store/modules/test/activity-test.js
+57
-0
No files found.
src/sidebar/store/modules/activity.js
View file @
d7a959c1
...
...
@@ -14,6 +14,10 @@ function init() {
* 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
,
},
};
}
...
...
@@ -44,6 +48,32 @@ const update = {
},
};
},
ANNOTATION_FETCH_STARTED
(
state
)
{
const
{
activity
}
=
state
;
return
{
activity
:
{
...
activity
,
activeAnnotationFetches
:
activity
.
activeAnnotationFetches
+
1
,
},
};
},
ANNOTATION_FETCH_FINISHED
(
state
)
{
const
{
activity
}
=
state
;
if
(
activity
.
activeAnnotationFetches
===
0
)
{
throw
new
Error
(
'ANNOTATION_FETCH_FINISHED action when no annotation fetches were active'
);
}
return
{
activity
:
{
...
activity
,
activeAnnotationFetches
:
activity
.
activeAnnotationFetches
-
1
,
},
};
},
};
const
actions
=
actionTypes
(
update
);
...
...
@@ -56,6 +86,14 @@ function apiRequestFinished() {
return
{
type
:
actions
.
API_REQUEST_FINISHED
};
}
function
annotationFetchStarted
()
{
return
{
type
:
actions
.
ANNOTATION_FETCH_STARTED
};
}
function
annotationFetchFinished
()
{
return
{
type
:
actions
.
ANNOTATION_FETCH_FINISHED
};
}
/**
* Return true when any activity is happening in the app that needs to complete
* before the UI will be idle.
...
...
@@ -64,6 +102,13 @@ function isLoading(state) {
return
state
.
activity
.
activeApiRequests
>
0
;
}
/**
* Return true when annotations are actively being fetched.
*/
function
isFetchingAnnotations
(
state
)
{
return
state
.
activity
.
activeAnnotationFetches
>
0
;
}
module
.
exports
=
{
init
,
update
,
...
...
@@ -71,9 +116,12 @@ module.exports = {
actions
:
{
apiRequestStarted
,
apiRequestFinished
,
annotationFetchStarted
,
annotationFetchFinished
,
},
selectors
:
{
isLoading
,
isFetchingAnnotations
,
},
};
src/sidebar/store/modules/test/activity-test.js
View file @
d7a959c1
...
...
@@ -33,6 +33,63 @@ describe('sidebar/store/modules/activity', () => {
});
});
describe
(
'isFetchingAnnotations'
,
()
=>
{
it
(
'returns false with the initial state'
,
()
=>
{
assert
.
equal
(
store
.
isFetchingAnnotations
(),
false
);
});
it
(
'returns true when API requests are in flight'
,
()
=>
{
store
.
annotationFetchStarted
();
assert
.
equal
(
store
.
isFetchingAnnotations
(),
true
);
});
it
(
'returns false when all requests end'
,
()
=>
{
store
.
annotationFetchStarted
();
store
.
annotationFetchStarted
();
store
.
annotationFetchFinished
();
assert
.
equal
(
store
.
isFetchingAnnotations
(),
true
);
store
.
annotationFetchFinished
();
assert
.
equal
(
store
.
isFetchingAnnotations
(),
false
);
});
});
it
(
'defaults `activeAnnotationFetches` counter to zero'
,
()
=>
{
assert
.
equal
(
store
.
getState
().
activity
.
activeAnnotationFetches
,
0
);
});
describe
(
'annotationFetchFinished'
,
()
=>
{
it
(
'triggers an error if no requests are in flight'
,
()
=>
{
assert
.
throws
(()
=>
{
store
.
annotationFetchFinished
();
});
});
it
(
'increments `activeAnnotationFetches` counter when a new annotation fetch is started'
,
()
=>
{
store
.
annotationFetchStarted
();
assert
.
equal
(
store
.
getState
().
activity
.
activeAnnotationFetches
,
1
);
});
});
describe
(
'annotationFetchStarted'
,
()
=>
{
it
(
'triggers an error if no requests are in flight'
,
()
=>
{
assert
.
throws
(()
=>
{
store
.
annotationFetchFinished
();
});
});
it
(
'decrements `activeAnnotationFetches` counter when an annotation fetch is finished'
,
()
=>
{
store
.
annotationFetchStarted
();
store
.
annotationFetchFinished
();
assert
.
equal
(
store
.
getState
().
activity
.
activeAnnotationFetches
,
0
);
});
});
describe
(
'#apiRequestFinished'
,
()
=>
{
it
(
'triggers an error if no requests are in flight'
,
()
=>
{
assert
.
throws
(()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment