Commit f4745253 authored by Paul Kaplan's avatar Paul Kaplan

Remove unused loadMore functionality from infinite list because it was overly...

Remove unused loadMore functionality from infinite list because it was overly specific, now it is no longer being used by any component
parent 600e5846
...@@ -16,14 +16,6 @@ ...@@ -16,14 +16,6 @@
* the next state. * the next state.
*/ */
/**
* @typedef {function} InfiniteListFetcher
* A function to call that returns more data for the InfiniteList
* loadMore action. It must resolve to {items: [], moreToLoad} or
* reject with the error {statusCode}.
* @returns {Promise<{items:[], moreToLoad:boolean}>}
*/
/** /**
* A redux module to create a list of items where more items can be loaded * A redux module to create a list of items where more items can be loaded
* using an API. Additionally, there are actions for prepending items * using an API. Additionally, there are actions for prepending items
...@@ -99,22 +91,7 @@ const InfiniteList = key => { ...@@ -99,22 +91,7 @@ const InfiniteList = key => {
replace: (index, item) => ({type: `${key}_REPLACE`, index, item}), replace: (index, item) => ({type: `${key}_REPLACE`, index, item}),
error: error => ({type: `${key}_ERROR`, error}), error: error => ({type: `${key}_ERROR`, error}),
loading: () => ({type: `${key}_LOADING`}), loading: () => ({type: `${key}_LOADING`}),
append: (items, moreToLoad) => ({type: `${key}_APPEND`, items, moreToLoad}), append: (items, moreToLoad) => ({type: `${key}_APPEND`, items, moreToLoad})
/**
* Load more action returns a thunk. It takes a function to call to get more items.
* It will call the LOADING action before calling the fetcher, and call
* APPEND with the results or call ERROR.
* @param {InfiniteListFetcher} fetcher - function that returns a promise
* which must resolve to {items: [], moreToLoad}.
* @returns {function} a thunk that sequences the load and dispatches
*/
loadMore: fetcher => (dispatch => {
dispatch(actions.loading());
return fetcher()
.then(({items, moreToLoad}) => dispatch(actions.append(items, moreToLoad)))
.catch(error => dispatch(actions.error(error)));
})
}; };
const selector = state => state[key]; const selector = state => state[key];
......
...@@ -134,34 +134,6 @@ describe('Infinite List redux module', () => { ...@@ -134,34 +134,6 @@ describe('Infinite List redux module', () => {
expect(typeof module.actions[key]).toBe('function'); expect(typeof module.actions[key]).toBe('function');
} }
}); });
describe('loadMore', () => {
test('returns a thunk function, rather than a standard action object', () => {
expect(typeof module.actions.loadMore()).toBe('function');
});
test('calls loading and the fetcher', () => {
let dispatch = jest.fn();
let fetcher = jest.fn(() => new Promise(() => { })); // that never resolves
module.actions.loadMore(fetcher)(dispatch);
expect(dispatch).toHaveBeenCalledWith(module.actions.loading());
expect(fetcher).toHaveBeenCalled();
});
test('calls append with resolved result from fetcher', async () => {
let dispatch = jest.fn();
let fetcher = jest.fn(() => Promise.resolve({items: ['a', 'b'], moreToLoad: false}));
await module.actions.loadMore(fetcher)(dispatch);
expect(dispatch.mock.calls[1][0]) // the second call to dispatch, after LOADING
.toEqual(module.actions.append(['a', 'b'], false));
});
test('calls error with rejecting promise from fetcher', async () => {
let error = new Error();
let dispatch = jest.fn();
let fetcher = jest.fn(() => Promise.reject(error));
await module.actions.loadMore(fetcher)(dispatch);
expect(dispatch.mock.calls[1][0]) // the second call to dispatch, after LOADING
.toEqual(module.actions.error(error));
});
});
}); });
describe('selector', () => { describe('selector', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment