Skip to content

Commit

Permalink
fix: avoid to call root state function twice (#1034)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsn authored and yyx990803 committed Nov 1, 2017
1 parent e821f1b commit 86677eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
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

0 comments on commit 86677eb

Please sign in to comment.