2016-12-29 40 views
0

で唯一のネストされたプロパティをマージI以下の状態があります。減速状態

new Map({ 
    data: new Map({ 
     all: null, 
     recent: null 
    }), 
    filters: new Map({ 
     pagination: new Map({ 
      currentPage: 1 
     }), 
     sortBy: new Map({ 
      key: 'id', 
      order: 'desc' 
     }) 
    }), 
    various: new Map() 
} 

をそして私はこのように、一人でsortByを残し、唯一currentPageプロパティを変更したい:

case PAGINATE: 
    return state.merge({ 
     filters: new Map({ 
      pagination: new Map({ 
       currentPage: action.response 
      }) 
     }) 
    }) 

しかし、その代わりに、 sortByfiltersから消去されているので、正常に動作させるためには、このような操作が必要です。

case PAGINATE: 
    return state.merge({ 
     filters: new Map({ 
      pagination: new Map({ 
       currentPage: action.response 
      }), 
      sortBy: new Map({ 
       key: state.getIn(['filters', 'sortBy', 'key']), 
       order: state.getIn(['filters', 'sortBy', 'order']) 
      }) 
     }) 
    }) 

これを行うより良い方法はありますか?

答えて

0

あなたは、あなたの場合はhere

0

からもっとこの

return state.merge({ 
    filters: state.get('filters').merge({ 
     pagination: new Map({ 
      currentPage: action.response 
     }) 
    }) 
}) 

読むが好きなことができ、あなたは新しいマップを返し、updateInmergeの組み合わせである、mergeInを使用できますが、マージを実行しますkeyPathに従うことによって到着した時点で。

あなたのコードは次のようになりますようにするには:

case PAGINATE: 
    return state.mergeIn(['filters', 'pagination'], { 
    currentPage: action.response 
    }) 

hereからmergeInについては、こちらをご覧ください。

関連する問題