Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detecting state changes #33

Open
chisholmd opened this issue May 12, 2020 · 4 comments
Open

detecting state changes #33

chisholmd opened this issue May 12, 2020 · 4 comments

Comments

@chisholmd
Copy link

If I set a deep property like this this:

  setExplorerSelectedBomId(state, payload) {
        state.explorer.bomId = payload;
        return state;
    },

my state change listeners do not get called.

If I add a kind of cache buster at the root of my state object, then it works.

    setExplorerSelectedBomId(state, payload) {
        state.foo=Date.now();
        state.explorer.bomId = payload;
        return state;
    },

It seems to work and is pretty painless, but I thought I would just check to see if this was a bug, or if there is a more proper way to push changes so that they get detected.

@chisholmd
Copy link
Author

OK I lied, this is not working.

Is it by design that the stateChange function is called each time a state property is updated, and before return state is called?

@chisholmd
Copy link
Author

Ok I found a way to be able to group my state values, and still ahve the changes registered.

setExplorerSelectedBomId(state, payload) {
        var tmp = JSON.parse(JSON.stringify(state.explorer));
        tmp.bomId = payload
        state.explorer = tmp;
        return state;
    },

More hacky then before,... Is there another way? or are deep properties frowned upon?

@chisholmd
Copy link
Author

Ok Never mind.... The internet tells me to "keep your state flat". So I will trade _'s for .'s
state.explorer_bomId
state.explorer_parId

etc

@AMerkuri
Copy link

Change self.state = newState to self.state = Object.assign(self.state, newState);. This will trigger Proxy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants