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
Show 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] = [
...
@@ -45,6 +45,17 @@ TAB_SORTKEYS_AVAILABLE[uiConstants.TAB_ORPHANS] = [
'Location'
,
'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
)
{
function
initialSelection
(
settings
)
{
const
selection
=
{};
const
selection
=
{};
// TODO: Do not take into account existence of `settings.query` here
// TODO: Do not take into account existence of `settings.query` here
...
@@ -402,9 +413,7 @@ function setSortKey(key) {
...
@@ -402,9 +413,7 @@ function setSortKey(key) {
/* Selectors */
/* Selectors */
function
focusedAnnotations
(
state
)
{
function
focusedAnnotations
(
state
)
{
return
Object
.
keys
(
state
.
selection
.
focused
).
filter
(
return
truthyKeys
(
state
.
selection
.
focused
);
id
=>
state
.
selection
.
focused
[
id
]
===
true
);
}
}
/** Is the annotation referenced by `$tag` currently focused? */
/** Is the annotation referenced by `$tag` currently focused? */
...
@@ -417,8 +426,7 @@ function isAnnotationFocused(state, $tag) {
...
@@ -417,8 +426,7 @@ function isAnnotationFocused(state, $tag) {
*/
*/
const
hasSelectedAnnotations
=
createSelector
(
const
hasSelectedAnnotations
=
createSelector
(
state
=>
state
.
selection
.
selected
,
state
=>
state
.
selection
.
selected
,
selection
=>
selection
=>
truthyKeys
(
selection
).
length
>
0
Object
.
keys
(
selection
).
filter
(
id
=>
selection
[
id
]
===
true
).
length
>
0
);
);
/** De-select all annotations. */
/** De-select all annotations. */
...
@@ -441,9 +449,7 @@ function clearSelection() {
...
@@ -441,9 +449,7 @@ function clearSelection() {
const
getFirstSelectedAnnotationId
=
createSelector
(
const
getFirstSelectedAnnotationId
=
createSelector
(
state
=>
state
.
selection
.
selected
,
state
=>
state
.
selection
.
selected
,
selection
=>
{
selection
=>
{
const
selectedIds
=
Object
.
keys
(
selection
).
filter
(
const
selectedIds
=
truthyKeys
(
selection
);
id
=>
selection
[
id
]
===
true
);
return
selectedIds
.
length
?
selectedIds
[
0
]
:
null
;
return
selectedIds
.
length
?
selectedIds
[
0
]
:
null
;
}
}
);
);
...
@@ -543,7 +549,7 @@ const hasAppliedFilter = createSelector(
...
@@ -543,7 +549,7 @@ const hasAppliedFilter = createSelector(
const
selectedAnnotations
=
createSelector
(
const
selectedAnnotations
=
createSelector
(
state
=>
state
.
selection
.
selected
,
state
=>
state
.
selection
.
selected
,
selection
=>
Object
.
keys
(
selection
).
filter
(
id
=>
selection
[
id
]
===
true
)
selection
=>
truthyKeys
(
selection
)
);
);
export
default
{
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