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
286f8332
Commit
286f8332
authored
Jul 14, 2020
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Jul 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DRY out selectors with `truthyKeys`
Use utility function to derive "truthy" keys in internal maps
parent
cd4b7a86
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
9 deletions
+15
-9
selection.js
src/sidebar/store/modules/selection.js
+15
-9
No files found.
src/sidebar/store/modules/selection.js
View file @
286f8332
...
...
@@ -45,6 +45,17 @@ TAB_SORTKEYS_AVAILABLE[uiConstants.TAB_ORPHANS] = [
'Location'
,
];
/**
* Utility function that returns all of the properties of an object whose
* value is `true`.
*
* @param {Object} obj
* @return {any[]}
*/
function
truthyKeys
(
obj
)
{
return
Object
.
keys
(
obj
).
filter
(
key
=>
obj
[
key
]
===
true
);
}
function
initialSelection
(
settings
)
{
const
selection
=
{};
// TODO: Do not take into account existence of `settings.query` here
...
...
@@ -402,9 +413,7 @@ function setSortKey(key) {
/* Selectors */
function
focusedAnnotations
(
state
)
{
return
Object
.
keys
(
state
.
selection
.
focused
).
filter
(
id
=>
state
.
selection
.
focused
[
id
]
===
true
);
return
truthyKeys
(
state
.
selection
.
focused
);
}
/** Is the annotation referenced by `$tag` currently focused? */
...
...
@@ -417,8 +426,7 @@ function isAnnotationFocused(state, $tag) {
*/
const
hasSelectedAnnotations
=
createSelector
(
state
=>
state
.
selection
.
selected
,
selection
=>
Object
.
keys
(
selection
).
filter
(
id
=>
selection
[
id
]
===
true
).
length
>
0
selection
=>
truthyKeys
(
selection
).
length
>
0
);
/** De-select all annotations. */
...
...
@@ -441,9 +449,7 @@ function clearSelection() {
const
getFirstSelectedAnnotationId
=
createSelector
(
state
=>
state
.
selection
.
selected
,
selection
=>
{
const
selectedIds
=
Object
.
keys
(
selection
).
filter
(
id
=>
selection
[
id
]
===
true
);
const
selectedIds
=
truthyKeys
(
selection
);
return
selectedIds
.
length
?
selectedIds
[
0
]
:
null
;
}
);
...
...
@@ -543,7 +549,7 @@ const hasAppliedFilter = createSelector(
const
selectedAnnotations
=
createSelector
(
state
=>
state
.
selection
.
selected
,
selection
=>
Object
.
keys
(
selection
).
filter
(
id
=>
selection
[
id
]
===
true
)
selection
=>
truthyKeys
(
selection
)
);
export
default
{
...
...
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