github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/themes/wind/static/libs/vue-1.0.24/src/global-api.js (about)

     1  import config from './config'
     2  import directives from './directives/public/index'
     3  import elementDirectives from './directives/element/index'
     4  import filters from './filters/index'
     5  import * as util from './util/index'
     6  import * as compiler from './compiler/index'
     7  import * as path from './parsers/path'
     8  import * as text from './parsers/text'
     9  import * as template from './parsers/template'
    10  import * as directive from './parsers/directive'
    11  import * as expression from './parsers/expression'
    12  import * as transition from './transition/index'
    13  import FragmentFactory from './fragment/factory'
    14  import internalDirectives from './directives/internal/index'
    15  
    16  import {
    17    set,
    18    del,
    19    nextTick,
    20    mergeOptions,
    21    classify,
    22    toArray,
    23    commonTagRE,
    24    reservedTagRE,
    25    warn,
    26    isPlainObject,
    27    extend
    28  } from './util/index'
    29  
    30  export default function (Vue) {
    31    /**
    32     * Vue and every constructor that extends Vue has an
    33     * associated options object, which can be accessed during
    34     * compilation steps as `this.constructor.options`.
    35     *
    36     * These can be seen as the default options of every
    37     * Vue instance.
    38     */
    39  
    40    Vue.options = {
    41      directives,
    42      elementDirectives,
    43      filters,
    44      transitions: {},
    45      components: {},
    46      partials: {},
    47      replace: true
    48    }
    49  
    50    /**
    51     * Expose useful internals
    52     */
    53  
    54    Vue.util = util
    55    Vue.config = config
    56    Vue.set = set
    57    Vue.delete = del
    58    Vue.nextTick = nextTick
    59  
    60    /**
    61     * The following are exposed for advanced usage / plugins
    62     */
    63  
    64    Vue.compiler = compiler
    65    Vue.FragmentFactory = FragmentFactory
    66    Vue.internalDirectives = internalDirectives
    67    Vue.parsers = {
    68      path,
    69      text,
    70      template,
    71      directive,
    72      expression
    73    }
    74  
    75    /**
    76     * Each instance constructor, including Vue, has a unique
    77     * cid. This enables us to create wrapped "child
    78     * constructors" for prototypal inheritance and cache them.
    79     */
    80  
    81    Vue.cid = 0
    82    var cid = 1
    83  
    84    /**
    85     * Class inheritance
    86     *
    87     * @param {Object} extendOptions
    88     */
    89  
    90    Vue.extend = function (extendOptions) {
    91      extendOptions = extendOptions || {}
    92      var Super = this
    93      var isFirstExtend = Super.cid === 0
    94      if (isFirstExtend && extendOptions._Ctor) {
    95        return extendOptions._Ctor
    96      }
    97      var name = extendOptions.name || Super.options.name
    98      if (process.env.NODE_ENV !== 'production') {
    99        if (!/^[a-zA-Z][\w-]*$/.test(name)) {
   100          warn(
   101            'Invalid component name: "' + name + '". Component names ' +
   102            'can only contain alphanumeric characaters and the hyphen.'
   103          )
   104          name = null
   105        }
   106      }
   107      var Sub = createClass(name || 'VueComponent')
   108      Sub.prototype = Object.create(Super.prototype)
   109      Sub.prototype.constructor = Sub
   110      Sub.cid = cid++
   111      Sub.options = mergeOptions(
   112        Super.options,
   113        extendOptions
   114      )
   115      Sub['super'] = Super
   116      // allow further extension
   117      Sub.extend = Super.extend
   118      // create asset registers, so extended classes
   119      // can have their private assets too.
   120      config._assetTypes.forEach(function (type) {
   121        Sub[type] = Super[type]
   122      })
   123      // enable recursive self-lookup
   124      if (name) {
   125        Sub.options.components[name] = Sub
   126      }
   127      // cache constructor
   128      if (isFirstExtend) {
   129        extendOptions._Ctor = Sub
   130      }
   131      return Sub
   132    }
   133  
   134    /**
   135     * A function that returns a sub-class constructor with the
   136     * given name. This gives us much nicer output when
   137     * logging instances in the console.
   138     *
   139     * @param {String} name
   140     * @return {Function}
   141     */
   142  
   143    function createClass (name) {
   144      /* eslint-disable no-new-func */
   145      return new Function(
   146        'return function ' + classify(name) +
   147        ' (options) { this._init(options) }'
   148      )()
   149      /* eslint-enable no-new-func */
   150    }
   151  
   152    /**
   153     * Plugin system
   154     *
   155     * @param {Object} plugin
   156     */
   157  
   158    Vue.use = function (plugin) {
   159      /* istanbul ignore if */
   160      if (plugin.installed) {
   161        return
   162      }
   163      // additional parameters
   164      var args = toArray(arguments, 1)
   165      args.unshift(this)
   166      if (typeof plugin.install === 'function') {
   167        plugin.install.apply(plugin, args)
   168      } else {
   169        plugin.apply(null, args)
   170      }
   171      plugin.installed = true
   172      return this
   173    }
   174  
   175    /**
   176     * Apply a global mixin by merging it into the default
   177     * options.
   178     */
   179  
   180    Vue.mixin = function (mixin) {
   181      Vue.options = mergeOptions(Vue.options, mixin)
   182    }
   183  
   184    /**
   185     * Create asset registration methods with the following
   186     * signature:
   187     *
   188     * @param {String} id
   189     * @param {*} definition
   190     */
   191  
   192    config._assetTypes.forEach(function (type) {
   193      Vue[type] = function (id, definition) {
   194        if (!definition) {
   195          return this.options[type + 's'][id]
   196        } else {
   197          /* istanbul ignore if */
   198          if (process.env.NODE_ENV !== 'production') {
   199            if (
   200              type === 'component' &&
   201              (commonTagRE.test(id) || reservedTagRE.test(id))
   202            ) {
   203              warn(
   204                'Do not use built-in or reserved HTML elements as component ' +
   205                'id: ' + id
   206              )
   207            }
   208          }
   209          if (
   210            type === 'component' &&
   211            isPlainObject(definition)
   212          ) {
   213            definition.name = id
   214            definition = Vue.extend(definition)
   215          }
   216          this.options[type + 's'][id] = definition
   217          return definition
   218        }
   219      }
   220    })
   221  
   222    // expose internal transition API
   223    extend(Vue.transition, transition)
   224  }