Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scratch-www
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
scratch-www
Commits
95766fd6
Commit
95766fd6
authored
May 10, 2021
by
Paul Kaplan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add clear to infinite list, fixup tests
parent
cb7c60e8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
5 deletions
+20
-5
src/redux/infinite-list.js
src/redux/infinite-list.js
+6
-4
test/unit/redux/infinite-list.test.js
test/unit/redux/infinite-list.test.js
+14
-1
No files found.
src/redux/infinite-list.js
View file @
95766fd6
...
...
@@ -35,17 +35,16 @@
*/
const
InfiniteList
=
key
=>
{
const
initialState
=
{
const
getInitialState
=
()
=>
(
{
items
:
[],
offset
:
0
,
error
:
null
,
loading
:
true
,
moreToLoad
:
false
};
}
)
;
const
reducer
=
(
state
,
action
)
=>
{
if
(
typeof
state
===
'
undefined
'
)
{
state
=
initialState
;
state
=
getInitialState
()
;
}
switch
(
action
.
type
)
{
...
...
@@ -88,6 +87,8 @@ const InfiniteList = key => {
loading
:
false
,
moreToLoad
:
false
};
case
`
${
key
}
_CLEAR`
:
return
getInitialState
();
default
:
return
state
;
}
...
...
@@ -100,6 +101,7 @@ const InfiniteList = key => {
error
:
error
=>
({
type
:
`
${
key
}
_ERROR`
,
error
}),
loading
:
()
=>
({
type
:
`
${
key
}
_LOADING`
}),
append
:
(
items
,
moreToLoad
)
=>
({
type
:
`
${
key
}
_APPEND`
,
items
,
moreToLoad
}),
clear
:
()
=>
({
type
:
`
${
key
}
_CLEAR`
}),
/**
* Load more action returns a thunk. It takes a function to call to get more items.
...
...
test/unit/redux/infinite-list.test.js
View file @
95766fd6
...
...
@@ -104,6 +104,19 @@ describe('Infinite List redux module', () => {
});
});
describe
(
'
CLEAR
'
,
()
=>
{
test
(
'
resets everything back to the initial state
'
,
()
=>
{
const
state
=
{
error
:
new
Error
(),
items
:
[
1
,
2
,
3
],
loading
:
'
something not initial
'
,
moreToLoad
:
'
something not initial
'
};
const
newState
=
module
.
reducer
(
state
,
module
.
actions
.
clear
());
expect
(
newState
).
toEqual
(
initialState
);
});
});
describe
(
'
ERROR
'
,
()
=>
{
let
action
;
let
error
=
new
Error
();
...
...
@@ -167,7 +180,7 @@ describe('Infinite List redux module', () => {
describe
(
'
selector
'
,
()
=>
{
test
(
'
will return the slice of state defined by the key
'
,
()
=>
{
const
state
=
{
[
module
.
key
]:
module
.
reducer
(
undefined
,
{})
// eslint-disable-line no-undefined
[
module
.
key
]:
initialState
};
expect
(
module
.
selector
(
state
)).
toBe
(
initialState
);
});
...
...
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