Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Just curiosity #65

Closed
ghost opened this issue Oct 9, 2017 · 11 comments
Closed

Just curiosity #65

ghost opened this issue Oct 9, 2017 · 11 comments
Labels

Comments

@ghost
Copy link

ghost commented Oct 9, 2017

When the plugin is using the localStorage and a refresh happends internally it is just commiting a mutation to kept in sync with the store and if I declare a mutation that mutate the state this is pick up by the plugin, if so what is the best way of doing it? I am making my own for more specific needs and I will appreciate your tips and answer.

Are you changing the state directly from within the plugin?

By the way awesome plugin...

@robinvdvleuten
Copy link
Owner

@AAhrit The recommended way is to go full-in on the Vuex API where possible. If you're going to mutate the localStorage instance from outside Vuex, you'll end up with some pretty nifty side effects.

@robinvdvleuten
Copy link
Owner

@AAhrit So the answer your second answer, I only interact with localStorage from within the plugin. When I need to access any "persisted state" I use the getters from the Vuex.

@ghost
Copy link
Author

ghost commented Oct 10, 2017

Oh I see, but how you change the state from within the plugin in every refresh? There is a function called replaceState in the Vuex doc but there is no examples on how to use it. Thanks for the answers.

@robinvdvleuten
Copy link
Owner

@AAhrit depends on what you want to do with your plugin. I use replaceState in my plugin as I replace the complete state (localstorage merged with initial state).

@ghost
Copy link
Author

ghost commented Oct 10, 2017

When you say whenever you need to access to any "persisted state" you use Vuex getters, but this is when the state changes and you need to store whatever was changed? I mean you kept track any changes by watching the state through getters?

@robinvdvleuten
Copy link
Owner

I get the state changes by subscribing my plugin to Vuex

@ghost
Copy link
Author

ghost commented Oct 10, 2017

subscribing you mean adding the plugin to the plugins array? or subscribing to mutations like so: store.subscribe(mutation, state)?

@robinvdvleuten
Copy link
Owner

Yes indeed, exactly as described in the docs.

@ghost
Copy link
Author

ghost commented Oct 10, 2017

So, every time the state changes you grab it using getters then you store it, again, again and again

@ghost
Copy link
Author

ghost commented Oct 11, 2017

I'm sorry if I sound repetitive but when you access to the state you do something like this: store.getters.count from within the plugin? if true, how? if I haven't declared any getters in my store? how you are accessing them anyways?

I'm guessing that if I put inside the paths: [] array any state I want to persist it will be something like this: paths: ['count', 'anotherCount', 'andAnotherOne']?

Lastly if I don't write down what I want to persist how you from within the plugin persist everything? I mean what is your code aproach.

@robinvdvleuten
Copy link
Owner

@AAhrit I will close this issue for now. I do not really get what you're trying to solve here. If you like to know how the plugin works try to look at the code, those hundred or so lines aren't that hard to understand.

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

No branches or pull requests

1 participant