2017-11-30 11 views
1

reduxでアクションを入力する最も良い方法は何ですか?Reduxでアクションを入力する最も良い方法は? (フロータイプ)

"ベスト"という意味は、読みやすさを最大化し、書き込み/保守に必要な作業を最小限に抑えることです。

ファイルのために...

// @flow 

export const incrementCounter = (counter: string, amount: number) => ({ 
    type: 'INCREMENT_COUNTER', 
    counter, 
    amount 
}) 

export const resetCounter = (counter: string) => ({ 
    type: 'RESET_COUNTER', 
    counter 
}) 

答えて

1

これは$Call Utility Typeを使用して、私は私の行動を入力するか、現在あります。あなたが複数のファイルにあなたの行動を分割した場合

// @flow 

export const incrementCounter = (counter: string, amount: number) => ({ 
    type: 'INCREMENT_COUNTER', 
    counter, 
    amount 
}) 

export const resetCounter = (counter: string) => ({ 
    type: 'RESET_COUNTER', 
    counter 
}) 

export Action = 
    | $Call<typeof incrementCounter, *, *> 
    | $Call<typeof resetCounter, *> 

、あなたがして...そうのようなトップレベルの指標で一緒にすべてのアクションをマージすることができ

import type { Action as CounterActions } from './counter-actions' 
import type { Action as TimerActions } from './timer-actions' 

export type Action = 
    | CounterActions 
    | TimerActions 
関連する問題