Browse Source

change: Vuex -> Vuex.Store, async action format

Evan You 9 years ago
parent
commit
cff54fc846
35 changed files with 108 additions and 112 deletions
  1. 1 3
      README.md
  2. 0 1
      examples/chat/api/index.js
  3. 2 0
      examples/chat/components/App.vue
  4. 5 5
      examples/chat/components/MessageSection.vue
  5. 3 3
      examples/chat/components/Thread.vue
  6. 3 3
      examples/chat/components/ThreadSection.vue
  7. 2 2
      examples/chat/main.js
  8. 3 3
      examples/chat/store/actions.js
  9. 1 1
      examples/chat/store/index.js
  10. 0 0
      examples/chat/store/mutation-types.js
  11. 0 0
      examples/chat/store/mutations.js
  12. 3 3
      examples/counter-hot/Counter.vue
  13. 2 2
      examples/counter-hot/store/actions.js
  14. 3 3
      examples/counter-hot/store/index.js
  15. 0 0
      examples/counter-hot/store/mutation-types.js
  16. 0 0
      examples/counter-hot/store/mutations.js
  17. 3 3
      examples/counter/Counter.vue
  18. 4 4
      examples/counter/store.js
  19. 5 5
      examples/shopping-cart/components/Cart.vue
  20. 3 3
      examples/shopping-cart/components/ProductList.vue
  21. 2 2
      examples/shopping-cart/store/actions.js
  22. 1 1
      examples/shopping-cart/store/index.js
  23. 0 0
      examples/shopping-cart/store/modules/cart.js
  24. 0 0
      examples/shopping-cart/store/modules/products.js
  25. 0 0
      examples/shopping-cart/store/mutation-types.js
  26. 3 3
      examples/todomvc/components/App.vue
  27. 2 2
      examples/todomvc/components/Todo.vue
  28. 0 0
      examples/todomvc/store/actions.js
  29. 1 1
      examples/todomvc/store/index.js
  30. 0 0
      examples/todomvc/store/middlewares.js
  31. 0 0
      examples/todomvc/store/mutations.js
  32. 2 2
      package.json
  33. 13 9
      src/index.js
  34. 5 12
      src/util.js
  35. 36 36
      test/test.js

+ 1 - 3
README.md

@@ -6,9 +6,7 @@
   <img width="700px" src="https://raw.githubusercontent.com/vuejs/vuex/master/docs/en/vuex.png">
   <img width="700px" src="https://raw.githubusercontent.com/vuejs/vuex/master/docs/en/vuex.png">
 </p>
 </p>
 
 
