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
d8f9baae
Unverified
Commit
d8f9baae
authored
Jan 14, 2020
by
Robert Knight
Committed by
GitHub
Jan 14, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1674 from hypothesis/convert-sidebar-store-to-es-modules
Convert src/sidebar/store to ES modules
parents
db679988
25e5e7fe
Changes
34
Hide whitespace changes
Inline
Side-by-side
Showing
34 changed files
with
140 additions
and
153 deletions
+140
-153
create-store.js
src/sidebar/store/create-store.js
+4
-6
debug-middleware.js
src/sidebar/store/debug-middleware.js
+1
-3
index.js
src/sidebar/store/index.js
+15
-18
activity.js
src/sidebar/store/modules/activity.js
+2
-2
annotations.js
src/sidebar/store/modules/annotations.js
+8
-8
direct-linked.js
src/sidebar/store/modules/direct-linked.js
+2
-2
drafts.js
src/sidebar/store/modules/drafts.js
+6
-6
frames.js
src/sidebar/store/modules/frames.js
+3
-3
groups.js
src/sidebar/store/modules/groups.js
+5
-4
links.js
src/sidebar/store/modules/links.js
+1
-1
real-time-updates.js
src/sidebar/store/modules/real-time-updates.js
+6
-6
selection.js
src/sidebar/store/modules/selection.js
+8
-9
session.js
src/sidebar/store/modules/session.js
+2
-2
sidebar-panels.js
src/sidebar/store/modules/sidebar-panels.js
+2
-2
activity-test.js
src/sidebar/store/modules/test/activity-test.js
+2
-2
annotations-test.js
src/sidebar/store/modules/test/annotations-test.js
+10
-12
direct-linked-test.js
src/sidebar/store/modules/test/direct-linked-test.js
+2
-2
drafts-test.js
src/sidebar/store/modules/test/drafts-test.js
+6
-6
frames-test.js
src/sidebar/store/modules/test/frames-test.js
+2
-2
groups-test.js
src/sidebar/store/modules/test/groups-test.js
+4
-4
links-test.js
src/sidebar/store/modules/test/links-test.js
+1
-1
real-time-updates-test.js
src/sidebar/store/modules/test/real-time-updates-test.js
+15
-10
selection-test.js
src/sidebar/store/modules/test/selection-test.js
+4
-4
session-test.js
src/sidebar/store/modules/test/session-test.js
+2
-2
sidebar-panels-test.js
src/sidebar/store/modules/test/sidebar-panels-test.js
+2
-2
viewer-test.js
src/sidebar/store/modules/test/viewer-test.js
+2
-2
viewer.js
src/sidebar/store/modules/viewer.js
+2
-2
create-store-test.js
src/sidebar/store/test/create-store-test.js
+1
-1
debug-middleware-test.js
src/sidebar/store/test/debug-middleware-test.js
+2
-2
index-test.js
src/sidebar/store/test/index-test.js
+4
-4
use-store-test.js
src/sidebar/store/test/use-store-test.js
+5
-6
util-test.js
src/sidebar/store/test/util-test.js
+1
-1
use-store.js
src/sidebar/store/use-store.js
+5
-7
util.js
src/sidebar/store/util.js
+3
-9
No files found.
src/sidebar/store/create-store.js
View file @
d8f9baae
const
redux
=
require
(
'redux'
)
;
import
*
as
redux
from
'redux'
;
const
{
default
:
thunk
}
=
require
(
'redux-thunk'
)
;
import
thunk
from
'redux-thunk'
;
const
{
createReducer
,
bindSelectors
}
=
require
(
'./util'
)
;
import
{
createReducer
,
bindSelectors
}
from
'./util'
;
/**
/**
* Create a Redux store from a set of _modules_.
* Create a Redux store from a set of _modules_.
...
@@ -22,7 +22,7 @@ const { createReducer, bindSelectors } = require('./util');
...
@@ -22,7 +22,7 @@ const { createReducer, bindSelectors } = require('./util');
* @param {any[]} initArgs - Arguments to pass to each state module's `init` function
* @param {any[]} initArgs - Arguments to pass to each state module's `init` function
* @param [any[]] middleware - List of additional Redux middlewares to use.
* @param [any[]] middleware - List of additional Redux middlewares to use.
*/
*/
function
createStore
(
modules
,
initArgs
=
[],
middleware
=
[])
{
export
default
function
createStore
(
modules
,
initArgs
=
[],
middleware
=
[])
{
// Create the initial state and state update function.
// Create the initial state and state update function.
// Namespaced objects for initial states.
// Namespaced objects for initial states.
...
@@ -74,5 +74,3 @@ function createStore(modules, initArgs = [], middleware = []) {
...
@@ -74,5 +74,3 @@ function createStore(modules, initArgs = [], middleware = []) {
return
store
;
return
store
;
}
}
module
.
exports
=
createStore
;
src/sidebar/store/debug-middleware.js
View file @
d8f9baae
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
* to the console, along with the application state before and after the action
* to the console, along with the application state before and after the action
* was handled.
* was handled.
*/
*/
function
debugMiddleware
(
store
)
{
export
default
function
debugMiddleware
(
store
)
{
/* eslint-disable no-console */
/* eslint-disable no-console */
let
serial
=
0
;
let
serial
=
0
;
...
@@ -34,5 +34,3 @@ function debugMiddleware(store) {
...
@@ -34,5 +34,3 @@ function debugMiddleware(store) {
};
};
/* eslint-enable no-console */
/* eslint-enable no-console */
}
}
module
.
exports
=
debugMiddleware
;
src/sidebar/store/index.js
View file @
d8f9baae
...
@@ -29,21 +29,20 @@
...
@@ -29,21 +29,20 @@
* 3. Checking that the UI correctly presents a given state.
* 3. Checking that the UI correctly presents a given state.
*/
*/
const
createStore
=
require
(
'./create-store'
);
import
createStore
from
'./create-store'
;
const
debugMiddleware
=
require
(
'./debug-middleware'
);
import
debugMiddleware
from
'./debug-middleware'
;
import
activity
from
'./modules/activity'
;
const
activity
=
require
(
'./modules/activity'
);
import
annotations
from
'./modules/annotations'
;
const
annotations
=
require
(
'./modules/annotations'
);
import
directLinked
from
'./modules/direct-linked'
;
const
directLinked
=
require
(
'./modules/direct-linked'
);
import
drafts
from
'./modules/drafts'
;
const
drafts
=
require
(
'./modules/drafts'
);
import
frames
from
'./modules/frames'
;
const
frames
=
require
(
'./modules/frames'
);
import
groups
from
'./modules/groups'
;
const
links
=
require
(
'./modules/links'
);
import
links
from
'./modules/links'
;
const
groups
=
require
(
'./modules/groups'
);
import
realTimeUpdates
from
'./modules/real-time-updates'
;
const
realTimeUpdates
=
require
(
'./modules/real-time-updates'
);
import
selection
from
'./modules/selection'
;
const
selection
=
require
(
'./modules/selection'
);
import
session
from
'./modules/session'
;
const
session
=
require
(
'./modules/session'
);
import
sidebarPanels
from
'./modules/sidebar-panels'
;
const
sidebarPanels
=
require
(
'./modules/sidebar-panels'
);
import
viewer
from
'./modules/viewer'
;
const
viewer
=
require
(
'./modules/viewer'
);
/**
/**
* Redux middleware which triggers an Angular change-detection cycle
* Redux middleware which triggers an Angular change-detection cycle
...
@@ -79,7 +78,7 @@ function angularDigestMiddleware($rootScope) {
...
@@ -79,7 +78,7 @@ function angularDigestMiddleware($rootScope) {
* passing the current state of the store.
* passing the current state of the store.
*/
*/
// @ngInject
// @ngInject
function
store
(
$rootScope
,
settings
)
{
export
default
function
store
(
$rootScope
,
settings
)
{
const
middleware
=
[
const
middleware
=
[
debugMiddleware
,
debugMiddleware
,
angularDigestMiddleware
.
bind
(
null
,
$rootScope
),
angularDigestMiddleware
.
bind
(
null
,
$rootScope
),
...
@@ -101,5 +100,3 @@ function store($rootScope, settings) {
...
@@ -101,5 +100,3 @@ function store($rootScope, settings) {
];
];
return
createStore
(
modules
,
[
settings
],
middleware
);
return
createStore
(
modules
,
[
settings
],
middleware
);
}
}
module
.
exports
=
store
;
src/sidebar/store/modules/activity.js
View file @
d8f9baae
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
* need to be reflected in the UI.
* need to be reflected in the UI.
*/
*/
const
{
actionTypes
}
=
require
(
'../util'
)
;
import
{
actionTypes
}
from
'../util'
;
function
init
()
{
function
init
()
{
return
{
return
{
...
@@ -93,7 +93,7 @@ function isFetchingAnnotations(state) {
...
@@ -93,7 +93,7 @@ function isFetchingAnnotations(state) {
return
state
.
activity
.
activeAnnotationFetches
>
0
;
return
state
.
activity
.
activeAnnotationFetches
>
0
;
}
}
module
.
exports
=
{
export
default
{
init
,
init
,
update
,
update
,
namespace
:
'activity'
,
namespace
:
'activity'
,
...
...
src/sidebar/store/modules/annotations.js
View file @
d8f9baae
...
@@ -3,15 +3,15 @@
...
@@ -3,15 +3,15 @@
* sidebar.
* sidebar.
*/
*/
const
{
createSelector
}
=
require
(
'reselect'
)
;
import
{
createSelector
}
from
'reselect'
;
const
arrayUtil
=
require
(
'../../util/array'
);
import
uiConstants
from
'../../ui-constants'
;
const
metadata
=
require
(
'../../util/annotation-metadata'
);
import
*
as
metadata
from
'../../util/annotation-metadata'
;
const
uiConstants
=
require
(
'../../ui-constants'
);
import
*
as
arrayUtil
from
'../../util/array'
;
import
*
as
util
from
'../util'
;
const
selection
=
require
(
'./selection'
);
import
drafts
from
'./drafts'
;
const
drafts
=
require
(
'./drafts'
);
import
selection
from
'./selection'
;
const
util
=
require
(
'../util'
);
/**
/**
* Return a copy of `current` with all matching annotations in `annotations`
* Return a copy of `current` with all matching annotations in `annotations`
...
@@ -461,7 +461,7 @@ const isWaitingToAnchorAnnotations = createSelector(
...
@@ -461,7 +461,7 @@ const isWaitingToAnchorAnnotations = createSelector(
annotations
=>
annotations
.
some
(
metadata
.
isWaitingToAnchor
)
annotations
=>
annotations
.
some
(
metadata
.
isWaitingToAnchor
)
);
);
module
.
exports
=
{
export
default
{
init
:
init
,
init
:
init
,
namespace
:
'annotations'
,
namespace
:
'annotations'
,
update
:
update
,
update
:
update
,
...
...
src/sidebar/store/modules/direct-linked.js
View file @
d8f9baae
const
util
=
require
(
'../util'
)
;
import
*
as
util
from
'../util'
;
function
init
(
settings
)
{
function
init
(
settings
)
{
return
{
return
{
...
@@ -125,7 +125,7 @@ function clearDirectLinkedIds() {
...
@@ -125,7 +125,7 @@ function clearDirectLinkedIds() {
};
};
}
}
module
.
exports
=
{
export
default
{
init
,
init
,
namespace
:
'directLinked'
,
namespace
:
'directLinked'
,
update
,
update
,
...
...
src/sidebar/store/modules/drafts.js
View file @
d8f9baae
const
metadata
=
require
(
'../../util/annotation-metadata'
)
;
import
*
as
metadata
from
'../../util/annotation-metadata'
;
const
util
=
require
(
'../util'
)
;
import
*
as
util
from
'../util'
;
/**
/**
* The drafts store provides temporary storage for unsaved edits to new or
* The drafts store provides temporary storage for unsaved edits to new or
...
@@ -23,7 +23,7 @@ function init() {
...
@@ -23,7 +23,7 @@ function init() {
* which are the user's draft changes to the annotation. These are returned
* which are the user's draft changes to the annotation. These are returned
* from the drafts store selector by `drafts.getDraft()`.
* from the drafts store selector by `drafts.getDraft()`.
*/
*/
class
Draft
{
export
class
Draft
{
constructor
(
annotation
,
changes
)
{
constructor
(
annotation
,
changes
)
{
this
.
annotation
=
{
id
:
annotation
.
id
,
$tag
:
annotation
.
$tag
};
this
.
annotation
=
{
id
:
annotation
.
id
,
$tag
:
annotation
.
$tag
};
this
.
isPrivate
=
changes
.
isPrivate
;
this
.
isPrivate
=
changes
.
isPrivate
;
...
@@ -94,7 +94,8 @@ function createDraft(annotation, changes) {
...
@@ -94,7 +94,8 @@ function createDraft(annotation, changes) {
*/
*/
function
deleteNewAndEmptyDrafts
()
{
function
deleteNewAndEmptyDrafts
()
{
const
annotations
=
require
(
'./annotations'
);
const
{
default
:
annotations
}
=
require
(
'./annotations'
);
return
(
dispatch
,
getState
)
=>
{
return
(
dispatch
,
getState
)
=>
{
const
newDrafts
=
getState
().
drafts
.
filter
(
draft
=>
{
const
newDrafts
=
getState
().
drafts
.
filter
(
draft
=>
{
return
(
return
(
...
@@ -183,7 +184,7 @@ function unsavedAnnotations(state) {
...
@@ -183,7 +184,7 @@ function unsavedAnnotations(state) {
.
map
(
draft
=>
draft
.
annotation
);
.
map
(
draft
=>
draft
.
annotation
);
}
}
module
.
exports
=
{
export
default
{
init
,
init
,
namespace
:
'drafts'
,
namespace
:
'drafts'
,
update
,
update
,
...
@@ -200,5 +201,4 @@ module.exports = {
...
@@ -200,5 +201,4 @@ module.exports = {
getDraftIfNotEmpty
,
getDraftIfNotEmpty
,
unsavedAnnotations
,
unsavedAnnotations
,
},
},
Draft
,
};
};
src/sidebar/store/modules/frames.js
View file @
d8f9baae
const
{
createSelector
}
=
require
(
'reselect'
)
;
import
{
createSelector
}
from
'reselect'
;
const
util
=
require
(
'../util'
)
;
import
*
as
util
from
'../util'
;
function
init
()
{
function
init
()
{
// The list of frames connected to the sidebar app
// The list of frames connected to the sidebar app
...
@@ -113,7 +113,7 @@ function searchUris(state) {
...
@@ -113,7 +113,7 @@ function searchUris(state) {
},
[]);
},
[]);
}
}
module
.
exports
=
{
export
default
{
init
:
init
,
init
:
init
,
namespace
:
'frames'
,
namespace
:
'frames'
,
update
:
update
,
update
:
update
,
...
...
src/sidebar/store/modules/groups.js
View file @
d8f9baae
const
{
createSelector
}
=
require
(
'reselect'
)
;
import
{
createSelector
}
from
'reselect'
;
const
util
=
require
(
'../util'
);
import
*
as
util
from
'../util'
;
const
session
=
require
(
'./session'
);
import
session
from
'./session'
;
function
init
()
{
function
init
()
{
return
{
return
{
...
@@ -189,7 +190,7 @@ const getInScopeGroups = createSelector(
...
@@ -189,7 +190,7 @@ const getInScopeGroups = createSelector(
groups
=>
groups
.
filter
(
g
=>
g
.
isScopedToUri
)
groups
=>
groups
.
filter
(
g
=>
g
.
isScopedToUri
)
);
);
module
.
exports
=
{
export
default
{
init
,
init
,
namespace
:
'groups'
,
namespace
:
'groups'
,
update
,
update
,
...
...
src/sidebar/store/modules/links.js
View file @
d8f9baae
...
@@ -22,7 +22,7 @@ function updateLinksAction(newLinks) {
...
@@ -22,7 +22,7 @@ function updateLinksAction(newLinks) {
return
{
type
:
'UPDATE_LINKS'
,
newLinks
:
newLinks
};
return
{
type
:
'UPDATE_LINKS'
,
newLinks
:
newLinks
};
}
}
module
.
exports
=
{
export
default
{
init
:
init
,
init
:
init
,
namespace
:
'links'
,
namespace
:
'links'
,
update
:
{
UPDATE_LINKS
:
updateLinks
},
update
:
{
UPDATE_LINKS
:
updateLinks
},
...
...
src/sidebar/store/modules/real-time-updates.js
View file @
d8f9baae
...
@@ -3,13 +3,13 @@
...
@@ -3,13 +3,13 @@
* WebSocket connection to h's real-time API.
* WebSocket connection to h's real-time API.
*/
*/
const
{
createSelector
}
=
require
(
'reselect'
)
;
import
{
createSelector
}
from
'reselect'
;
const
{
actionTypes
}
=
require
(
'../util'
)
;
import
{
actionTypes
}
from
'../util'
;
const
annotations
=
require
(
'./annotations'
)
;
import
annotations
from
'./annotations'
;
const
groups
=
require
(
'./groups'
)
;
import
groups
from
'./groups'
;
const
viewer
=
require
(
'./viewer'
)
;
import
viewer
from
'./viewer'
;
function
init
()
{
function
init
()
{
return
{
return
{
...
@@ -172,7 +172,7 @@ function hasPendingDeletion(state, id) {
...
@@ -172,7 +172,7 @@ function hasPendingDeletion(state, id) {
return
state
.
realTimeUpdates
.
pendingDeletions
.
hasOwnProperty
(
id
);
return
state
.
realTimeUpdates
.
pendingDeletions
.
hasOwnProperty
(
id
);
}
}
module
.
exports
=
{
export
default
{
init
,
init
,
namespace
:
'realTimeUpdates'
,
namespace
:
'realTimeUpdates'
,
update
,
update
,
...
...
src/sidebar/store/modules/selection.js
View file @
d8f9baae
...
@@ -14,15 +14,14 @@
...
@@ -14,15 +14,14 @@
* @property {string} displayName - User's display name
* @property {string} displayName - User's display name
*/
*/
const
{
createSelector
}
=
require
(
'reselect'
)
;
import
{
createSelector
}
from
'reselect'
;
const
immutable
=
require
(
'seamless-immutable'
)
;
import
immutable
from
'seamless-immutable'
;
const
arrayUtil
=
require
(
'../../util/array'
);
import
uiConstants
from
'../../ui-constants'
;
const
metadata
=
require
(
'../../util/annotation-metadata'
);
import
*
as
metadata
from
'../../util/annotation-metadata'
;
const
{
toSet
}
=
require
(
'../../util/array'
);
import
*
as
arrayUtil
from
'../../util/array'
;
const
uiConstants
=
require
(
'../../ui-constants'
);
import
{
toSet
}
from
'../../util/array'
;
import
*
as
util
from
'../util'
;
const
util
=
require
(
'../util'
);
/**
/**
* Default starting tab.
* Default starting tab.
...
@@ -500,7 +499,7 @@ function focusModeUserPrettyName(state) {
...
@@ -500,7 +499,7 @@ function focusModeUserPrettyName(state) {
}
}
}
}
module
.
exports
=
{
export
default
{
init
:
init
,
init
:
init
,
namespace
:
'selection'
,
namespace
:
'selection'
,
update
:
update
,
update
:
update
,
...
...
src/sidebar/store/modules/session.js
View file @
d8f9baae
const
util
=
require
(
'../util'
)
;
import
*
as
util
from
'../util'
;
function
init
()
{
function
init
()
{
/**
/**
...
@@ -65,7 +65,7 @@ function profile(state) {
...
@@ -65,7 +65,7 @@ function profile(state) {
return
state
.
session
;
return
state
.
session
;
}
}
module
.
exports
=
{
export
default
{
init
,
init
,
namespace
:
'session'
,
namespace
:
'session'
,
update
,
update
,
...
...
src/sidebar/store/modules/sidebar-panels.js
View file @
d8f9baae
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
* may be "active" (open) at one time.
* may be "active" (open) at one time.
*/
*/
const
util
=
require
(
'../util'
)
;
import
*
as
util
from
'../util'
;
function
init
()
{
function
init
()
{
return
{
return
{
...
@@ -111,7 +111,7 @@ function isSidebarPanelOpen(state, panelName) {
...
@@ -111,7 +111,7 @@ function isSidebarPanelOpen(state, panelName) {
return
state
.
sidebarPanels
.
activePanelName
===
panelName
;
return
state
.
sidebarPanels
.
activePanelName
===
panelName
;
}
}
module
.
exports
=
{
export
default
{
namespace
:
'sidebarPanels'
,
namespace
:
'sidebarPanels'
,
init
:
init
,
init
:
init
,
update
:
update
,
update
:
update
,
...
...
src/sidebar/store/modules/test/activity-test.js
View file @
d8f9baae
const
createStore
=
require
(
'../../create-store'
)
;
import
createStore
from
'../../create-store'
;
const
activity
=
require
(
'../activity'
)
;
import
activity
from
'../activity'
;
describe
(
'sidebar/store/modules/activity'
,
()
=>
{
describe
(
'sidebar/store/modules/activity'
,
()
=>
{
let
store
;
let
store
;
...
...
src/sidebar/store/modules/test/annotations-test.js
View file @
d8f9baae
const
annotations
=
require
(
'../annotations'
);
import
*
as
fixtures
from
'../../../test/annotation-fixtures'
;
const
createStore
=
require
(
'../../create-store'
);
import
uiConstants
from
'../../../ui-constants'
;
const
drafts
=
require
(
'../drafts'
);
import
*
as
metadata
from
'../../../util/annotation-metadata'
;
const
fixtures
=
require
(
'../../../test/annotation-fixtures'
);
import
createStore
from
'../../create-store'
;
import
annotations
from
'../annotations'
;
const
metadata
=
require
(
'../../../util/annotation-metadata'
);
import
drafts
from
'../drafts'
;
import
groups
from
'../groups'
;
const
groups
=
require
(
'../groups'
);
import
selection
from
'../selection'
;
const
selection
=
require
(
'../selection'
);
import
session
from
'../session'
;
const
session
=
require
(
'../session'
);
import
viewer
from
'../viewer'
;
const
viewer
=
require
(
'../viewer'
);
const
uiConstants
=
require
(
'../../../ui-constants'
);
const
{
actions
,
selectors
}
=
annotations
;
const
{
actions
,
selectors
}
=
annotations
;
...
...
src/sidebar/store/modules/test/direct-linked-test.js
View file @
d8f9baae
const
createStore
=
require
(
'../../create-store'
)
;
import
createStore
from
'../../create-store'
;
const
directLinked
=
require
(
'../direct-linked'
)
;
import
directLinked
from
'../direct-linked'
;
describe
(
'sidebar/store/modules/direct-linked'
,
()
=>
{
describe
(
'sidebar/store/modules/direct-linked'
,
()
=>
{
let
store
;
let
store
;
...
...
src/sidebar/store/modules/test/drafts-test.js
View file @
d8f9baae
const
immutable
=
require
(
'seamless-immutable'
)
;
import
immutable
from
'seamless-immutable'
;
const
drafts
=
require
(
'../drafts'
)
;
import
createStore
from
'../../create-store'
;
const
annotations
=
require
(
'../annotations'
)
;
import
annotations
from
'../annotations'
;
const
selection
=
require
(
'../selection'
)
;
import
drafts
from
'../drafts'
;
const
{
Draft
}
=
require
(
'../drafts'
)
;
import
{
Draft
}
from
'../drafts'
;
const
createStore
=
require
(
'../../create-store'
)
;
import
selection
from
'../selection'
;
const
fixtures
=
immutable
({
const
fixtures
=
immutable
({
draftWithText
:
{
draftWithText
:
{
...
...
src/sidebar/store/modules/test/frames-test.js
View file @
d8f9baae
const
frames
=
require
(
'../frames'
)
;
import
createStore
from
'../../create-store'
;
const
createStore
=
require
(
'../../create-store'
)
;
import
frames
from
'../frames'
;
describe
(
'sidebar/store/modules/frames'
,
function
()
{
describe
(
'sidebar/store/modules/frames'
,
function
()
{
let
store
;
let
store
;
...
...
src/sidebar/store/modules/test/groups-test.js
View file @
d8f9baae
const
immutable
=
require
(
'seamless-immutable'
)
;
import
immutable
from
'seamless-immutable'
;
const
createStore
=
require
(
'../../create-store'
)
;
import
createStore
from
'../../create-store'
;
const
groups
=
require
(
'../groups'
)
;
import
groups
from
'../groups'
;
const
session
=
require
(
'../session'
)
;
import
session
from
'../session'
;
describe
(
'sidebar/store/modules/groups'
,
()
=>
{
describe
(
'sidebar/store/modules/groups'
,
()
=>
{
const
publicGroup
=
immutable
({
const
publicGroup
=
immutable
({
...
...
src/sidebar/store/modules/test/links-test.js
View file @
d8f9baae
const
links
=
require
(
'../links'
)
;
import
links
from
'../links'
;
const
init
=
links
.
init
;
const
init
=
links
.
init
;
const
update
=
links
.
update
.
UPDATE_LINKS
;
const
update
=
links
.
update
.
UPDATE_LINKS
;
...
...
src/sidebar/store/modules/test/real-time-updates-test.js
View file @
d8f9baae
const
createStore
=
require
(
'../../create-store'
);
import
createStore
from
'../../create-store'
;
import
annotations
from
'../annotations'
;
const
annotations
=
require
(
'../annotations'
);
import
groups
from
'../groups'
;
const
groups
=
require
(
'../groups'
);
import
realTimeUpdates
from
'../real-time-updates'
;
const
realTimeUpdates
=
require
(
'../real-time-updates'
);
import
{
$imports
}
from
'../real-time-updates'
;
const
{
$imports
}
=
require
(
'../real-time-updates'
);
import
selection
from
'../selection'
;
const
selection
=
require
(
'../selection'
);
const
{
removeAnnotations
}
=
annotations
.
actions
;
const
{
removeAnnotations
}
=
annotations
.
actions
;
const
{
focusGroup
}
=
groups
.
actions
;
const
{
focusGroup
}
=
groups
.
actions
;
...
@@ -28,13 +27,19 @@ describe('sidebar/store/modules/real-time-updates', () => {
...
@@ -28,13 +27,19 @@ describe('sidebar/store/modules/real-time-updates', () => {
$imports
.
$mock
({
$imports
.
$mock
({
'./annotations'
:
{
'./annotations'
:
{
selectors
:
{
annotationExists
:
fakeAnnotationExists
},
default
:
{
selectors
:
{
annotationExists
:
fakeAnnotationExists
},
},
},
},
'./groups'
:
{
'./groups'
:
{
selectors
:
{
focusedGroupId
:
fakeFocusedGroupId
},
default
:
{
selectors
:
{
focusedGroupId
:
fakeFocusedGroupId
},
},
},
},
'./viewer'
:
{
'./viewer'
:
{
selectors
:
{
isSidebar
:
fakeIsSidebar
},
default
:
{
selectors
:
{
isSidebar
:
fakeIsSidebar
},
},
},
},
});
});
});
});
...
...
src/sidebar/store/modules/test/selection-test.js
View file @
d8f9baae
const
annotations
=
require
(
'../annotations'
)
;
import
uiConstants
from
'../../../ui-constants'
;
const
createStore
=
require
(
'../../create-store'
)
;
import
createStore
from
'../../create-store'
;
const
selection
=
require
(
'../selection'
)
;
import
annotations
from
'../annotations'
;
const
uiConstants
=
require
(
'../../../ui-constants'
)
;
import
selection
from
'../selection'
;
describe
(
'sidebar/store/modules/selection'
,
()
=>
{
describe
(
'sidebar/store/modules/selection'
,
()
=>
{
let
store
;
let
store
;
...
...
src/sidebar/store/modules/test/session-test.js
View file @
d8f9baae
const
createStore
=
require
(
'../../create-store'
)
;
import
createStore
from
'../../create-store'
;
const
session
=
require
(
'../session'
)
;
import
session
from
'../session'
;
const
{
init
}
=
session
;
const
{
init
}
=
session
;
...
...
src/sidebar/store/modules/test/sidebar-panels-test.js
View file @
d8f9baae
const
createStore
=
require
(
'../../create-store'
)
;
import
createStore
from
'../../create-store'
;
const
sidebarPanels
=
require
(
'../sidebar-panels'
)
;
import
sidebarPanels
from
'../sidebar-panels'
;
describe
(
'sidebar/store/modules/sidebar-panels'
,
()
=>
{
describe
(
'sidebar/store/modules/sidebar-panels'
,
()
=>
{
let
store
;
let
store
;
...
...
src/sidebar/store/modules/test/viewer-test.js
View file @
d8f9baae
const
viewer
=
require
(
'../viewer'
)
;
import
createStore
from
'../../create-store'
;
const
createStore
=
require
(
'../../create-store'
)
;
import
viewer
from
'../viewer'
;
describe
(
'store/modules/viewer'
,
function
()
{
describe
(
'store/modules/viewer'
,
function
()
{
let
store
;
let
store
;
...
...
src/sidebar/store/modules/viewer.js
View file @
d8f9baae
const
util
=
require
(
'../util'
)
;
import
*
as
util
from
'../util'
;
/**
/**
* This module defines actions and state related to the display mode of the
* This module defines actions and state related to the display mode of the
...
@@ -50,7 +50,7 @@ function isSidebar(state) {
...
@@ -50,7 +50,7 @@ function isSidebar(state) {
return
state
.
viewer
.
isSidebar
;
return
state
.
viewer
.
isSidebar
;
}
}
module
.
exports
=
{
export
default
{
init
:
init
,
init
:
init
,
namespace
:
'viewer'
,
namespace
:
'viewer'
,
update
:
update
,
update
:
update
,
...
...
src/sidebar/store/test/create-store-test.js
View file @
d8f9baae
const
createStore
=
require
(
'../create-store'
)
;
import
createStore
from
'../create-store'
;
const
A
=
0
;
const
A
=
0
;
...
...
src/sidebar/store/test/debug-middleware-test.js
View file @
d8f9baae
/* eslint-disable no-console */
/* eslint-disable no-console */
const
redux
=
require
(
'redux'
)
;
import
*
as
redux
from
'redux'
;
const
debugMiddleware
=
require
(
'../debug-middleware'
)
;
import
debugMiddleware
from
'../debug-middleware'
;
function
id
(
state
)
{
function
id
(
state
)
{
return
state
;
return
state
;
...
...
src/sidebar/store/test/index-test.js
View file @
d8f9baae
const
immutable
=
require
(
'seamless-immutable'
)
;
import
immutable
from
'seamless-immutable'
;
const
storeFactory
=
require
(
'../index'
)
;
import
*
as
annotationFixtures
from
'../../test/annotation-fixtures'
;
const
annotationFixtures
=
require
(
'../../test/annotation-fixtures'
)
;
import
uiConstants
from
'../../ui-constants'
;
const
uiConstants
=
require
(
'../../ui-constants'
)
;
import
storeFactory
from
'../index'
;
const
defaultAnnotation
=
annotationFixtures
.
defaultAnnotation
;
const
defaultAnnotation
=
annotationFixtures
.
defaultAnnotation
;
const
newAnnotation
=
annotationFixtures
.
newAnnotation
;
const
newAnnotation
=
annotationFixtures
.
newAnnotation
;
...
...
src/sidebar/store/test/use-store-test.js
View file @
d8f9baae
const
{
mount
}
=
require
(
'enzyme'
)
;
import
{
mount
}
from
'enzyme'
;
const
{
createStore
}
=
require
(
'redux'
)
;
import
{
createElement
}
from
'preact'
;
const
{
createElement
}
=
require
(
'preact'
)
;
import
{
act
}
from
'preact/test-utils'
;
const
{
act
}
=
require
(
'preact/test-utils'
)
;
import
{
createStore
}
from
'redux'
;
const
useStore
=
require
(
'../use-store'
);
import
useStore
,
{
$imports
}
from
'../use-store'
;
const
{
$imports
}
=
useStore
;
const
initialState
=
{
value
:
10
,
otherValue
:
20
};
const
initialState
=
{
value
:
10
,
otherValue
:
20
};
const
reducer
=
(
state
=
initialState
,
action
)
=>
{
const
reducer
=
(
state
=
initialState
,
action
)
=>
{
...
...
src/sidebar/store/test/util-test.js
View file @
d8f9baae
const
util
=
require
(
'../util'
)
;
import
*
as
util
from
'../util'
;
const
fixtures
=
{
const
fixtures
=
{
update
:
{
update
:
{
...
...
src/sidebar/store/use-store.js
View file @
d8f9baae
/* global process */
/* global process */
const
shallowEqual
=
require
(
'shallowequal'
)
;
import
{
useEffect
,
useRef
,
useReducer
}
from
'preact/hooks'
;
const
{
useEffect
,
useRef
,
useReducer
}
=
require
(
'preact/hooks'
)
;
import
shallowEqual
from
'shallowequal'
;
const
{
useService
}
=
require
(
'../util/service-context'
)
;
import
warnOnce
from
'../../shared/warn-once'
;
const
warnOnce
=
require
(
'../../shared/warn-once'
)
;
import
{
useService
}
from
'../util/service-context'
;
/**
/**
* Hook for accessing state or actions from the store inside a component.
* Hook for accessing state or actions from the store inside a component.
...
@@ -35,7 +35,7 @@ const warnOnce = require('../../shared/warn-once');
...
@@ -35,7 +35,7 @@ const warnOnce = require('../../shared/warn-once');
* and/or actions extracted from the store.
* and/or actions extracted from the store.
* @return {T} - The result of `callback(store)`
* @return {T} - The result of `callback(store)`
*/
*/
function
useStore
(
callback
)
{
export
default
function
useStore
(
callback
)
{
const
store
=
useService
(
'store'
);
const
store
=
useService
(
'store'
);
// Store the last-used callback in a ref so we can access it in the effect
// Store the last-used callback in a ref so we can access it in the effect
...
@@ -84,5 +84,3 @@ function useStore(callback) {
...
@@ -84,5 +84,3 @@ function useStore(callback) {
return
lastResult
.
current
;
return
lastResult
.
current
;
}
}
module
.
exports
=
useStore
;
src/sidebar/store/util.js
View file @
d8f9baae
/**
/**
* Return an object where each key in `updateFns` is mapped to the key itself.
* Return an object where each key in `updateFns` is mapped to the key itself.
*/
*/
function
actionTypes
(
updateFns
)
{
export
function
actionTypes
(
updateFns
)
{
return
Object
.
keys
(
updateFns
).
reduce
(
function
(
types
,
key
)
{
return
Object
.
keys
(
updateFns
).
reduce
(
function
(
types
,
key
)
{
types
[
key
]
=
key
;
types
[
key
]
=
key
;
return
types
;
return
types
;
...
@@ -15,7 +15,7 @@ function actionTypes(updateFns) {
...
@@ -15,7 +15,7 @@ function actionTypes(updateFns) {
* @param {Object} actionToUpdateFn - Object mapping action names to update
* @param {Object} actionToUpdateFn - Object mapping action names to update
* functions.
* functions.
*/
*/
function
createReducer
(
actionToUpdateFn
)
{
export
function
createReducer
(
actionToUpdateFn
)
{
return
(
state
=
{},
action
)
=>
{
return
(
state
=
{},
action
)
=>
{
const
fn
=
actionToUpdateFn
[
action
.
type
];
const
fn
=
actionToUpdateFn
[
action
.
type
];
if
(
!
fn
)
{
if
(
!
fn
)
{
...
@@ -39,7 +39,7 @@ function createReducer(actionToUpdateFn) {
...
@@ -39,7 +39,7 @@ function createReducer(actionToUpdateFn) {
* level. The keys to this object are functions that call the original
* level. The keys to this object are functions that call the original
* selectors with the `state` argument set to the current value of `getState()`.
* selectors with the `state` argument set to the current value of `getState()`.
*/
*/
function
bindSelectors
(
namespaces
,
getState
)
{
export
function
bindSelectors
(
namespaces
,
getState
)
{
const
totalSelectors
=
{};
const
totalSelectors
=
{};
Object
.
keys
(
namespaces
).
forEach
(
namespace
=>
{
Object
.
keys
(
namespaces
).
forEach
(
namespace
=>
{
const
selectors
=
namespaces
[
namespace
].
selectors
;
const
selectors
=
namespaces
[
namespace
].
selectors
;
...
@@ -53,9 +53,3 @@ function bindSelectors(namespaces, getState) {
...
@@ -53,9 +53,3 @@ function bindSelectors(namespaces, getState) {
});
});
return
totalSelectors
;
return
totalSelectors
;
}
}
module
.
exports
=
{
actionTypes
,
bindSelectors
,
createReducer
,
};
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