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
65d131cd
Commit
65d131cd
authored
Mar 31, 2022
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add types for "defaults" store module
parent
ef9426db
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
10 deletions
+25
-10
persisted-defaults.js
src/sidebar/services/persisted-defaults.js
+6
-1
defaults.js
src/sidebar/store/modules/defaults.js
+19
-9
No files found.
src/sidebar/services/persisted-defaults.js
View file @
65d131cd
import
{
watch
}
from
'../util/watch'
;
/**
* @typedef {import('../store/modules/defaults').Key} Key
*/
/** @type {Record<Key, string>} */
const
DEFAULT_KEYS
=
{
annotationPrivacy
:
'hypothesis.privacy'
,
focusedGroup
:
'hypothesis.groups.focus'
,
...
...
@@ -46,7 +51,7 @@ export class PersistedDefaultsService {
Object
.
keys
(
DEFAULT_KEYS
).
forEach
(
defaultKey
=>
{
// `localStorage.getItem` will return `null` for a non-existent key
const
defaultValue
=
this
.
_storage
.
getItem
(
DEFAULT_KEYS
[
defaultKey
]);
this
.
_store
.
setDefault
(
defaultKey
,
defaultValue
);
this
.
_store
.
setDefault
(
/** @type {Key} */
(
defaultKey
)
,
defaultValue
);
});
// Listen for changes to those defaults from the store and persist them
...
...
src/sidebar/store/modules/defaults.js
View file @
65d131cd
import
*
as
util
from
'../util'
;
import
{
createStoreModule
}
from
'../create-store'
;
import
{
createStoreModule
,
makeAction
}
from
'../create-store'
;
/**
* A store module for managing client-side user-convenience defaults.
...
...
@@ -21,16 +19,27 @@ const initialState = {
focusedGroup
:
/** @type {string|null} */
(
null
),
};
/**
* @typedef {keyof initialState} Key
* @typedef {typeof initialState} State
*/
const
reducers
=
{
SET_DEFAULT
:
function
(
state
,
action
)
{
/**
* @param {State} state
* @param {{ defaultKey: Key, value: string|null }} action
*/
SET_DEFAULT
(
state
,
action
)
{
return
{
[
action
.
defaultKey
]:
action
.
value
};
},
};
const
actions
=
util
.
actionTypes
(
reducers
);
/**
* @param {Key} defaultKey
* @param {string|null} value
*/
function
setDefault
(
defaultKey
,
value
)
{
return
{
type
:
actions
.
SET_DEFAULT
,
defaultKey
,
value
}
;
return
makeAction
(
reducers
,
'SET_DEFAULT'
,
{
defaultKey
,
value
})
;
}
/** Selectors */
...
...
@@ -38,13 +47,14 @@ function setDefault(defaultKey, value) {
/**
* Retrieve the state's current value for `defaultKey`.
*
* @
return {string|null} - The current value for `defaultKey` or `undefined` if it is not
*
present
* @
param {State} state
*
@param {Key} defaultKey
*/
function
getDefault
(
state
,
defaultKey
)
{
return
state
[
defaultKey
];
}
/** @param {State} state */
function
getDefaults
(
state
)
{
return
state
;
}
...
...
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