| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- var _ = require('../util')
- var mergeOptions = require('../util/merge-option')
- /**
- * Expose useful internals
- */
- exports.util = _
- exports.nextTick = _.nextTick
- exports.config = require('../config')
- exports.transition = require('../transition')
- /**
- * Each instance constructor, including Vue, has a unique
- * cid. This enables us to create wrapped "child
- * constructors" for prototypal inheritance and cache them.
- */
- exports.cid = 0
- var cid = 1
- /**
- * Class inehritance
- *
- * @param {Object} extendOptions
- */
- exports.extend = function (extendOptions) {
- var Super = this
- var Sub = function (instanceOptions) {
- _.Vue.call(this, instanceOptions)
- }
- Sub.prototype = Object.create(Super.prototype)
- Sub.prototype.constructor = Sub
- Sub.cid = cid++
- Sub.options = mergeOptions(Super.options, extendOptions)
- Sub.super = Super
- // allow further extension
- Sub.extend = Super.extend
- // create asset registers, so extended classes
- // can have their private assets too.
- createAssetRegisters(Sub)
- return Sub
- }
- /**
- * Plugin system
- *
- * @param {String|Object} plugin
- */
- exports.use = function (plugin) {
- if (typeof plugin === 'string') {
- try {
- plugin = require(plugin)
- } catch (e) {
- _.warn('Cannot load plugin: ' + plugin)
- }
- }
- // additional parameters
- var args = _.toArray(arguments, 1)
- args.unshift(this)
- if (typeof plugin.install === 'function') {
- plugin.install.apply(plugin, args)
- } else {
- plugin.apply(null, args)
- }
- return this
- }
- /**
- * Define asset registration methods on a constructor.
- *
- * @param {Function} Constructor
- */
- var assetTypes = [
- 'directive',
- 'filter',
- 'partial',
- 'transition'
- ]
- function createAssetRegisters (Constructor) {
- /* Asset registration methods share the same signature:
- *
- * @param {String} id
- * @param {*} definition
- */
- assetTypes.forEach(function (type) {
- Constructor[type] = function (id, definition) {
- if (!definition) {
- return this.options[type + 's'][id]
- } else {
- this.options[type + 's'][id] = definition
- }
- }
- })
- /**
- * Component registration needs to automatically invoke
- * Vue.extend on object values.
- *
- * @param {String} id
- * @param {Object|Function} definition
- */
- Constructor.component = function (id, definition) {
- if (!definition) {
- return this.options.components[id]
- } else {
- if (_.isPlainObject(definition)) {
- definition = _.Vue.extend(definition)
- }
- this.options.components[id] = definition
- }
- }
- }
- createAssetRegisters(exports)
|