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

fix: avoid to call root state function twice #1034

Merged
merged 1 commit into from
Nov 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ export class Store {
strict = false
} = options

let {
state = {}
} = options
if (typeof state === 'function') {
state = state() || {}
}

// store internal state
this._committing = false
this._actions = Object.create(null)
Expand All @@ -56,6 +49,8 @@ export class Store {
// strict mode
this.strict = strict

const state = this._modules.root.state

// init root module.
// this also recursively registers all sub-modules
// and collects all module getters inside this._wrappedGetters
Expand Down
8 changes: 8 additions & 0 deletions test/unit/store.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,14 @@ describe('Store', () => {
expect(store.state.a).toBe(3)
})

it('should not call root state function twice', () => {
const spy = jasmine.createSpy().and.returnValue(1)
new Vuex.Store({
state: spy
})
expect(spy).toHaveBeenCalledTimes(1)
})

it('subscribe: should handle subscriptions / unsubscriptions', () => {
const subscribeSpy = jasmine.createSpy()
const secondSubscribeSpy = jasmine.createSpy()
Expand Down