A
A
Artur Galyaev2021-02-27 17:47:30
Vue.js
Artur Galyaev, 2021-02-27 17:47:30

Why does Vuex need rootState to be a reference to an object, not a copy of it?

There is a problem in the repository related to the fact that the rootState in actions is a reference to the object, and not a copy of it
https://github.com/vuejs/vuex/issues/1939
https://codesandbox.io/s/dank-https-tqtvo ?file=/sr... (You can have a look here)
Trying to fix this, I ran into a test error,

Expected: {"a": 1, "four": {"a": 6}, "nested": {"a": 2, "nested": {"three": {"a": 5}, "two": {"a": 4}}, "one": {"a": 3}}}
    Received: serializes to the same string

      269 |             calls++
      270 |             expect(state.a).toBe(n)
    > 271 |             expect(rootState).toBe(store.state)
          |                               ^
      272 |           }
      273 |         }
      274 |       }

This says that rootState MUST be a reference to store.state.
Question: why was it done this way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Shvedov, 2021-02-27
@mmmaaak

Why copy it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question