Преглед изворни кода

move global api to a more proper place

Evan You пре 10 година
родитељ
комит
e0e406221a
4 измењених фајлова са 41 додато и 38 уклоњено
  1. 35 13
      src/global-api.js
  2. 3 22
      src/index.js
  3. 1 3
      src/instance/vue.js
  4. 2 0
      test/unit/specs/global_api_spec.js

+ 35 - 13
src/instance/api/global.js → src/global-api.js

@@ -10,21 +10,43 @@ import {
   warn,
   isPlainObject,
   extend
-} from '../../util/index'
-
-import config from '../../config'
-import * as util from '../../util/index'
-import * as compiler from '../../compiler/index'
-import * as path from '../../parsers/path'
-import * as text from '../../parsers/text'
-import * as template from '../../parsers/template'
-import * as directive from '../../parsers/directive'
-import * as expression from '../../parsers/expression'
-import * as transition from '../../transition/index'
-import FragmentFactory from '../../fragment/factory'
-import internalDirectives from '../../directives/internal/index'
+} from './util/index'
+
+import config from './config'
+import directives from './directives/public/index'
+import elementDirectives from './directives/element/index'
+import filters from './filters/index'
+import * as util from './util/index'
+import * as compiler from './compiler/index'
+import * as path from './parsers/path'
+import * as text from './parsers/text'
+import * as template from './parsers/template'
+import * as directive from './parsers/directive'
+import * as expression from './parsers/expression'
+import * as transition from './transition/index'
+import FragmentFactory from './fragment/factory'
+import internalDirectives from './directives/internal/index'
 
 export default function (Vue) {
+  /**
+   * Vue and every constructor that extends Vue has an
+   * associated options object, which can be accessed during
+   * compilation steps as `this.constructor.options`.
+   *
+   * These can be seen as the default options of every
+   * Vue instance.
+   */
+
+  Vue.options = {
+    directives,
+    elementDirectives,
+    filters,
+    transitions: {},
+    components: {},
+    partials: {},
+    replace: true
+  }
+
   /**
    * Expose useful internals
    */

+ 3 - 22
src/index.js

@@ -1,29 +1,10 @@
 import Vue from './instance/vue'
-import directives from './directives/public/index'
-import elementDirectives from './directives/element/index'
-import filters from './filters/index'
+import installGlobalAPI from './global-api'
 import { inBrowser, devtools } from './util/index'
 
-Vue.version = '1.0.16'
-
-/**
- * Vue and every constructor that extends Vue has an
- * associated options object, which can be accessed during
- * compilation steps as `this.constructor.options`.
- *
- * These can be seen as the default options of every
- * Vue instance.
- */
+installGlobalAPI(Vue)
 
-Vue.options = {
-  directives,
-  elementDirectives,
-  filters,
-  transitions: {},
-  components: {},
-  partials: {},
-  replace: true
-}
+Vue.version = '1.0.16'
 
 export default Vue
 

+ 1 - 3
src/instance/vue.js

@@ -4,7 +4,6 @@ import eventsMixin from './internal/events'
 import lifecycleMixin from './internal/lifecycle'
 import miscMixin from './internal/misc'
 
-import globalAPI from './api/global'
 import dataAPI from './api/data'
 import domAPI from './api/dom'
 import eventsAPI from './api/events'
@@ -35,8 +34,7 @@ eventsMixin(Vue)
 lifecycleMixin(Vue)
 miscMixin(Vue)
 
-// install APIs
-globalAPI(Vue)
+// install instance APIs
 dataAPI(Vue)
 domAPI(Vue)
 eventsAPI(Vue)

+ 2 - 0
test/unit/specs/api/global_spec.js → test/unit/specs/global_api_spec.js

@@ -1,6 +1,7 @@
 var Vue = require('src')
 var _ = require('src/util')
 var config = require('src/config')
+var transition = require('src/transition')
 
 describe('Global API', function () {
   beforeEach(function () {
@@ -11,6 +12,7 @@ describe('Global API', function () {
     expect(Vue.util).toBe(_)
     expect(Vue.nextTick).toBe(_.nextTick)
     expect(Vue.config).toBe(config)
+    expect(Vue.transition.applyTransition).toBe(transition.applyTransition)
   })
 
   it('extend', function () {