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) {
...
@@ -109,23 +109,14 @@ module.exports = function ($rootScope, settings) {
// selection.isAnnotationSelected(annotationUI.getState(), id)
// selection.isAnnotationSelected(annotationUI.getState(), id)
// You can use:
// You can use:
// annotationUI.isAnnotationSelected(id)
// annotationUI.isAnnotationSelected(id)
var
selectors
=
util
.
bindSelectors
({
var
selectors
=
util
.
bindSelectors
(
Object
.
assign
({},
isAnnotationSelected
:
selectionReducer
.
isAnnotationSelected
,
annotationsReducer
.
selectors
,
hasSelectedAnnotations
:
selectionReducer
.
hasSelectedAnnotations
,
framesReducer
.
selectors
,
linksReducer
.
selectors
,
annotationExists
:
annotationsReducer
.
annotationExists
,
selectionReducer
.
selectors
,
findAnnotationByID
:
annotationsReducer
.
findAnnotationByID
,
sessionReducer
.
selectors
,
findIDsForTags
:
annotationsReducer
.
findIDsForTags
,
viewerReducer
.
selectors
savedAnnotations
:
annotationsReducer
.
savedAnnotations
,
),
store
.
getState
);
frames
:
framesReducer
.
frames
,
searchUris
:
framesReducer
.
searchUris
,
isSidebar
:
viewerReducer
.
isSidebar
,
isFeatureEnabled
:
sessionReducer
.
isFeatureEnabled
,
profile
:
sessionReducer
.
profile
,
},
store
.
getState
);
return
Object
.
assign
(
store
,
actionCreators
,
selectors
);
return
Object
.
assign
(
store
,
actionCreators
,
selectors
);
};
};
src/sidebar/reducers/annotations.js
View file @
5b9b6efd
...
@@ -389,9 +389,10 @@ module.exports = {
...
@@ -389,9 +389,10 @@ module.exports = {
unhideAnnotation
:
unhideAnnotation
,
unhideAnnotation
:
unhideAnnotation
,
},
},
// Selectors
selectors
:
{
annotationExists
:
annotationExists
,
annotationExists
,
findAnnotationByID
:
findAnnotationByID
,
findAnnotationByID
,
findIDsForTags
:
findIDsForTags
,
findIDsForTags
,
savedAnnotations
:
savedAnnotations
,
savedAnnotations
,
},
};
};
src/sidebar/reducers/frames.js
View file @
5b9b6efd
...
@@ -111,7 +111,8 @@ module.exports = {
...
@@ -111,7 +111,8 @@ module.exports = {
updateFrameAnnotationFetchStatus
:
updateFrameAnnotationFetchStatus
,
updateFrameAnnotationFetchStatus
:
updateFrameAnnotationFetchStatus
,
},
},
// Selectors
selectors
:
{
frames
:
frames
,
frames
,
searchUris
:
searchUris
,
searchUris
,
},
};
};
src/sidebar/reducers/links.js
View file @
5b9b6efd
...
@@ -24,4 +24,5 @@ module.exports = {
...
@@ -24,4 +24,5 @@ module.exports = {
init
:
init
,
init
:
init
,
update
:
{
UPDATE_LINKS
:
updateLinks
},
update
:
{
UPDATE_LINKS
:
updateLinks
},
actions
:
{
updateLinks
:
updateLinksAction
},
actions
:
{
updateLinks
:
updateLinksAction
},
selectors
:
{},
};
};
src/sidebar/reducers/selection.js
View file @
5b9b6efd
...
@@ -311,7 +311,8 @@ module.exports = {
...
@@ -311,7 +311,8 @@ module.exports = {
toggleSelectedAnnotations
:
toggleSelectedAnnotations
,
toggleSelectedAnnotations
:
toggleSelectedAnnotations
,
},
},
// Selectors
selectors
:
{
hasSelectedAnnotations
:
hasSelectedAnnotations
,
hasSelectedAnnotations
,
isAnnotationSelected
:
isAnnotationSelected
,
isAnnotationSelected
,
},
};
};
src/sidebar/reducers/session.js
View file @
5b9b6efd
...
@@ -73,7 +73,8 @@ module.exports = {
...
@@ -73,7 +73,8 @@ module.exports = {
updateSession
,
updateSession
,
},
},
// Selectors
selectors
:
{
isFeatureEnabled
,
isFeatureEnabled
,
profile
,
profile
,
},
};
};
src/sidebar/reducers/test/annotations-test.js
View file @
5b9b6efd
...
@@ -9,7 +9,7 @@ var fixtures = require('../../test/annotation-fixtures');
...
@@ -9,7 +9,7 @@ var fixtures = require('../../test/annotation-fixtures');
var
util
=
require
(
'../util'
);
var
util
=
require
(
'../util'
);
var
unroll
=
require
(
'../../../shared/test/util'
).
unroll
;
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.
* Create a Redux store which only handles annotation actions.
...
@@ -26,7 +26,7 @@ function createStore() {
...
@@ -26,7 +26,7 @@ function createStore() {
describe
(
'annotations reducer'
,
function
()
{
describe
(
'annotations reducer'
,
function
()
{
describe
(
'#savedAnnotations'
,
function
()
{
describe
(
'#savedAnnotations'
,
function
()
{
var
savedAnnotations
=
annotation
s
.
savedAnnotations
;
var
savedAnnotations
=
selector
s
.
savedAnnotations
;
it
(
'returns annotations which are saved'
,
function
()
{
it
(
'returns annotations which are saved'
,
function
()
{
var
state
=
{
var
state
=
{
...
@@ -37,7 +37,7 @@ describe('annotations reducer', function () {
...
@@ -37,7 +37,7 @@ describe('annotations reducer', function () {
});
});
describe
(
'#findIDsForTags'
,
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
()
{
it
(
'returns the IDs corresponding to the provided local tags'
,
function
()
{
var
ann
=
fixtures
.
defaultAnnotation
();
var
ann
=
fixtures
.
defaultAnnotation
();
...
@@ -64,7 +64,7 @@ describe('annotations reducer', function () {
...
@@ -64,7 +64,7 @@ describe('annotations reducer', function () {
store
.
dispatch
(
actions
.
addAnnotations
([
ann
]));
store
.
dispatch
(
actions
.
addAnnotations
([
ann
]));
store
.
dispatch
(
actions
.
hideAnnotation
(
ann
.
id
));
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
);
assert
.
equal
(
storeAnn
.
hidden
,
true
);
});
});
});
});
...
@@ -77,7 +77,7 @@ describe('annotations reducer', function () {
...
@@ -77,7 +77,7 @@ describe('annotations reducer', function () {
store
.
dispatch
(
actions
.
addAnnotations
([
ann
]));
store
.
dispatch
(
actions
.
addAnnotations
([
ann
]));
store
.
dispatch
(
actions
.
unhideAnnotation
(
ann
.
id
));
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
);
assert
.
equal
(
storeAnn
.
hidden
,
false
);
});
});
});
});
...
@@ -92,7 +92,7 @@ describe('annotations reducer', function () {
...
@@ -92,7 +92,7 @@ describe('annotations reducer', function () {
store
.
dispatch
(
actions
.
addAnnotations
([
ann
]));
store
.
dispatch
(
actions
.
addAnnotations
([
ann
]));
store
.
dispatch
(
actions
.
updateFlagStatus
(
ann
.
id
,
testCase
.
nowFlagged
));
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
.
equal
(
storeAnn
.
flagged
,
testCase
.
nowFlagged
);
assert
.
deepEqual
(
storeAnn
.
moderation
,
testCase
.
newModeration
);
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;
...
@@ -7,6 +7,7 @@ var unroll = require('../../../shared/test/util').unroll;
var
actions
=
frames
.
actions
;
var
actions
=
frames
.
actions
;
var
update
=
util
.
createReducer
(
frames
.
update
);
var
update
=
util
.
createReducer
(
frames
.
update
);
var
selectors
=
frames
.
selectors
;
function
init
()
{
function
init
()
{
return
Object
.
assign
({},
frames
.
init
(),
session
.
init
());
return
Object
.
assign
({},
frames
.
init
(),
session
.
init
());
...
@@ -17,7 +18,7 @@ describe('frames reducer', function () {
...
@@ -17,7 +18,7 @@ describe('frames reducer', function () {
it
(
'adds the frame to the list of connected frames'
,
function
()
{
it
(
'adds the frame to the list of connected frames'
,
function
()
{
var
frame
=
{
uri
:
'http://example.com'
};
var
frame
=
{
uri
:
'http://example.com'
};
var
state
=
update
(
init
(),
actions
.
connectFrame
(
frame
));
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 () {
...
@@ -28,9 +29,9 @@ describe('frames reducer', function () {
frameList
.
forEach
(
function
(
frame
)
{
frameList
.
forEach
(
function
(
frame
)
{
state
=
update
(
state
,
actions
.
connectFrame
(
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
]));
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 () {
...
@@ -46,7 +47,7 @@ describe('frames reducer', function () {
var
connectedState
=
update
(
init
(),
actions
.
connectFrame
(
frame
));
var
connectedState
=
update
(
init
(),
actions
.
connectFrame
(
frame
));
var
updatedState
=
update
(
connectedState
,
var
updatedState
=
update
(
connectedState
,
actions
.
updateFrameAnnotationFetchStatus
(
frame
.
uri
,
true
));
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
()
{
it
(
'does not update the isAnnotationFetchComplete status of the wrong frame'
,
function
()
{
...
@@ -56,7 +57,7 @@ describe('frames reducer', function () {
...
@@ -56,7 +57,7 @@ describe('frames reducer', function () {
var
connectedState
=
update
(
init
(),
actions
.
connectFrame
(
frame
));
var
connectedState
=
update
(
init
(),
actions
.
connectFrame
(
frame
));
var
updatedState
=
update
(
connectedState
,
var
updatedState
=
update
(
connectedState
,
actions
.
updateFrameAnnotationFetchStatus
(
'http://anotherexample.com'
,
true
));
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 () {
...
@@ -69,7 +70,7 @@ describe('frames reducer', function () {
testCase
.
frames
.
forEach
(
function
(
frame
)
{
testCase
.
frames
.
forEach
(
function
(
frame
)
{
state
=
update
(
state
,
actions
.
connectFrame
(
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'
,
when
:
'one HTML frame'
,
frames
:
[{
frames
:
[{
...
...
src/sidebar/reducers/test/session-test.js
View file @
5b9b6efd
...
@@ -4,8 +4,7 @@ var session = require('../session');
...
@@ -4,8 +4,7 @@ var session = require('../session');
var
util
=
require
(
'../util'
);
var
util
=
require
(
'../util'
);
var
init
=
session
.
init
;
var
{
init
,
actions
,
selectors
}
=
session
;
var
actions
=
session
.
actions
;
var
update
=
util
.
createReducer
(
session
.
update
);
var
update
=
util
.
createReducer
(
session
.
update
);
describe
(
'sidebar.reducers.session'
,
function
()
{
describe
(
'sidebar.reducers.session'
,
function
()
{
...
@@ -21,7 +20,7 @@ describe('sidebar.reducers.session', function () {
...
@@ -21,7 +20,7 @@ describe('sidebar.reducers.session', function () {
it
(
"returns the user's profile"
,
()
=>
{
it
(
"returns the user's profile"
,
()
=>
{
var
newSession
=
Object
.
assign
(
init
(),
{
userid
:
'john'
});
var
newSession
=
Object
.
assign
(
init
(),
{
userid
:
'john'
});
var
state
=
update
(
init
(),
actions
.
updateSession
(
newSession
));
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');
...
@@ -4,20 +4,19 @@ var viewer = require('../viewer');
var
util
=
require
(
'../util'
);
var
util
=
require
(
'../util'
);
var
init
=
viewer
.
init
;
var
{
init
,
actions
,
selectors
}
=
viewer
;
var
actions
=
viewer
.
actions
;
var
update
=
util
.
createReducer
(
viewer
.
update
);
var
update
=
util
.
createReducer
(
viewer
.
update
);
describe
(
'viewer reducer'
,
function
()
{
describe
(
'viewer reducer'
,
function
()
{
describe
(
'#setAppIsSidebar'
,
function
()
{
describe
(
'#setAppIsSidebar'
,
function
()
{
it
(
'sets a flag indicating that the app is the sidebar'
,
function
()
{
it
(
'sets a flag indicating that the app is the sidebar'
,
function
()
{
var
state
=
update
(
init
(),
actions
.
setAppIsSidebar
(
true
));
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
()
{
it
(
'sets a flag indicating that the app is not the sidebar'
,
function
()
{
var
state
=
update
(
init
(),
actions
.
setAppIsSidebar
(
false
));
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 = {
...
@@ -57,6 +57,7 @@ module.exports = {
setShowHighlights
:
setShowHighlights
,
setShowHighlights
:
setShowHighlights
,
},
},
// Selectors
selectors
:
{
isSidebar
:
isSidebar
,
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