-**Note**: Vuex is still in development - API may change anytime.
-
-[Documentation](http://vuex.vuejs.org)
+## NOTE: Vuex is still in development - API may change anytime.
 
 
 ## Examples
 ## Examples
 
 

+ 0 - 1
examples/chat/api/index.js

@@ -1,4 +1,3 @@
-import vuex from '../vuex'
 const data = require('./mock-data')
 const data = require('./mock-data')
 const LATENCY = 16
 const LATENCY = 16
 
 

+ 2 - 0
examples/chat/components/App.vue

@@ -8,10 +8,12 @@
 </template>
 </template>
 
 
 <script>
 <script>
+import store from '../store'
 import ThreadSection from './ThreadSection.vue'
 import ThreadSection from './ThreadSection.vue'
 import MessageSection from './MessageSection.vue'
 import MessageSection from './MessageSection.vue'
 
 
 export default {
 export default {
+  store,
   components: {
   components: {
     ThreadSection,
     ThreadSection,
     MessageSection
     MessageSection

+ 5 - 5
examples/chat/components/MessageSection.vue

@@ -13,21 +13,21 @@
 </template>
 </template>
 
 
 <script>
 <script>
-import vuex from '../vuex'
+import store from '../store'
 import Message from './Message.vue'
 import Message from './Message.vue'
 
 
 export default {
 export default {
   components: { Message },
   components: { Message },
   computed: {
   computed: {
     thread () {
     thread () {
-      const id = vuex.state.currentThreadID
+      const id = store.state.currentThreadID
       return id
       return id
-        ? vuex.state.threads[id]
+        ? store.state.threads[id]
         : {}
         : {}
     },
     },
     messages () {
     messages () {
       return this.thread.messages &&
       return this.thread.messages &&
-        this.thread.messages.map(id => vuex.state.messages[id])
+        this.thread.messages.map(id => store.state.messages[id])
     }
     }
   },
   },
   watch: {
   watch: {
@@ -42,7 +42,7 @@ export default {
     sendMessage (e) {
     sendMessage (e) {
       const text = e.target.value
       const text = e.target.value
       if (text.trim()) {
       if (text.trim()) {
-        vuex.actions.sendMessage(text, this.thread)
+        store.actions.sendMessage(text, this.thread)
         e.target.value = ''
         e.target.value = ''
       }
       }
     }
     }

+ 3 - 3
examples/chat/components/Thread.vue

@@ -14,18 +14,18 @@
 </template>
 </template>
 
 
 <script>
 <script>
-import vuex from '../vuex'
+import store from '../store'
 
 
 export default {
 export default {
   props: ['thread'],
   props: ['thread'],
   computed: {
   computed: {
     isCurrentThread () {
     isCurrentThread () {
-      return this.thread.id === vuex.state.currentThreadID
+      return this.thread.id === store.state.currentThreadID
     }
     }
   },
   },
   methods: {
   methods: {
     onClick () {
     onClick () {
-      vuex.actions.switchThread(this.thread.id)
+      store.actions.switchThread(this.thread.id)
     }
     }
   }
   }
 }
 }

+ 3 - 3
examples/chat/components/ThreadSection.vue

@@ -16,17 +16,17 @@
 </template>
 </template>
 
 
 <script>
 <script>
-import vuex from '../vuex'
+import store from '../store'
 import Thread from './Thread.vue'
 import Thread from './Thread.vue'
 
 
 export default {
 export default {
   components: { Thread },
   components: { Thread },
   computed: {
   computed: {
     threads () {
     threads () {
-      return vuex.state.threads
+      return store.state.threads
     },
     },
     unreadCount () {
     unreadCount () {
-      const threads = vuex.state.threads
+      const threads = store.state.threads
       return Object.keys(threads).reduce((count, id) => {
       return Object.keys(threads).reduce((count, id) => {
         return threads[id].lastMessage.isRead
         return threads[id].lastMessage.isRead
           ? count
           ? count

+ 2 - 2
examples/chat/main.js

@@ -1,7 +1,7 @@
 import 'babel-polyfill'
 import 'babel-polyfill'
 import Vue from 'vue'
 import Vue from 'vue'
 import App from './components/App.vue'
 import App from './components/App.vue'
-import vuex from './vuex'
+import store from './store'
 
 
 Vue.filter('time', timestamp => {
 Vue.filter('time', timestamp => {
   return new Date(timestamp).toLocaleTimeString()
   return new Date(timestamp).toLocaleTimeString()
@@ -12,4 +12,4 @@ new Vue({
   components: { App }
   components: { App }
 })
 })
 
 
-vuex.actions.getAllMessages()
+store.actions.getAllMessages()

+ 3 - 3
examples/chat/vuex/actions.js → examples/chat/store/actions.js

@@ -1,18 +1,18 @@
 import * as api from '../api'
 import * as api from '../api'
 import * as types from './mutation-types'
 import * as types from './mutation-types'
 
 
-export const getAllMessages = () => dispatch => {
+export const getAllMessages = ({ dispatch }) => {
   api.getAllMessages(messages => {
   api.getAllMessages(messages => {
     dispatch(types.RECEIVE_ALL, messages)
     dispatch(types.RECEIVE_ALL, messages)
   })
   })
 }
 }
 
 
-export const sendMessage = (text, thread) => dispatch => {
+export const sendMessage = ({ dispatch }, text, thread) => {
   api.createMessage({ text, thread }, message => {
   api.createMessage({ text, thread }, message => {
     dispatch(types.RECEIVE_MESSAGE, message)
     dispatch(types.RECEIVE_MESSAGE, message)
   })
   })
 }
 }
 
 
-export const switchThread = id => dispatch => {
+export const switchThread = ({ dispatch }, id) => {
   dispatch(types.SWITCH_THREAD, id)
   dispatch(types.SWITCH_THREAD, id)
 }
 }

+ 1 - 1
examples/chat/vuex/index.js → examples/chat/store/index.js

@@ -5,7 +5,7 @@ import mutations from './mutations'
 
 
 Vue.use(Vuex)
 Vue.use(Vuex)
 
 
-export default new Vuex({
+export default new Vuex.Store({
   state: {
   state: {
     currentThreadID: null,
     currentThreadID: null,
     threads: {
     threads: {

+ 0 - 0
examples/chat/vuex/mutation-types.js → examples/chat/store/mutation-types.js


+ 0 - 0
examples/chat/vuex/mutations.js → examples/chat/store/mutations.js


+ 3 - 3
examples/counter-hot/Counter.vue

@@ -9,14 +9,14 @@
 </template>
 </template>
 
 
 <script>
 <script>
-import vuex from './vuex'
+import store from './store'
 
 
 export default {
 export default {
   computed: {
   computed: {
     count () {
     count () {
-      return vuex.state.count
+      return store.state.count
     }
     }
   },
   },
-  methods: vuex.actions
+  methods: store.actions
 }
 }
 </script>
 </script>

+ 2 - 2
examples/counter-hot/vuex/actions.js → examples/counter-hot/store/actions.js

@@ -5,13 +5,13 @@ export default {
   increment: INCREMENT,
   increment: INCREMENT,
   decrement: DECREMENT,
   decrement: DECREMENT,
 
 
-  incrementIfOdd: () => (dispatch, state) => {
+  incrementIfOdd: ({ dispatch, state }) => {
     if ((state.count + 1) % 2 === 0) {
     if ((state.count + 1) % 2 === 0) {
       dispatch(INCREMENT)
       dispatch(INCREMENT)
     }
     }
   },
   },
 
 
-  incrementAsync: () => dispatch => {
+  incrementAsync: ({ dispatch }) => {
     setTimeout(() => {
     setTimeout(() => {
       dispatch(INCREMENT)
       dispatch(INCREMENT)
     }, 1000)
     }, 1000)

+ 3 - 3
examples/counter-hot/vuex/index.js → examples/counter-hot/store/index.js

@@ -9,7 +9,7 @@ const state = {
   count: 0
   count: 0
 }
 }
 
 
-const vuex = new Vuex({
+const store = new Vuex.Store({
   state,
   state,
   actions,
   actions,
   mutations
   mutations
@@ -19,11 +19,11 @@ if (module.hot) {
   module.hot.accept(['./actions', './mutations'], () => {
   module.hot.accept(['./actions', './mutations'], () => {
     const newActions = require('./actions').default
     const newActions = require('./actions').default
     const newMutations = require('./mutations').default
     const newMutations = require('./mutations').default
-    vuex.hotUpdate({
+    store.hotUpdate({
       actions: newActions,
       actions: newActions,
       mutations: newMutations
       mutations: newMutations
     })
     })
   })
   })
 }
 }
 
 
-export default vuex
+export default store

+ 0 - 0
examples/counter-hot/vuex/mutation-types.js → examples/counter-hot/store/mutation-types.js


+ 0 - 0
examples/counter-hot/vuex/mutations.js → examples/counter-hot/store/mutations.js


+ 3 - 3
examples/counter/Counter.vue

@@ -9,14 +9,14 @@
 </template>
 </template>
 
 
 <script>
 <script>
-import vuex from './vuex'
+import store from './store'
 
 
 export default {
 export default {
   computed: {
   computed: {
     count () {
     count () {
-      return vuex.state.count
+      return store.state.count
     }
     }
   },
   },
-  methods: vuex.actions
+  methods: store.actions
 }
 }
 </script>
 </script>

+ 4 - 4
examples/counter/vuex.js → examples/counter/store.js

@@ -15,7 +15,7 @@ const state = {
 }
 }
 
 
 // actions are what components will be able to
 // actions are what components will be able to
-// call as vuex.actions.xxx
+// call as store.actions.xxx
 // note these are not the final functions the
 // note these are not the final functions the
 // components will be calling.
 // components will be calling.
 const actions = {
 const actions = {
@@ -30,7 +30,7 @@ const actions = {
   // the returned function will get two arguments,
   // the returned function will get two arguments,
   // the first being the dispatch function and the second is
   // the first being the dispatch function and the second is
   // the state tree.
   // the state tree.
-  incrementIfOdd: () => (dispatch, state) => {
+  incrementIfOdd: ({ dispatch, state }) => {
     if ((state.count + 1) % 2 === 0) {
     if ((state.count + 1) % 2 === 0) {
       dispatch(INCREMENT)
       dispatch(INCREMENT)
     }
     }
@@ -38,7 +38,7 @@ const actions = {
 
 
   // we also use thunks for async actions.
   // we also use thunks for async actions.
   // you can dispatch multiple mutations inside a thunk action.
   // you can dispatch multiple mutations inside a thunk action.
-  incrementAsync: () => dispatch => {
+  incrementAsync: ({ dispatch }) => {
     setTimeout(() => {
     setTimeout(() => {
       dispatch(INCREMENT)
       dispatch(INCREMENT)
     }, 1000)
     }, 1000)
@@ -67,7 +67,7 @@ const mutations = {
 // You can also provide middlewares, which is just an array of
 // You can also provide middlewares, which is just an array of
 // objects containing some hooks to be called at initialization
 // objects containing some hooks to be called at initialization
 // and after each mutation.
 // and after each mutation.
-export default new Vuex({
+export default new Vuex.Store({
   state,
   state,
   actions,
   actions,
   mutations
   mutations

+ 5 - 5
examples/shopping-cart/components/Cart.vue

@@ -14,14 +14,14 @@
 </template>
 </template>
 
 
 <script>
 <script>
-import vuex from '../vuex'
-const { checkout } = vuex.actions
+import store from '../store'
+const { checkout } = store.actions
 
 
 export default {
 export default {
   computed: {
   computed: {
     products () {
     products () {
-      return vuex.state.cart.added.map(({ id, quantity }) => {
-        const product = vuex.state.products.find(p => p.id === id)
+      return store.state.cart.added.map(({ id, quantity }) => {
+        const product = store.state.products.find(p => p.id === id)
         return {
         return {
           title: product.title,
           title: product.title,
           price: product.price,
           price: product.price,
@@ -30,7 +30,7 @@ export default {
       })
       })
     },
     },
     checkoutStatus () {
     checkoutStatus () {
-      return vuex.state.cart.lastCheckout
+      return store.state.cart.lastCheckout
     },
     },
     total () {
     total () {
       return this.products.reduce((total, p) => {
       return this.products.reduce((total, p) => {

+ 3 - 3
examples/shopping-cart/components/ProductList.vue

@@ -13,13 +13,13 @@
 </template>
 </template>
 
 
 <script>
 <script>
-import vuex from '../vuex'
-const { getAllProducts, addToCart } = vuex.actions
+import store from '../store'
+const { getAllProducts, addToCart } = store.actions
 
 
 export default {
 export default {
   computed: {
   computed: {
     products () {
     products () {
-      return vuex.state.products
+      return store.state.products
     }
     }
   },
   },
   created () {
   created () {

+ 2 - 2
examples/shopping-cart/vuex/actions.js → examples/shopping-cart/store/actions.js

@@ -3,7 +3,7 @@ import * as types from './mutation-types'
 
 
 export const addToCart = types.ADD_TO_CART
 export const addToCart = types.ADD_TO_CART
 
 
-export const checkout = (products) => (dispatch, state) => {
+export const checkout = ({ dispatch, state }, products) => {
   const savedCartItems = [...state.cart.added]
   const savedCartItems = [...state.cart.added]
   dispatch(types.CHECKOUT_REQUEST)
   dispatch(types.CHECKOUT_REQUEST)
   shop.buyProducts(
   shop.buyProducts(
@@ -13,7 +13,7 @@ export const checkout = (products) => (dispatch, state) => {
   )
   )
 }
 }
 
 
-export const getAllProducts = () => dispatch => {
+export const getAllProducts = ({ dispatch }) => {
   shop.getProducts(products => {
   shop.getProducts(products => {
     dispatch(types.RECEIVE_PRODUCTS, products)
     dispatch(types.RECEIVE_PRODUCTS, products)
   })
   })

+ 1 - 1
examples/shopping-cart/vuex/index.js → examples/shopping-cart/store/index.js

@@ -9,7 +9,7 @@ Vue.config.debug = true
 
 
 const debug = process.env.NODE_ENV !== 'production'
 const debug = process.env.NODE_ENV !== 'production'
 
 
-export default new Vuex({
+export default new Vuex.Store({
   state: {
   state: {
     cart: cartInitialState,
     cart: cartInitialState,
     products: productsInitialState
     products: productsInitialState

+ 0 - 0
examples/shopping-cart/vuex/modules/cart.js → examples/shopping-cart/store/modules/cart.js


+ 0 - 0
examples/shopping-cart/vuex/modules/products.js → examples/shopping-cart/store/modules/products.js


+ 0 - 0
examples/shopping-cart/vuex/mutation-types.js → examples/shopping-cart/store/mutation-types.js


+ 3 - 3
examples/todomvc/components/App.vue

@@ -46,14 +46,14 @@
 </template>
 </template>
 
 
 <script>
 <script>
-import vuex from '../vuex'
+import store from '../store'
 import Todo from './Todo.vue'
 import Todo from './Todo.vue'
 
 
 const {
 const {
   addTodo,
   addTodo,
   toggleAll,
   toggleAll,
   clearCompleted
   clearCompleted
-} = vuex.actions
+} = store.actions
 
 
 const filters = {
 const filters = {
   all: (todos) => todos,
   all: (todos) => todos,
@@ -71,7 +71,7 @@ export default {
   },
   },
   computed: {
   computed: {
     todos () {
     todos () {
-      return vuex.state.todos
+      return store.state.todos
     },
     },
     allChecked () {
     allChecked () {
       return this.todos.every(todo => todo.done)
       return this.todos.every(todo => todo.done)

+ 2 - 2
examples/todomvc/components/Todo.vue

@@ -19,12 +19,12 @@
 </template>
 </template>
 
 
 <script>
 <script>
-import vuex from '../vuex'
+import store from '../store'
 const {
 const {
   toggleTodo,
   toggleTodo,
   deleteTodo,
   deleteTodo,
   editTodo
   editTodo
-} = vuex.actions
+} = store.actions
 
 
 export default {
 export default {
   props: ['todo'],
   props: ['todo'],

+ 0 - 0
examples/todomvc/vuex/actions.js → examples/todomvc/store/actions.js


+ 1 - 1
examples/todomvc/vuex/index.js → examples/todomvc/store/index.js

@@ -11,7 +11,7 @@ const state = {
   todos: JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]')
   todos: JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]')
 }
 }
 
 
-export default new Vuex({
+export default new Vuex.Store({
   state,
   state,
   actions,
   actions,
   mutations,
   mutations,

+ 0 - 0
examples/todomvc/vuex/middlewares.js → examples/todomvc/store/middlewares.js


+ 0 - 0
examples/todomvc/vuex/mutations.js → examples/todomvc/store/mutations.js


+ 2 - 2
package.json

@@ -36,7 +36,7 @@
     "babel-polyfill": "^6.2.0",
     "babel-polyfill": "^6.2.0",
     "babel-preset-es2015": "^6.1.18",
     "babel-preset-es2015": "^6.1.18",
     "babel-preset-stage-2": "^6.1.18",
     "babel-preset-stage-2": "^6.1.18",
-    "babel-runtime": "^6.2.0",
+    "babel-runtime": "^5.8.0",
     "chai": "^3.4.1",
     "chai": "^3.4.1",
     "css-loader": "^0.21.0",
     "css-loader": "^0.21.0",
     "eslint": "^1.10.2",
     "eslint": "^1.10.2",
@@ -46,7 +46,7 @@
     "vue": "^1.0.8",
     "vue": "^1.0.8",
     "vue-hot-reload-api": "^1.2.1",
     "vue-hot-reload-api": "^1.2.1",
     "vue-html-loader": "^1.0.0",
     "vue-html-loader": "^1.0.0",
-    "vue-loader": "^7.1.1",
+    "vue-loader": "^7.2.0",
     "webpack": "^1.12.8",
     "webpack": "^1.12.8",
     "webpack-dev-server": "^1.12.1"
     "webpack-dev-server": "^1.12.1"
   }
   }

+ 13 - 9
src/index.js

@@ -4,7 +4,7 @@ import createLogger from './middlewares/logger'
 
 
 let Vue
 let Vue
 
 
-export default class Vuex {
+export class Store {
 
 
   /**
   /**
    * @param {Object} options
    * @param {Object} options
@@ -22,6 +22,11 @@ export default class Vuex {
     middlewares = [],
     middlewares = [],
     strict = false
     strict = false
   } = {}) {
   } = {}) {
+    // bind dispatch to self
+    const dispatch = this.dispatch
+    this.dispatch = (...args) => {
+      dispatch.apply(this, args)
+    }
     // use a Vue instance to store the state tree
     // use a Vue instance to store the state tree
     this._vm = new Vue({
     this._vm = new Vue({
       data: state
       data: state
@@ -127,7 +132,7 @@ export default class Vuex {
     new Watcher(this._vm, '$data', () => {
     new Watcher(this._vm, '$data', () => {
       if (!this._dispatching) {
       if (!this._dispatching) {
         throw new Error(
         throw new Error(
-          '[vuex] Do not mutate vuex state outside mutation handlers.'
+          '[vuex] Do not mutate vuex store state outside mutation handlers.'
         )
         )
       }
       }
     }, { deep: true, sync: true })
     }, { deep: true, sync: true })
@@ -214,12 +219,11 @@ export default class Vuex {
 
 
 // export logger factory
 // export logger factory
 export { createLogger }
 export { createLogger }
-Vuex.createLogger = createLogger
-
-/**
- * Exposed install method
- */
 
 
-Vuex.install = function (_Vue) {
-  Vue = _Vue
+export default {
+  Store,
+  createLogger,
+  install (_Vue) {
+    Vue = _Vue
+  }
 }
 }

+ 5 - 12
src/util.js

@@ -2,24 +2,17 @@
  * Create a actual callable action function.
  * Create a actual callable action function.
  *
  *
  * @param {String|Function} action
  * @param {String|Function} action
- * @param {Vuex} vuex
+ * @param {Vuex} store
  * @return {Function} [description]
  * @return {Function} [description]
  */
  */
 
 
-export function createAction (action, vuex) {
+export function createAction (action, store) {
   if (typeof action === 'string') {
   if (typeof action === 'string') {
     // simple action string shorthand
     // simple action string shorthand
-    return (...payload) => {
-      vuex.dispatch(action, ...payload)
-    }
+    return (...payload) => store.dispatch(action, ...payload)
   } else if (typeof action === 'function') {
   } else if (typeof action === 'function') {
-    // thunk action
-    return (...args) => {
-      const dispatch = (...args) => {
-        vuex.dispatch(...args)
-      }
-      action(...args)(dispatch, vuex.state)
-    }
+    // normal action
+    return (...payload) => action(store, ...payload)
   }
   }
 }
 }
 
 

+ 36 - 36
test/test.js

@@ -9,7 +9,7 @@ const TEST = 'TEST'
 
 
 describe('Vuex', () => {
 describe('Vuex', () => {
   it('direct dispatch', () => {
   it('direct dispatch', () => {
-    const vuex = new Vuex({
+    const store = new Vuex.Store({
       state: {
       state: {
         a: 1
         a: 1
       },
       },
@@ -19,12 +19,12 @@ describe('Vuex', () => {
         }
         }
       }
       }
     })
     })
-    vuex.dispatch(TEST, 2)
-    expect(vuex.state.a).to.equal(3)
+    store.dispatch(TEST, 2)
+    expect(store.state.a).to.equal(3)
   })
   })
 
 
   it('simple action', function () {
   it('simple action', function () {
-    const vuex = new Vuex({
+    const store = new Vuex.Store({
       state: {
       state: {
         a: 1
         a: 1
       },
       },
@@ -37,19 +37,19 @@ describe('Vuex', () => {
         }
         }
       }
       }
     })
     })
-    vuex.actions.test(2)
-    expect(vuex.state.a).to.equal(3)
+    store.actions.test(2)
+    expect(store.state.a).to.equal(3)
   })
   })
 
 
   it('async action', function (done) {
   it('async action', function (done) {
     const TEST = 'TEST'
     const TEST = 'TEST'
-    const vuex = new Vuex({
+    const store = new Vuex.Store({
       state: {
       state: {
         a: 1,
         a: 1,
         timeout: 10
         timeout: 10
       },
       },
       actions: {
       actions: {
-        test: (n) => (dispatch, state) => {
+        test: ({ dispatch, state }, n) => {
           setTimeout(() => {
           setTimeout(() => {
             dispatch(TEST, n)
             dispatch(TEST, n)
           }, state.timeout)
           }, state.timeout)
@@ -61,16 +61,16 @@ describe('Vuex', () => {
         }
         }
       }
       }
     })
     })
-    vuex.actions.test(2)
+    store.actions.test(2)
     setTimeout(() => {
     setTimeout(() => {
-      expect(vuex.state.a).to.equal(3)
+      expect(store.state.a).to.equal(3)
       done()
       done()
-    }, vuex.state.timeout)
+    }, store.state.timeout)
   })
   })
 
 
   it('array option syntax', function () {
   it('array option syntax', function () {
     const TEST2 = 'TEST2'
     const TEST2 = 'TEST2'
-    const vuex = new Vuex({
+    const store = new Vuex.Store({
       state: {
       state: {
         a: 1,
         a: 1,
         b: 1,
         b: 1,
@@ -94,16 +94,16 @@ describe('Vuex', () => {
         }
         }
       ]
       ]
     })
     })
-    vuex.actions.test(2)
-    expect(vuex.state.a).to.equal(3)
-    expect(vuex.state.b).to.equal(3)
-    expect(vuex.state.c).to.equal(1)
-    vuex.actions.test2(2)
-    expect(vuex.state.c).to.equal(3)
+    store.actions.test(2)
+    expect(store.state.a).to.equal(3)
+    expect(store.state.b).to.equal(3)
+    expect(store.state.c).to.equal(1)
+    store.actions.test2(2)
+    expect(store.state.c).to.equal(3)
   })
   })
 
 
   it('hot reload', function () {
   it('hot reload', function () {
-    const vuex = new Vuex({
+    const store = new Vuex.Store({
       state: {
       state: {
         a: 1
         a: 1
       },
       },
@@ -116,12 +116,12 @@ describe('Vuex', () => {
         }
         }
       }
       }
     })
     })
-    const test = vuex.actions.test
+    const test = store.actions.test
     test(2)
     test(2)
-    expect(vuex.state.a).to.equal(3)
-    vuex.hotUpdate({
+    expect(store.state.a).to.equal(3)
+    store.hotUpdate({
       actions: {
       actions: {
-        test: n => dispatch => dispatch(TEST, n + 1)
+        test: ({ dispatch }, n) => dispatch(TEST, n + 1)
       },
       },
       mutations: {
       mutations: {
         [TEST] (state, n) {
         [TEST] (state, n) {
@@ -130,13 +130,13 @@ describe('Vuex', () => {
       }
       }
     })
     })
     test(999)
     test(999)
-    expect(vuex.state.a).to.equal(1000)
+    expect(store.state.a).to.equal(1000)
   })
   })
 
 
   it('middleware', function () {
   it('middleware', function () {
     let initState
     let initState
     const mutations = []
     const mutations = []
-    const vuex = new Vuex({
+    const store = new Vuex.Store({
       state: {
       state: {
         a: 1
         a: 1
       },
       },
@@ -154,14 +154,14 @@ describe('Vuex', () => {
             initState = state
             initState = state
           },
           },
           onMutation (mut, state) {
           onMutation (mut, state) {
-            expect(state).to.equal(vuex.state)
+            expect(state).to.equal(store.state)
             mutations.push(mut)
             mutations.push(mut)
           }
           }
         }
         }
       ]
       ]
     })
     })
-    expect(initState).to.equal(vuex.state)
-    vuex.actions.test(2)
+    expect(initState).to.equal(store.state)
+    store.actions.test(2)
     expect(mutations.length).to.equal(1)
     expect(mutations.length).to.equal(1)
     expect(mutations[0].type).to.equal(TEST)
     expect(mutations[0].type).to.equal(TEST)
     expect(mutations[0].payload[0]).to.equal(2)
     expect(mutations[0].payload[0]).to.equal(2)
@@ -170,7 +170,7 @@ describe('Vuex', () => {
   it('middleware with snapshot', function () {
   it('middleware with snapshot', function () {
     let initState
     let initState
     const mutations = []
     const mutations = []
-    const vuex = new Vuex({
+    const store = new Vuex.Store({
       state: {
       state: {
         a: 1
         a: 1
       },
       },
@@ -198,31 +198,31 @@ describe('Vuex', () => {
         }
         }
       ]
       ]
     })
     })
-    expect(initState).not.to.equal(vuex.state)
+    expect(initState).not.to.equal(store.state)
     expect(initState.a).to.equal(1)
     expect(initState.a).to.equal(1)
-    vuex.actions.test(2)
+    store.actions.test(2)
     expect(mutations.length).to.equal(1)
     expect(mutations.length).to.equal(1)
     expect(mutations[0].mutation.type).to.equal(TEST)
     expect(mutations[0].mutation.type).to.equal(TEST)
     expect(mutations[0].mutation.payload[0]).to.equal(2)
     expect(mutations[0].mutation.payload[0]).to.equal(2)
-    expect(mutations[0].nextState).not.to.equal(vuex.state)
+    expect(mutations[0].nextState).not.to.equal(store.state)
     expect(mutations[0].prevState.a).to.equal(1)
     expect(mutations[0].prevState.a).to.equal(1)
     expect(mutations[0].nextState.a).to.equal(3)
     expect(mutations[0].nextState.a).to.equal(3)
   })
   })
 
 
   it('strict mode: warn mutations outside of handlers', function () {
   it('strict mode: warn mutations outside of handlers', function () {
-    const vuex = new Vuex({
+    const store = new Vuex.Store({
       state: {
       state: {
         a: 1
         a: 1
       },
       },
       actions: {
       actions: {
-        test: () => (dispatch, state) => {
+        test: ({ dispatch, state }) => {
           state.a++
           state.a++
         }
         }
       },
       },
       strict: true
       strict: true
     })
     })
     expect(() => {
     expect(() => {
-      vuex.actions.test(2)
-    }).to.throw(/Do not mutate vuex state outside mutation handlers/)
+      store.actions.test(2)
+    }).to.throw(/Do not mutate vuex store state outside mutation handlers/)
   })
   })
 })
 })