Skip to content

Persist partial state #25

Open
Open
@PaulBernier

Description

@PaulBernier
Contributor

The whole global state is persisted in the Store: https://github.com/vue-electron/vuex-electron/blob/master/src/persisted-state.js#L96

It would be nice to be able to only save parts of the state. We can easily imagine that some part of the state are transient (only relevant to the current execution of the application) and shouldn't not be persisted on disk (and not reloaded at startup).

On top of my mind changing setState like this could be sufficient:

setState(state) {
        const stateToPersist = typeof this.options.statePick === 'function' ? this.options.statePick(state) : state
        this.options.storage.set(this.options.storageKey, stateToPersist)
}

And because the loading operation do a deep merge with the initial state it should work seamlessly. Thoughts?

Activity

PaulBernier

PaulBernier commented on Feb 20, 2019

@PaulBernier
ContributorAuthor

This is actually what this package does: https://github.com/robinvdvleuten/vuex-persistedstate with its options saveSate and getState

NoelDavies

NoelDavies commented on Feb 22, 2019

@NoelDavies

I've got a similar issue - I want some state persisted in memory to enable state to persist during only the app's current session. (Eg switching views, the state should be there still in the same session. But not when closing the app and opening it for another session)

Eg I have a list of players that should only be stored in memory for that session:

{
...otherData,
"players":["Player1","Player2"]
}

But that data, even though it's in the blacklist, it's persisted..

NoelDavies

NoelDavies commented on Feb 23, 2019

@NoelDavies

I've ended up swapping out this repo for #22

akodkod

akodkod commented on Aug 29, 2019

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @NoelDavies@akodkod@PaulBernier

        Issue actions

          Persist partial state · Issue #25 · vue-electron/vuex-electron