diff --git a/lib/request/index.js b/lib/request/index.js index 068966a..44dc1fb 100644 --- a/lib/request/index.js +++ b/lib/request/index.js @@ -62,6 +62,9 @@ makeRequestReducer.getError = state => makeRequestReducer.getIsLoading = state => state.state === STATES.EMPTY || state.state === STATES.REQUESTING +makeRequestReducer.getIsDone = state => + !makeRequestReducer.getIsLoading(state) + makeRequestReducer.STATES = STATES makeRequestReducer.INITIAL_STATE = INITIAL_STATE diff --git a/lib/request/index.test.js b/lib/request/index.test.js index ec4e97d..5b6a7d4 100644 --- a/lib/request/index.test.js +++ b/lib/request/index.test.js @@ -12,6 +12,7 @@ describe('request', () => { expect(request.getIsError(nextState)).toEqual(false) expect(request.getError(nextState)).toEqual(undefined) expect(request.getIsLoading(nextState)).toEqual(true) + expect(request.getIsDone(nextState)).toEqual(false) }) }) @@ -26,6 +27,7 @@ describe('request', () => { expect(request.getIsError(nextState)).toEqual(false) expect(request.getError(nextState)).toEqual(undefined) expect(request.getIsLoading(nextState)).toEqual(true) + expect(request.getIsDone(nextState)).toEqual(false) }) it('success', () => { @@ -38,6 +40,7 @@ describe('request', () => { expect(request.getIsError(nextState)).toEqual(false) expect(request.getError(nextState)).toEqual(undefined) expect(request.getIsLoading(nextState)).toEqual(false) + expect(request.getIsDone(nextState)).toEqual(true) }) it('error', () => { @@ -50,6 +53,7 @@ describe('request', () => { expect(request.getIsError(nextState)).toEqual(true) expect(request.getError(nextState)).toEqual('foobar') expect(request.getIsLoading(nextState)).toEqual(false) + expect(request.getIsDone(nextState)).toEqual(true) }) it('clear', () => { @@ -62,6 +66,7 @@ describe('request', () => { expect(request.getIsError(nextState)).toEqual(false) expect(request.getError(nextState)).toEqual(undefined) expect(request.getIsLoading(nextState)).toEqual(true) + expect(request.getIsDone(nextState)).toEqual(false) }) }) }) diff --git a/lib/requestById/index.js b/lib/requestById/index.js index 0d532d5..be781cb 100644 --- a/lib/requestById/index.js +++ b/lib/requestById/index.js @@ -39,6 +39,9 @@ makeRequestByIdReducer.getErrorById = id => makeRequestByIdReducer.getIsLoadingById = id => F.pipe(makeRequestByIdReducer.getById(id), request.getIsLoading) +makeRequestByIdReducer.getIsDoneById = id => + F.pipe(makeRequestByIdReducer.getById(id), request.getIsDone) + makeRequestByIdReducer.STATES = request.STATES export default makeRequestByIdReducer diff --git a/lib/requestById/index.test.js b/lib/requestById/index.test.js index 9818469..1f68bcd 100644 --- a/lib/requestById/index.test.js +++ b/lib/requestById/index.test.js @@ -12,6 +12,7 @@ describe('requestById', () => { expect(requestById.getIsErrorById('foo')(nextState)).toEqual(false) expect(requestById.getErrorById('foo')(nextState)).toEqual(undefined) expect(requestById.getIsLoadingById('foo')(nextState)).toEqual(true) + expect(requestById.getIsDoneById('foo')(nextState)).toEqual(false) }) }) @@ -26,6 +27,7 @@ describe('requestById', () => { expect(requestById.getIsErrorById('foo')(nextState)).toEqual(false) expect(requestById.getErrorById('foo')(nextState)).toEqual(undefined) expect(requestById.getIsLoadingById('foo')(nextState)).toEqual(true) + expect(requestById.getIsDoneById('foo')(nextState)).toEqual(false) }) it('success', () => { @@ -38,13 +40,14 @@ describe('requestById', () => { expect(requestById.getIsErrorById('foo')(nextState)).toEqual(false) expect(requestById.getErrorById('foo')(nextState)).toEqual(undefined) expect(requestById.getIsLoadingById('foo')(nextState)).toEqual(false) + expect(requestById.getIsDoneById('foo')(nextState)).toEqual(true) }) it('error', () => { const reducer = requestById({ error: 'ERROR' }) const nextState = reducer(undefined, { - type: 'ERROR', - payload: { id: 'foo', error: 'error' } + type: 'ERROR', + payload: { id: 'foo', error: 'error' } }) expect(requestById.getIsEmptyById('foo')(nextState)).toEqual(false) @@ -53,6 +56,7 @@ describe('requestById', () => { expect(requestById.getIsErrorById('foo')(nextState)).toEqual(true) expect(requestById.getErrorById('foo')(nextState)).toEqual('error') expect(requestById.getIsLoadingById('foo')(nextState)).toEqual(false) + expect(requestById.getIsDoneById('foo')(nextState)).toEqual(true) }) it('clear', () => { @@ -65,6 +69,7 @@ describe('requestById', () => { expect(requestById.getIsErrorById('foo')(nextState)).toEqual(false) expect(requestById.getErrorById('foo')(nextState)).toEqual(undefined) expect(requestById.getIsLoadingById('foo')(nextState)).toEqual(true) + expect(requestById.getIsDoneById('foo')(nextState)).toEqual(false) }) }) })