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

Commit68127d0

Browse files
committed
Documents impact of partial actions
1 parentc97ee82 commit68127d0

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

‎src/actions/index.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import * as redux from 'redux'
33
import{api}from'../api'
44
import*asstatefrom'../reducers/index'
55

6+
// API actions contain details on the initial request and an eventual error or
7+
// response
68
typeAPIAction<Q,S>={
79
request?:Q
810
response?:S
@@ -14,7 +16,8 @@ export type Action =
1416
{type:'INCREMENT_COUNTER',delta:number}
1517
|{type:'RESET_COUNTER'}
1618

17-
// API Requests
19+
// API Requests implemented as partial actions
20+
// See: https://goo.gl/FYWGpr
1821
|({type:'SAVE_COUNT'}&APIAction<{value:number},{}>)
1922
|({type:'LOAD_COUNT'}&APIAction<undefined,{value:number}>)
2023

‎src/reducers/index.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export type All = {
1313

1414
functionisSaving(state:boolean=false,action:Action):boolean{
1515
if(action.type==='SAVE_COUNT'){
16+
// `SAVE_COUNT` is a partial action. We'll check its payload to determine
17+
// whether this instance describes its resolution.
18+
// See: https://goo.gl/FYWGpr
1619
return!action.response&&!action.error
1720
}
1821
returnstate
@@ -51,6 +54,8 @@ function counter (state: Counter = initialState, action: Action): Counter {
5154
case'LOAD_COUNT':{
5255
const{ response}=action
5356
if(response){
57+
// If `response` is set, `LOAD_COUNT` is "resolved"
58+
// See: https://goo.gl/FYWGpr
5459
return{value:response.value}
5560
}
5661
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp