Просмотр исходного кода

assets: standardize "name" usage

Evan You 10 лет назад
Родитель
Сommit
deb43a8fca
2 измененных файлов с 7 добавлено и 6 удалено
  1. 3 3
      src/util/options.js
  2. 4 3
      test/unit/specs/util/options_spec.js

+ 3 - 3
src/util/options.js

@@ -231,7 +231,7 @@ function guardComponents (options) {
       }
       def = components[key]
       if (_.isPlainObject(def)) {
-        def.id = def.id || key
+        def.name = def.name || key
         components[key] = def._Ctor || (def._Ctor = _.Vue.extend(def))
       }
     }
@@ -280,10 +280,10 @@ function guardArrayAssets (assets) {
     var asset
     while (i--) {
       asset = assets[i]
-      var id = asset.id || (asset.options && asset.options.id)
+      var id = asset.name || (asset.options && asset.options.name)
       if (!id) {
         process.env.NODE_ENV !== 'production' && _.warn(
-          'Array-syntax assets must provide an id field.'
+          'Array-syntax assets must provide a "name" field.'
         )
       } else {
         res[id] = asset

+ 4 - 3
test/unit/specs/util/options_spec.js

@@ -123,7 +123,7 @@ describe('Util - Option merging', function () {
       }
     })
     expect(typeof res.components.test).toBe('function')
-    expect(res.components.test.options.id).toBe('test')
+    expect(res.components.test.options.name).toBe('test')
     expect(res.components.test.super).toBe(Vue)
   })
 
@@ -282,11 +282,12 @@ describe('Util - Option merging', function () {
       }
     }
     var b = {
-      components: [{ id: 'b' }]
+      components: [{ name: 'b' }]
     }
     var res = merge(a, b)
     expect(res.components.a).toBe(a.components.a)
     // b.components is guarded and converted to object hash
+    expect(res.components.b).toBeTruthy()
     expect(res.components.b).toBe(b.components.b)
   })
 
@@ -300,7 +301,7 @@ describe('Util - Option merging', function () {
       components: [{}]
     }
     merge(a, b)
-    expect(hasWarned(_, 'must provide an id')).toBe(true)
+    expect(hasWarned(_, 'must provide a "name" field')).toBe(true)
   })
 
 })