1
0
Эх сурвалжийг харах

Merge branch 'dev' into 4.0

# Conflicts:
#	CHANGELOG.md
#	dist/logger.js
#	dist/vuex.common.js
#	dist/vuex.esm.browser.js
#	dist/vuex.esm.browser.min.js
#	dist/vuex.esm.js
#	dist/vuex.js
#	dist/vuex.min.js
#	package.json
Kia Ishii 4 жил өмнө
parent
commit
6ec8f44190

+ 17 - 1
docs/guide/plugins.md

@@ -92,13 +92,17 @@ The plugin will be used by default. For production, you will need [DefinePlugin]
 Vuex comes with a logger plugin for common debugging usage:
 
 ``` js
-import createLogger from 'vuex/dist/logger'
+import { createLogger } from 'vuex'
 
 const store = new Vuex.Store({
   plugins: [createLogger()]
 })
 ```
 
+:::warning WARNING
+Before v3.5.0, the `createLogger` function is exported at `vuex/dist/logger` package. PLease checkout the "Before Vuex v3.5.0" setion of this page.
+:::
+
 The `createLogger` function takes a few options:
 
 ``` js
@@ -137,3 +141,15 @@ const logger = createLogger({
 The logger file can also be included directly via a `<script>` tag, and will expose the `createVuexLogger` function globally.
 
 Note the logger plugin takes state snapshots, so use it only during development.
+
+#### Before Vuex v3.5.0
+
+Before v3.5.0, the `createLogger` function is exported at `vuex/dist/logger` package.
+
+``` js
+import createLogger from 'vuex/dist/logger'
+
+const store = new Vuex.Store({
+  plugins: [createLogger()]
+})
+```

+ 15 - 1
src/module/module-collection.js

@@ -49,7 +49,21 @@ export default class ModuleCollection {
   unregister (path) {
     const parent = this.get(path.slice(0, -1))
     const key = path[path.length - 1]
-    if (!parent.getChild(key).runtime) return
+    const child = parent.getChild(key)
+
+    if (!child) {
+      if (__DEV__) {
+        console.warn(
+          `[vuex] trying to unregister module '${key}', which is ` +
+          `not registered`
+        )
+      }
+      return
+    }
+
+    if (!child.runtime) {
+      return
+    }
 
     parent.removeChild(key)
   }

+ 8 - 0
test/unit/module/module-collection.spec.js

@@ -92,4 +92,12 @@ describe('ModuleCollection', () => {
     collection.unregister(['a'])
     expect(collection.get(['a']).state.value).toBe(true)
   })
+
+  it('warns when unregistering non existing module', () => {
+    const spy = jest.spyOn(console, 'warn').mockImplementation()
+
+    const collection = new ModuleCollection({})
+    collection.unregister(['a'])
+    expect(spy).toHaveBeenCalled()
+  })
 })