Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9c9d4e7

Browse files
committed
Add error flag to action creator if payload is instance of error
1 parent3d87833 commit9c9d4e7

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

‎src/create-action.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@flow
22

33
importcreateRequestTypesfrom'./create-request-types'
4-
importtype{Action,ActionCreator}from'./types.flow'
4+
importtype{Action,ActionCreator}from'./create-action.flow'
55

66
/**
77
* Utility function to build action action creator
@@ -10,13 +10,17 @@ import type { Action, ActionCreator } from './types.flow'
1010
*@return {Function}
1111
*/
1212
constcreateAction=(type:string,async:boolean=false):ActionCreator=>{
13-
constactionCreator=(payload?:any,meta?:any):Action=>{
13+
constactionCreator=(payload:any,meta:any):Action=>{
1414
constaction:Action={
1515
type
1616
}
1717

1818
if(payload!==undefined){
1919
action.payload=payload
20+
21+
if(payloadinstanceofError){
22+
action.error=true
23+
}
2024
}
2125

2226
if(meta!==undefined){

‎tests/create-action.spec.js‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
importtestfrom'tape'
44
importcreateActionfrom'../src/create-action'
5-
importtype{ActionCreator}from'../src/types.flow'
5+
importtype{ActionCreator}from'../src/create-action.flow'
66

77
test('createAction',t=>{
88
t.plan(7)
@@ -77,3 +77,17 @@ test('createAction async', t => {
7777
type:`${type}_FAILURE`
7878
})
7979
})
80+
81+
test('createAction with error',t=>{
82+
t.plan(1)
83+
84+
consttype:string='ERROR_ACTION'
85+
consterrorAction:ActionCreator=createAction(type)
86+
constpayload=newError('Failure')
87+
88+
t.deepEqual(errorAction(payload),{
89+
type,
90+
payload,
91+
error:true
92+
})
93+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp