Skip to content

Instantly share code, notes, and snippets.

@rchaser53
Created October 14, 2016 14:22
Show Gist options
  • Save rchaser53/279cf09a653c8ff781bf0a2f2236db62 to your computer and use it in GitHub Desktop.
Save rchaser53/279cf09a653c8ff781bf0a2f2236db62 to your computer and use it in GitHub Desktop.
redo,undoの対象がstateAなのかstateBなのか判断しなければならない例
const stateA = {
idA:{
xx:1
}
}
const stateB = {
idA:{
yy:1
}
}
combineReducers({
stateA,
stateB
});
const actionForA = () => {/* 略 */} // stateAを変更する
const actionForB = () => {/* 略 */} // stateBを変更する
// stateの状態をaction1つ分redo,undoする
const redo = () => {/* 略 */}
const undo = () => {/* 略 */}
@rchaser53
Copy link
Author

これを下みたいな感じにしたいと考えてます。

const stateAB = {

result: [1],
state: {
    stateA: {
        1: {
            id: 1,
            xx: 1,
            stateB:1
        }
    },
    stateB: {
        1: {
            id: 1,
            yy: 1
        }
    }
}

}

@rchaser53
Copy link
Author

あっ色々と失敗してしますね。すみません。多めに見てください。

2つあるオブジェクトを1つにしているだけなので
正規化という表現は適切ではない気がさっきからしてきています(;´・ω・)
normalizr のサンプルっぽくしたらどうだろうというのが正確な表現かもしれません。

しかしとりあえずこれで達成したい以下の2つの目的は何とかできそうだと考えています。

  • redo,undoの対象のオブジェクトを一つにする
  • オブジェクトの構造を必要以上に深くしない

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment