私はEmber Object Modelで計算されたプロパティに慣れています。これは、他のプロパティに依存する計算されたプロパティを指定する便利な方法です。
fullName
とに依存するfirstName
と言ってlastName
、計算されたプロパティを関数としてセットアップし、変更を加えるたびにcomputeProperties
呼び出すことができます。computeProperties
例:
function computeFullName(state) {
const fullName = state.get('firstName') + state.get('lastName');
const nextState = state.set('fullName', fullName);
return nextState;
}
function computeProperties(state) {
const nextState = computeFullName(state);
return nextState;
}
// store action handler
[handleActionX](state) {
let nextState = state.set('firstName', 'John');
nextState = state.set('lastName', 'Doe');
nextState = computeProperties(nextState);
return nextState;
}
毎回余分な関数を呼び出す必要がないように、計算されたプロパティを自動的にセットアップする方法はありますか? Redux または ImmutableJS で。