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
5b9b6efd
Unverified
Commit
5b9b6efd
authored
Feb 09, 2018
by
Sheetal Umesh Kumar
Committed by
GitHub
Feb 09, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #662 from hypothesis/refactor-selector-export
Refactor export of bound selectors from Redux store
parents
d78a4e4b
dcf77f92
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
48 additions
and
52 deletions
+48
-52
annotation-ui.js
src/sidebar/annotation-ui.js
+8
-17
annotations.js
src/sidebar/reducers/annotations.js
+6
-5
frames.js
src/sidebar/reducers/frames.js
+4
-3
links.js
src/sidebar/reducers/links.js
+1
-0
selection.js
src/sidebar/reducers/selection.js
+4
-3
session.js
src/sidebar/reducers/session.js
+4
-3
annotations-test.js
src/sidebar/reducers/test/annotations-test.js
+6
-6
frames-test.js
src/sidebar/reducers/test/frames-test.js
+7
-6
session-test.js
src/sidebar/reducers/test/session-test.js
+2
-3
viewer-test.js
src/sidebar/reducers/test/viewer-test.js
+3
-4
viewer.js
src/sidebar/reducers/viewer.js
+3
-2
No files found.
src/sidebar/annotation-ui.js
View file @
5b9b6efd
...
...
@@ -109,23 +109,14 @@ module.exports = function ($rootScope, settings) {
// selection.isAnnotationSelected(annotationUI.getState(), id)
// You can use:
// annotationUI.isAnnotationSelected(id)
var
selectors
=
util
.
bindSelectors
({
isAnnotationSelected
:
selectionReducer
.
isAnnotationSelected
,
hasSelectedAnnotations
:
selectionReducer
.
hasSelectedAnnotations
,
annotationExists
:
annotationsReducer
.
annotationExists
,
findAnnotationByID
:
annotationsReducer
.
findAnnotationByID
,
findIDsForTags
:
annotationsReducer
.
findIDsForTags
,
savedAnnotations
:
annotationsReducer
.
savedAnnotations
,
frames
:
framesReducer
.
frames
,
searchUris
:
framesReducer
.
searchUris
,
isSidebar
:
viewerReducer
.
isSidebar
,
isFeatureEnabled
:
sessionReducer
.
isFeatureEnabled
,
profile
:
sessionReducer
.
profile
,
},
store
.
getState
);
var
selectors
=
util
.
bindSelectors
(
Object
.
assign
({},
annotationsReducer
.
selectors
,
framesReducer
.
selectors
,
linksReducer
.
selectors
,
selectionReducer
.
selectors
,
sessionReducer
.
selectors
,
viewerReducer
.
selectors
),
store
.
getState
);
return
Object
.
assign
(
store
,
actionCreators
,
selectors
);
};
src/sidebar/reducers/annotations.js
View file @
5b9b6efd
...
...
@@ -389,9 +389,10 @@ module.exports = {
unhideAnnotation
:
unhideAnnotation
,
},
// Selectors
annotationExists
:
annotationExists
,
findAnnotationByID
:
findAnnotationByID
,
findIDsForTags
:
findIDsForTags
,
savedAnnotations
:
savedAnnotations
,
selectors
:
{
annotationExists
,
findAnnotationByID
,
findIDsForTags
,
savedAnnotations
,
},
};
src/sidebar/reducers/frames.js
View file @
5b9b6efd
...
...
@@ -111,7 +111,8 @@ module.exports = {
updateFrameAnnotationFetchStatus
:
updateFrameAnnotationFetchStatus
,
},
// Selectors
frames
:
frames
,
searchUris
:
searchUris
,
selectors
:
{
frames
,
searchUris
,
},
};
src/sidebar/reducers/links.js
View file @
5b9b6efd
...
...
@@ -24,4 +24,5 @@ module.exports = {
init
:
init
,
update
:
{
UPDATE_LINKS
:
updateLinks
},
actions
:
{
updateLinks
:
updateLinksAction
},
selectors
:
{},
};
src/sidebar/reducers/selection.js
View file @
5b9b6efd
...
...
@@ -311,7 +311,8 @@ module.exports = {
toggleSelectedAnnotations
:
toggleSelectedAnnotations
,
},
// Selectors
hasSelectedAnnotations
:
hasSelectedAnnotations
,
isAnnotationSelected
:
isAnnotationSelected
,
selectors
:
{
hasSelectedAnnotations
,
isAnnotationSelected
,
},
};
src/sidebar/reducers/session.js
View file @
5b9b6efd
...
...
@@ -73,7 +73,8 @@ module.exports = {
updateSession
,
},
// Selectors
selectors
:
{
isFeatureEnabled
,
profile
,
},
};
src/sidebar/reducers/test/annotations-test.js
View file @
5b9b6efd
...
...
@@ -9,7 +9,7 @@ var fixtures = require('../../test/annotation-fixtures');
var
util
=
require
(
'../util'
);
var
unroll
=
require
(
'../../../shared/test/util'
).
unroll
;
var
actions
=
annotations
.
ac
tions
;
var
{
actions
,
selectors
}
=
annota
tions
;
/**
* Create a Redux store which only handles annotation actions.
...
...
@@ -26,7 +26,7 @@ function createStore() {
describe
(
'annotations reducer'
,
function
()
{
describe
(
'#savedAnnotations'
,
function
()
{
var
savedAnnotations
=
annotation
s
.
savedAnnotations
;
var
savedAnnotations
=
selector
s
.
savedAnnotations
;
it
(
'returns annotations which are saved'
,
function
()
{
var
state
=
{
...
...
@@ -37,7 +37,7 @@ describe('annotations reducer', function () {
});
describe
(
'#findIDsForTags'
,
function
()
{
var
findIDsForTags
=
annotation
s
.
findIDsForTags
;
var
findIDsForTags
=
selector
s
.
findIDsForTags
;
it
(
'returns the IDs corresponding to the provided local tags'
,
function
()
{
var
ann
=
fixtures
.
defaultAnnotation
();
...
...
@@ -64,7 +64,7 @@ describe('annotations reducer', function () {
store
.
dispatch
(
actions
.
addAnnotations
([
ann
]));
store
.
dispatch
(
actions
.
hideAnnotation
(
ann
.
id
));
var
storeAnn
=
annotation
s
.
findAnnotationByID
(
store
.
getState
(),
ann
.
id
);
var
storeAnn
=
selector
s
.
findAnnotationByID
(
store
.
getState
(),
ann
.
id
);
assert
.
equal
(
storeAnn
.
hidden
,
true
);
});
});
...
...
@@ -77,7 +77,7 @@ describe('annotations reducer', function () {
store
.
dispatch
(
actions
.
addAnnotations
([
ann
]));
store
.
dispatch
(
actions
.
unhideAnnotation
(
ann
.
id
));
var
storeAnn
=
annotation
s
.
findAnnotationByID
(
store
.
getState
(),
ann
.
id
);
var
storeAnn
=
selector
s
.
findAnnotationByID
(
store
.
getState
(),
ann
.
id
);
assert
.
equal
(
storeAnn
.
hidden
,
false
);
});
});
...
...
@@ -92,7 +92,7 @@ describe('annotations reducer', function () {
store
.
dispatch
(
actions
.
addAnnotations
([
ann
]));
store
.
dispatch
(
actions
.
updateFlagStatus
(
ann
.
id
,
testCase
.
nowFlagged
));
var
storeAnn
=
annotation
s
.
findAnnotationByID
(
store
.
getState
(),
ann
.
id
);
var
storeAnn
=
selector
s
.
findAnnotationByID
(
store
.
getState
(),
ann
.
id
);
assert
.
equal
(
storeAnn
.
flagged
,
testCase
.
nowFlagged
);
assert
.
deepEqual
(
storeAnn
.
moderation
,
testCase
.
newModeration
);
},
[{
...
...
src/sidebar/reducers/test/frames-test.js
View file @
5b9b6efd
...
...
@@ -7,6 +7,7 @@ var unroll = require('../../../shared/test/util').unroll;
var
actions
=
frames
.
actions
;
var
update
=
util
.
createReducer
(
frames
.
update
);
var
selectors
=
frames
.
selectors
;
function
init
()
{
return
Object
.
assign
({},
frames
.
init
(),
session
.
init
());
...
...
@@ -17,7 +18,7 @@ describe('frames reducer', function () {
it
(
'adds the frame to the list of connected frames'
,
function
()
{
var
frame
=
{
uri
:
'http://example.com'
};
var
state
=
update
(
init
(),
actions
.
connectFrame
(
frame
));
assert
.
deepEqual
(
frame
s
.
frames
(
state
),
[
frame
]);
assert
.
deepEqual
(
selector
s
.
frames
(
state
),
[
frame
]);
});
});
...
...
@@ -28,9 +29,9 @@ describe('frames reducer', function () {
frameList
.
forEach
(
function
(
frame
)
{
state
=
update
(
state
,
actions
.
connectFrame
(
frame
));
});
assert
.
deepEqual
(
frame
s
.
frames
(
state
),
frameList
);
assert
.
deepEqual
(
selector
s
.
frames
(
state
),
frameList
);
var
updatedState
=
update
(
state
,
actions
.
destroyFrame
(
frameList
[
0
]));
assert
.
deepEqual
(
frame
s
.
frames
(
updatedState
),
[
frameList
[
1
]]);
assert
.
deepEqual
(
selector
s
.
frames
(
updatedState
),
[
frameList
[
1
]]);
});
});
...
...
@@ -46,7 +47,7 @@ describe('frames reducer', function () {
var
connectedState
=
update
(
init
(),
actions
.
connectFrame
(
frame
));
var
updatedState
=
update
(
connectedState
,
actions
.
updateFrameAnnotationFetchStatus
(
frame
.
uri
,
true
));
assert
.
deepEqual
(
frame
s
.
frames
(
updatedState
),
[
expectedFrame
]);
assert
.
deepEqual
(
selector
s
.
frames
(
updatedState
),
[
expectedFrame
]);
});
it
(
'does not update the isAnnotationFetchComplete status of the wrong frame'
,
function
()
{
...
...
@@ -56,7 +57,7 @@ describe('frames reducer', function () {
var
connectedState
=
update
(
init
(),
actions
.
connectFrame
(
frame
));
var
updatedState
=
update
(
connectedState
,
actions
.
updateFrameAnnotationFetchStatus
(
'http://anotherexample.com'
,
true
));
assert
.
deepEqual
(
frame
s
.
frames
(
updatedState
),
[
frame
]);
assert
.
deepEqual
(
selector
s
.
frames
(
updatedState
),
[
frame
]);
});
});
...
...
@@ -69,7 +70,7 @@ describe('frames reducer', function () {
testCase
.
frames
.
forEach
(
function
(
frame
)
{
state
=
update
(
state
,
actions
.
connectFrame
(
frame
));
});
assert
.
deepEqual
(
frame
s
.
searchUris
(
state
),
testCase
.
searchUris
);
assert
.
deepEqual
(
selector
s
.
searchUris
(
state
),
testCase
.
searchUris
);
},[{
when
:
'one HTML frame'
,
frames
:
[{
...
...
src/sidebar/reducers/test/session-test.js
View file @
5b9b6efd
...
...
@@ -4,8 +4,7 @@ var session = require('../session');
var
util
=
require
(
'../util'
);
var
init
=
session
.
init
;
var
actions
=
session
.
actions
;
var
{
init
,
actions
,
selectors
}
=
session
;
var
update
=
util
.
createReducer
(
session
.
update
);
describe
(
'sidebar.reducers.session'
,
function
()
{
...
...
@@ -21,7 +20,7 @@ describe('sidebar.reducers.session', function () {
it
(
"returns the user's profile"
,
()
=>
{
var
newSession
=
Object
.
assign
(
init
(),
{
userid
:
'john'
});
var
state
=
update
(
init
(),
actions
.
updateSession
(
newSession
));
assert
.
equal
(
se
ssion
.
profile
(
state
),
newSession
);
assert
.
equal
(
se
lectors
.
profile
(
state
),
newSession
);
});
});
});
src/sidebar/reducers/test/viewer-test.js
View file @
5b9b6efd
...
...
@@ -4,20 +4,19 @@ var viewer = require('../viewer');
var
util
=
require
(
'../util'
);
var
init
=
viewer
.
init
;
var
actions
=
viewer
.
actions
;
var
{
init
,
actions
,
selectors
}
=
viewer
;
var
update
=
util
.
createReducer
(
viewer
.
update
);
describe
(
'viewer reducer'
,
function
()
{
describe
(
'#setAppIsSidebar'
,
function
()
{
it
(
'sets a flag indicating that the app is the sidebar'
,
function
()
{
var
state
=
update
(
init
(),
actions
.
setAppIsSidebar
(
true
));
assert
.
isTrue
(
viewer
.
isSidebar
(
state
));
assert
.
isTrue
(
selectors
.
isSidebar
(
state
));
});
it
(
'sets a flag indicating that the app is not the sidebar'
,
function
()
{
var
state
=
update
(
init
(),
actions
.
setAppIsSidebar
(
false
));
assert
.
isFalse
(
viewer
.
isSidebar
(
state
));
assert
.
isFalse
(
selectors
.
isSidebar
(
state
));
});
});
});
src/sidebar/reducers/viewer.js
View file @
5b9b6efd
...
...
@@ -57,6 +57,7 @@ module.exports = {
setShowHighlights
:
setShowHighlights
,
},
// Selectors
isSidebar
:
isSidebar
,
selectors
:
{
isSidebar
,
},
};
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