Skip to content

Commit 46f9c79

Browse files
authored
Add type attribute (#156)
* Add special type property * Bump minor
1 parent d672733 commit 46f9c79

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@launchpadlab/lp-redux-api",
3-
"version": "6.2.4",
3+
"version": "6.3.0",
44
"description": "redux middleware and api library",
55
"main": "lib/index.js",
66
"scripts": {

src/create-request.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { isObject, isFunction } from 'lodash'
2222
* // -> will make request to /users/5
2323
*
2424
* // Just like in redux-actions, this action can be referenced in a reducer by name:
25-
*
25+
*
2626
* handleActions({
2727
* [apiActions.fetchUser]: (state, action) => ...
2828
* })
@@ -49,6 +49,7 @@ function createRequestWithMethod (type, definition, method) {
4949
}
5050
}
5151
actionCreator.toString = () => LP_API_ACTION_NAMESPACE + type
52+
actionCreator.type = LP_API_ACTION_NAMESPACE + type
5253
return actionCreator
5354
}
5455

test/create-request.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
createPatchRequest,
88
createDeleteRequest,
99
} from '../src/'
10+
import { LP_API_ACTION_NAMESPACE } from '../src/actions'
1011
import { REQUEST_TYPE } from './fixtures'
1112

1213
test('createRequest requires a type argument', () => {
@@ -36,6 +37,16 @@ test('createRequest rejects other types of request definitions', () => {
3637
expect(() => createRequest(REQUEST_TYPE, 'wtf')).toThrow()
3738
})
3839

40+
test('createRequest has the namespaced action type as its string representation', () => {
41+
const actionCreator = createRequest(REQUEST_TYPE, {})
42+
expect(actionCreator.toString()).toEqual(LP_API_ACTION_NAMESPACE+REQUEST_TYPE)
43+
})
44+
45+
test('createRequest has the namespaced action type set to the special `type` property', () => {
46+
const actionCreator = createRequest(REQUEST_TYPE, {})
47+
expect(actionCreator.type).toEqual(LP_API_ACTION_NAMESPACE+REQUEST_TYPE)
48+
})
49+
3950
// Convenience functions
4051

4152
test('createGetRequest creates a request with method GET', () => {

0 commit comments

Comments
 (0)