-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
Emit vuexPersistStateRestored
when state replaced for async stores
#107
Conversation
Codecov Report
@@ Coverage Diff @@
## master #107 +/- ##
==========================================
+ Coverage 83.47% 83.76% +0.28%
==========================================
Files 5 5
Lines 115 117 +2
Branches 38 38
==========================================
+ Hits 96 98 +2
Misses 7 7
Partials 12 12
Continue to review full report at Codecov.
|
What needs to happen to get this merged? Looking for this feature specifically. |
In the meantime, you can install directly from my fork: // package.json
{
dependencies: {
// ... other stuff
"vuex-persist": "github:morphatic/vuex-persist"
}
} Hth |
Is there a plan to merge this soon? I also need this to be able to continue with vuex-persist. Thanks! |
Will take a look and merge today
…On Tue 21 May, 2019, 11:29 AM Stephen, ***@***.***> wrote:
Is there a plan to merge this soon? I also need this to be able to
continue with vuex-persist. Thanks!
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#107?email_source=notifications&email_token=AAKD7STM6EUWGGWAFMTF7O3PWOFUPA5CNFSM4HEEFZK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODV22YJA#issuecomment-494251044>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAKD7SX77LA5WT2HS4ASJGDPWOFUPANCNFSM4HEEFZKQ>
.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not contribute dist files to the repository. Those are autogenerated when I publish.
Also is it possible to add tests for the code you added, as that will prevent coverage % from falling.
Sorry. The |
Addresses issue raised in issue 15 by @rulrok. Also addresses #56.
This PR contains updated
indext.ts
as well asREADME.md
to update the documentation on how to use the new event.As noted in the docs, the store is not immediately restored from asnyc stores like localForage. This
can have the unfortunate side effect of overwriting mutations to the store that happen before
vuex-persist
has a chance to do its thing. In strict mode, you can create a plugin tosubscribe to
RESTORE_MUTATION
so that you tell your app to wait until the state has beenrestored before committing any further mutations. (Issue #15 demonstrates how to write such a
plugin.) However, since you should
turn strict mode off in production, and since
vuex
doesn't currently provide any kind ofnotification when
replaceState()
has been called,this PR would cause
vuex-persist
to emit avuexPersistStateRestored
event and also seta
vuexPersistStateRestored
flag to let you know the state has been restored and that it isnow safe to commit any mutations that modify the stored state.
Here's an example of a
beforeEach()
hook invuex-router
that will cause your app to waitfor
vuex-persist
to restore the state before taking any further actions:Note 1:
store._vm.$root.$data['vuexPersistStateRestored']
will beundefined
and therefore"falsy" prior to being set to
true
by thevuex-persist
plugin. There should be no needto explicitly give it a value at any point.
Note 2: My linter automatically added in some spaces in the
import
statements at the top of the module, and also reformatted the indentation ofrestoreState()
andsaveState()
. I tried to revert and reapply my changes with the linter off so that this wouldn't happen, but it seemed to be following the rules already expressed intslint.json
so I gave up and left it as is. I don't make a habit of reformatting other people's code. ;)