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
cd5b852c
Commit
cd5b852c
authored
May 17, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
May 17, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate PersistedDefaultsService to TS
parent
7ffe7fc4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
17 deletions
+14
-17
persisted-defaults.ts
src/sidebar/services/persisted-defaults.ts
+14
-17
No files found.
src/sidebar/services/persisted-defaults.
j
s
→
src/sidebar/services/persisted-defaults.
t
s
View file @
cd5b852c
import
type
{
SidebarStore
}
from
'../store'
;
import
type
{
Key
}
from
'../store/modules/defaults'
;
import
{
entries
}
from
'../util/collections'
;
import
{
entries
}
from
'../util/collections'
;
import
{
watch
}
from
'../util/watch'
;
import
{
watch
}
from
'../util/watch'
;
import
type
{
LocalStorageService
}
from
'./local-storage'
;
/**
const
DEFAULT_KEYS
:
Record
<
Key
,
string
>
=
{
* @typedef {import('../store/modules/defaults').Key} Key
*/
/** @type {Record<Key, string>} */
const
DEFAULT_KEYS
=
{
annotationPrivacy
:
'hypothesis.privacy'
,
annotationPrivacy
:
'hypothesis.privacy'
,
focusedGroup
:
'hypothesis.groups.focus'
,
focusedGroup
:
'hypothesis.groups.focus'
,
};
};
...
@@ -18,11 +16,10 @@ const DEFAULT_KEYS = {
...
@@ -18,11 +16,10 @@ const DEFAULT_KEYS = {
* @inject
* @inject
*/
*/
export
class
PersistedDefaultsService
{
export
class
PersistedDefaultsService
{
/**
private
_storage
:
LocalStorageService
;
* @param {import('./local-storage').LocalStorageService} localStorage
private
_store
:
SidebarStore
;
* @param {import('../store').SidebarStore} store
*/
constructor
(
localStorage
:
LocalStorageService
,
store
:
SidebarStore
)
{
constructor
(
localStorage
,
store
)
{
this
.
_storage
=
localStorage
;
this
.
_storage
=
localStorage
;
this
.
_store
=
store
;
this
.
_store
=
store
;
}
}
...
@@ -36,12 +33,12 @@ export class PersistedDefaultsService {
...
@@ -36,12 +33,12 @@ export class PersistedDefaultsService {
/**
/**
* Store subscribe callback for persisting changes to defaults. It will only
* Store subscribe callback for persisting changes to defaults. It will only
* persist defaults that it "knows about" via `DEFAULT_KEYS`.
* persist defaults that it "knows about" via `DEFAULT_KEYS`.
*
* @param {Record<Key, any>} defaults
* @param {Record<Key, any>} prevDefaults
*/
*/
const
persistChangedDefaults
=
(
defaults
,
prevDefaults
)
=>
{
const
persistChangedDefaults
=
(
for
(
let
[
defaultKey
,
newValue
]
of
entries
(
defaults
))
{
defaults
:
Record
<
Key
,
any
>
,
prevDefaults
:
Record
<
Key
,
any
>
)
=>
{
for
(
const
[
defaultKey
,
newValue
]
of
entries
(
defaults
))
{
if
(
if
(
prevDefaults
[
defaultKey
]
!==
newValue
&&
prevDefaults
[
defaultKey
]
!==
newValue
&&
defaultKey
in
DEFAULT_KEYS
defaultKey
in
DEFAULT_KEYS
...
@@ -52,7 +49,7 @@ export class PersistedDefaultsService {
...
@@ -52,7 +49,7 @@ export class PersistedDefaultsService {
};
};
// Read persisted defaults into the store
// Read persisted defaults into the store
for
(
le
t
[
defaultKey
,
key
]
of
entries
(
DEFAULT_KEYS
))
{
for
(
cons
t
[
defaultKey
,
key
]
of
entries
(
DEFAULT_KEYS
))
{
// `localStorage.getItem` will return `null` for a non-existent key
// `localStorage.getItem` will return `null` for a non-existent key
const
defaultValue
=
this
.
_storage
.
getItem
(
key
);
const
defaultValue
=
this
.
_storage
.
getItem
(
key
);
this
.
_store
.
setDefault
(
defaultKey
,
defaultValue
);
this
.
_store
.
setDefault
(
defaultKey
,
defaultValue
);
...
...
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