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
3675cea5
Commit
3675cea5
authored
Apr 12, 2021
by
Eduardo Sanz García
Committed by
Eduardo
Apr 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added/improved types
I added more specific types to services, that was otherwise listed as `Object`.
parent
0eba1843
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
46 additions
and
39 deletions
+46
-39
AnnotationView.js
src/sidebar/components/AnnotationView.js
+1
-1
NotebookView.js
src/sidebar/components/NotebookView.js
+3
-3
SidebarView.js
src/sidebar/components/SidebarView.js
+3
-3
StreamView.js
src/sidebar/components/StreamView.js
+2
-2
api.js
src/sidebar/services/api.js
+3
-3
groups.js
src/sidebar/services/groups.js
+1
-1
load-annotations.js
src/sidebar/services/load-annotations.js
+9
-3
stream-filter.js
src/sidebar/services/stream-filter.js
+7
-11
streamer.js
src/sidebar/services/streamer.js
+6
-0
toast-messenger.js
src/sidebar/services/toast-messenger.js
+3
-3
annotations.js
src/sidebar/store/modules/annotations.js
+1
-1
drafts.js
src/sidebar/store/modules/drafts.js
+0
-1
real-time-updates.js
src/sidebar/store/modules/real-time-updates.js
+2
-2
url.js
src/sidebar/util/url.js
+2
-2
watch.js
src/sidebar/util/watch.js
+1
-1
websocket.js
src/sidebar/websocket.js
+2
-2
No files found.
src/sidebar/components/AnnotationView.js
View file @
3675cea5
...
@@ -10,7 +10,7 @@ import SidebarContentError from './SidebarContentError';
...
@@ -10,7 +10,7 @@ import SidebarContentError from './SidebarContentError';
/**
/**
* @typedef AnnotationViewProps
* @typedef AnnotationViewProps
* @prop {() => any} onLogin
* @prop {() => any} onLogin
* @prop {
Object} [loadAnnotationsService]
- Injected service
* @prop {
ReturnType<import('../services/load-annotations').default>} loadAnnotationsService
- Injected service
*/
*/
/**
/**
...
...
src/sidebar/components/NotebookView.js
View file @
3675cea5
...
@@ -15,8 +15,8 @@ import PaginatedThreadList from './PaginatedThreadList';
...
@@ -15,8 +15,8 @@ import PaginatedThreadList from './PaginatedThreadList';
/**
/**
* @typedef NotebookViewProps
* @typedef NotebookViewProps
* @prop {
Object} [loadAnnotationsService]
- Injected service
* @prop {
ReturnType<import('../services/load-annotations').default>} loadAnnotationsService
- Injected service
* @prop {
Object} [streamer]
- Injected service
* @prop {
import('../services/streamer').default} streamer
- Injected service
*/
*/
/**
/**
...
@@ -69,7 +69,7 @@ function NotebookView({ loadAnnotationsService, streamer }) {
...
@@ -69,7 +69,7 @@ function NotebookView({ loadAnnotationsService, streamer }) {
// Establish websocket connection
// Establish websocket connection
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
streamer
&&
hasFetchedProfile
)
{
if
(
hasFetchedProfile
)
{
streamer
.
connect
({
applyUpdatesImmediately
:
false
});
streamer
.
connect
({
applyUpdatesImmediately
:
false
});
}
}
},
[
hasFetchedProfile
,
streamer
]);
},
[
hasFetchedProfile
,
streamer
]);
...
...
src/sidebar/components/SidebarView.js
View file @
3675cea5
...
@@ -16,9 +16,9 @@ import ThreadList from './ThreadList';
...
@@ -16,9 +16,9 @@ import ThreadList from './ThreadList';
* @typedef SidebarViewProps
* @typedef SidebarViewProps
* @prop {() => any} onLogin
* @prop {() => any} onLogin
* @prop {() => any} onSignUp
* @prop {() => any} onSignUp
* @prop {
Object} [frameSync]
- Injected service
* @prop {
import('../services/frame-sync').default} frameSync
- Injected service
* @prop {
Object} [loadAnnotationsService]
- Injected service
* @prop {
ReturnType<import('../services/load-annotations').default>} loadAnnotationsService
- Injected service
* @prop {
Object} [streamer]
- Injected service
* @prop {
import('../services/streamer').default} streamer
- Injected service
*/
*/
/**
/**
...
...
src/sidebar/components/StreamView.js
View file @
3675cea5
...
@@ -9,8 +9,8 @@ import ThreadList from './ThreadList';
...
@@ -9,8 +9,8 @@ import ThreadList from './ThreadList';
/**
/**
* @typedef StreamViewProps
* @typedef StreamViewProps
* @prop {
Object} [api]
- Injected service
* @prop {
ReturnType<import('../services/api').default>} api
- Injected service
* @prop {
Object} [toastMessenger]
- Injected service
* @prop {
ReturnType<import('../services/toast-messenger').default>} toastMessenger
- Injected service
*/
*/
/**
/**
...
...
src/sidebar/services/api.js
View file @
3675cea5
...
@@ -56,9 +56,9 @@ function stripInternalProperties(obj) {
...
@@ -56,9 +56,9 @@ function stripInternalProperties(obj) {
* Function which makes an API request.
* Function which makes an API request.
*
*
* @callback APICallFunction
* @callback APICallFunction
* @param {
any} [params]
- A map of URL and query string parameters to include with the request.
* @param {
Record<string, any>} params
- A map of URL and query string parameters to include with the request.
* @param {
any
} [data] - The body of the request.
* @param {
Object
} [data] - The body of the request.
* @param {APICallOptions}
options
* @param {APICallOptions}
[options]
* @return {Promise<any|APIResponse>}
* @return {Promise<any|APIResponse>}
*/
*/
...
...
src/sidebar/services/groups.js
View file @
3675cea5
...
@@ -162,7 +162,7 @@ export default function groups(
...
@@ -162,7 +162,7 @@ export default function groups(
});
});
}
}
/*
/*
*
* Fetch a specific group.
* Fetch a specific group.
*
*
* @param {string} id
* @param {string} id
...
...
src/sidebar/services/load-annotations.js
View file @
3675cea5
...
@@ -29,6 +29,12 @@ import { SearchClient } from '../search-client';
...
@@ -29,6 +29,12 @@ import { SearchClient } from '../search-client';
import
{
isReply
}
from
'../helpers/annotation-metadata'
;
import
{
isReply
}
from
'../helpers/annotation-metadata'
;
/**
* @param {ReturnType<import('./api').default>} api
* @param {import('../store').SidebarStore} store
* @param {import('./streamer').default} streamer
* @param {import('./stream-filter').default} streamFilter
*/
// @inject
// @inject
export
default
function
loadAnnotationsService
(
export
default
function
loadAnnotationsService
(
api
,
api
,
...
@@ -83,7 +89,7 @@ export default function loadAnnotationsService(
...
@@ -83,7 +89,7 @@ export default function loadAnnotationsService(
const
searchOptions
=
{
const
searchOptions
=
{
incremental
:
true
,
incremental
:
true
,
maxResults
:
maxResults
??
null
,
maxResults
,
separateReplies
:
false
,
separateReplies
:
false
,
// Annotations are fetched in order of creation by default. This is expected
// Annotations are fetched in order of creation by default. This is expected
...
@@ -97,8 +103,8 @@ export default function loadAnnotationsService(
...
@@ -97,8 +103,8 @@ export default function loadAnnotationsService(
//
//
// If the backend would allow us to sort on document location, we could do even better.
// If the backend would allow us to sort on document location, we could do even better.
sortBy
:
/** @type {SortBy} */
(
sortBy
??
'created'
)
,
sortBy
,
sortOrder
:
/** @type {SortOrder} */
(
sortOrder
??
'asc'
)
,
sortOrder
,
};
};
searchClient
=
new
SearchClient
(
api
.
search
,
searchOptions
);
searchClient
=
new
SearchClient
(
api
.
search
,
searchOptions
);
...
...
src/sidebar/services/stream-filter.js
View file @
3675cea5
/**
* @typedef {'equals'|'one_of'} Operator
*/
/**
/**
* Filter clause against which annotation updates are tested before being
* Filter clause against which annotation updates are tested before being
* sent to the client.
* sent to the client.
*
*
* @typedef FilterClause
* @typedef FilterClause
* @prop {
string
} field
* @prop {
'/group'|'/id'|'/references'|'/uri'
} field
* @prop {
Operator
} operator
* @prop {
'equals'|'one_of'
} operator
* @prop {
any
} value
* @prop {
string|string[]
} value
* @prop {boolean} case_sensitive - TODO: Backend doesn't use this at present,
* @prop {boolean} case_sensitive - TODO: Backend doesn't use this at present,
* but it seems important for certain fields (eg. ID).
* but it seems important for certain fields (eg. ID).
*/
*/
...
@@ -56,10 +52,10 @@ export default class StreamFilter {
...
@@ -56,10 +52,10 @@ export default class StreamFilter {
/**
/**
* Add a matching clause to the configuration.
* Add a matching clause to the configuration.
*
*
* @param {
string
} field - Field to filter by
* @param {
FilterClause['field']
} field - Field to filter by
* @param {
Operator
} operator - How to filter
* @param {
FilterClause['operator']
} operator - How to filter
* @param {
any
} value - Value to match
* @param {
FilterClause['value']
} value - Value to match
* @param {
boolean
} caseSensitive - Whether matching should be case sensitive
* @param {
FilterClause['case_sensitive']
} caseSensitive - Whether matching should be case sensitive
*/
*/
addClause
(
field
,
operator
,
value
,
caseSensitive
=
false
)
{
addClause
(
field
,
operator
,
value
,
caseSensitive
=
false
)
{
this
.
filter
.
clauses
.
push
({
this
.
filter
.
clauses
.
push
({
...
...
src/sidebar/services/streamer.js
View file @
3675cea5
...
@@ -9,6 +9,12 @@ import { watch } from '../util/watch';
...
@@ -9,6 +9,12 @@ import { watch } from '../util/watch';
* Open a new WebSocket connection to the Hypothesis push notification service.
* Open a new WebSocket connection to the Hypothesis push notification service.
* Only one websocket connection may exist at a time, any existing socket is
* Only one websocket connection may exist at a time, any existing socket is
* closed.
* closed.
*
* @param {import('../store').SidebarStore} store
* @param {ReturnType<import('./oauth-auth').default>} auth
* @param {ReturnType<import('./groups').default>} groups
* @param {ReturnType<import('./session').default>} session
* @param {Record<string, any>} settings
*/
*/
// @inject
// @inject
export
default
function
Streamer
(
store
,
auth
,
groups
,
session
,
settings
)
{
export
default
function
Streamer
(
store
,
auth
,
groups
,
session
,
settings
)
{
...
...
src/sidebar/services/toast-messenger.js
View file @
3675cea5
...
@@ -80,7 +80,7 @@ export default function toastMessenger(store) {
...
@@ -80,7 +80,7 @@ export default function toastMessenger(store) {
* Add an error toast message with `messageText`
* Add an error toast message with `messageText`
*
*
* @param {string} messageText
* @param {string} messageText
* @param {MessageOptions}
options
* @param {MessageOptions}
[options]
*/
*/
const
error
=
(
messageText
,
options
)
=>
{
const
error
=
(
messageText
,
options
)
=>
{
addMessage
(
'error'
,
messageText
,
options
);
addMessage
(
'error'
,
messageText
,
options
);
...
@@ -90,7 +90,7 @@ export default function toastMessenger(store) {
...
@@ -90,7 +90,7 @@ export default function toastMessenger(store) {
* Add a success toast message with `messageText`
* Add a success toast message with `messageText`
*
*
* @param {string} messageText
* @param {string} messageText
* @param {MessageOptions}
options
* @param {MessageOptions}
[options]
*/
*/
const
success
=
(
messageText
,
options
)
=>
{
const
success
=
(
messageText
,
options
)
=>
{
addMessage
(
'success'
,
messageText
,
options
);
addMessage
(
'success'
,
messageText
,
options
);
...
@@ -100,7 +100,7 @@ export default function toastMessenger(store) {
...
@@ -100,7 +100,7 @@ export default function toastMessenger(store) {
* Add a warn/notice toast message with `messageText`
* Add a warn/notice toast message with `messageText`
*
*
* @param {string} messageText
* @param {string} messageText
* @param {MessageOptions}
options
* @param {MessageOptions}
[options]
*/
*/
const
notice
=
(
messageText
,
options
)
=>
{
const
notice
=
(
messageText
,
options
)
=>
{
addMessage
(
'notice'
,
messageText
,
options
);
addMessage
(
'notice'
,
messageText
,
options
);
...
...
src/sidebar/store/modules/annotations.js
View file @
3675cea5
...
@@ -342,7 +342,7 @@ function highlightAnnotations(ids) {
...
@@ -342,7 +342,7 @@ function highlightAnnotations(ids) {
/**
/**
* Remove annotations from the currently displayed set.
* Remove annotations from the currently displayed set.
*
*
* @param {Annotation[]} annotations -
* @param {Annotation
Stub
[]} annotations -
* Annotations to remove. These may be complete annotations or stubs which
* Annotations to remove. These may be complete annotations or stubs which
* only contain an `id` property.
* only contain an `id` property.
*/
*/
...
...
src/sidebar/store/modules/drafts.js
View file @
3675cea5
...
@@ -97,7 +97,6 @@ function createDraft(annotation, changes) {
...
@@ -97,7 +97,6 @@ function createDraft(annotation, changes) {
*
*
* An empty draft has no text and no reference tags.
* An empty draft has no text and no reference tags.
*/
*/
function
deleteNewAndEmptyDrafts
()
{
function
deleteNewAndEmptyDrafts
()
{
const
{
removeAnnotations
}
=
require
(
'./annotations'
);
const
{
removeAnnotations
}
=
require
(
'./annotations'
);
...
...
src/sidebar/store/modules/real-time-updates.js
View file @
3675cea5
...
@@ -83,8 +83,8 @@ const actions = actionTypes(update);
...
@@ -83,8 +83,8 @@ const actions = actionTypes(update);
* has been notified about but has not yet applied.
* has been notified about but has not yet applied.
*
*
* @param {Object} args
* @param {Object} args
* @param {Annotation[]}
args.updatedAnnotations
* @param {Annotation[]}
[args.updatedAnnotations]
* @param {Annotation[]}
args.deletedAnnotations
* @param {Annotation[]}
[args.deletedAnnotations]
*/
*/
function
receiveRealTimeUpdates
({
function
receiveRealTimeUpdates
({
updatedAnnotations
=
[],
updatedAnnotations
=
[],
...
...
src/sidebar/util/url.js
View file @
3675cea5
...
@@ -8,8 +8,8 @@
...
@@ -8,8 +8,8 @@
* {url: '/things/foo', params: {q: 'bar'}}
* {url: '/things/foo', params: {q: 'bar'}}
*
*
* @param {string} url
* @param {string} url
* @param {
Object
} params
* @param {
Record<string, any>
} params
* @return {{ url: string, params:
Object
}}
* @return {{ url: string, params:
Record<string, any>
}}
*/
*/
export
function
replaceURLParams
(
url
,
params
)
{
export
function
replaceURLParams
(
url
,
params
)
{
const
unusedParams
=
{};
const
unusedParams
=
{};
...
...
src/sidebar/util/watch.js
View file @
3675cea5
...
@@ -38,7 +38,7 @@ import shallowEqual from 'shallowequal';
...
@@ -38,7 +38,7 @@ import shallowEqual from 'shallowequal';
*
*
* Values are compared using strict equality (`===`).
* Values are compared using strict equality (`===`).
*
*
* @param {(callback:
Function
) => Function} subscribe - Function used to
* @param {(callback:
() => void
) => Function} subscribe - Function used to
* subscribe to notifications of _potential_ changes in the watched values.
* subscribe to notifications of _potential_ changes in the watched values.
* @param {Function|Array<Function>} watchFns - A function or array of functions
* @param {Function|Array<Function>} watchFns - A function or array of functions
* which return the current watched values
* which return the current watched values
...
...
src/sidebar/websocket.js
View file @
3675cea5
...
@@ -60,7 +60,7 @@ export default class Socket extends TinyEmitter {
...
@@ -60,7 +60,7 @@ export default class Socket extends TinyEmitter {
minTimeout
:
RECONNECT_MIN_DELAY
*
2
,
minTimeout
:
RECONNECT_MIN_DELAY
*
2
,
// Don't retry forever -- fail permanently after 10 retries
// Don't retry forever -- fail permanently after 10 retries
retries
:
10
,
retries
:
10
,
// Randomize retry times to minimi
s
e the thundering herd effect
// Randomize retry times to minimi
z
e the thundering herd effect
randomize
:
true
,
randomize
:
true
,
});
});
...
@@ -76,7 +76,7 @@ export default class Socket extends TinyEmitter {
...
@@ -76,7 +76,7 @@ export default class Socket extends TinyEmitter {
return
;
return
;
}
}
const
err
=
new
Error
(
const
err
=
new
Error
(
'WebSocket closed abnormally, code: '
+
event
.
code
`WebSocket closed abnormally, code:
${
event
.
code
}
`
);
);
console
.
warn
(
err
);
console
.
warn
(
err
);
onAbnormalClose
(
err
);
onAbnormalClose
(
err
);
...
...
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