Evan You 8 лет назад
Родитель
Сommit
565ebe6295
2 измененных файлов с 1 добавлено и 51 удалено
  1. 1 12
      src/index.js
  2. 0 39
      test/unit/test.js

+ 1 - 12
src/index.js

@@ -23,7 +23,6 @@ class Store {
     this._wrappedGetters = Object.create(null)
     this._runtimeModules = Object.create(null)
     this._subscribers = []
-    this._pendingActions = []
 
     // bind commit and dispatch to self
     const store = this
@@ -89,15 +88,9 @@ class Store {
       console.error(`[vuex] unknown action type: ${type}`)
       return
     }
-    const res = entry.length > 1
+    return entry.length > 1
       ? Promise.all(entry.map(handler => handler(payload)))
       : entry[0](payload)
-    const pending = this._pendingActions
-    pending.push(res)
-    return res.then(value => {
-      pending.splice(pending.indexOf(res), 1)
-      return value
-    })
   }
 
   subscribe (fn) {
@@ -163,10 +156,6 @@ class Store {
     resetStore(this)
   }
 
-  onActionsResolved (cb) {
-    Promise.all(this._pendingActions).then(cb)
-  }
-
   _withCommit (fn) {
     const committing = this._committing
     this._committing = true

+ 0 - 39
test/unit/test.js

@@ -129,45 +129,6 @@ describe('Vuex', () => {
       })
   })
 
-  it('onActionsResolved', done => {
-    const store = new Vuex.Store({
-      state: {
-        count: 0
-      },
-      mutations: {
-        inc: state => state.count++
-      },
-      actions: {
-        one ({ commit }) {
-          return new Promise(r => {
-            commit('inc')
-            r(1)
-          })
-        },
-        two ({ commit }) {
-          return new Promise(r => {
-            setTimeout(() => {
-              commit('inc')
-              r(2)
-            }, 0)
-          })
-        }
-      }
-    })
-    store.dispatch('one')
-    store.dispatch('two')
-    expect(store.state.count).toBe(1)
-    expect(store._pendingActions.length).toBe(2)
-    store.onActionsResolved(res => {
-      expect(store._pendingActions.length).toBe(0)
-      expect(store.state.count).toBe(2)
-      expect(res.length).toBe(2)
-      expect(res[0]).toBe(1)
-      expect(res[1]).toBe(2)
-      done()
-    })
-  })
-
   it('getters', () => {
     const store = new Vuex.Store({
       state: {