|
|
@@ -2,60 +2,95 @@ var _ = require('../util')
|
|
|
var config = require('../config')
|
|
|
|
|
|
/**
|
|
|
- * Configuration
|
|
|
+ * Vue and every constructor that extends Vue has an associated
|
|
|
+ * options object, which can be accessed during compilation steps
|
|
|
+ * as `this.constructor.options`.
|
|
|
*/
|
|
|
|
|
|
-exports.config = function () {
|
|
|
-
|
|
|
+exports.options = {
|
|
|
+ directives : require('../directives'),
|
|
|
+ filters : require('../filters'),
|
|
|
+ partials : {},
|
|
|
+ effects : {},
|
|
|
+ components : {}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Class inehritance
|
|
|
+ * Expose useful internals
|
|
|
*/
|
|
|
|
|
|
-exports.extend = function () {
|
|
|
-
|
|
|
-}
|
|
|
+exports.util = _
|
|
|
+exports.config = config
|
|
|
+exports.nextTick = _.nextTick
|
|
|
+exports.transition = require('../transition/transition')
|
|
|
|
|
|
/**
|
|
|
- * Plugin system
|
|
|
+ * Class inehritance
|
|
|
+ *
|
|
|
+ * @param {Object} extendOptions
|
|
|
*/
|
|
|
|
|
|
-exports.use = function () {
|
|
|
-
|
|
|
+exports.extend = function (extendOptions) {
|
|
|
+ var Super = this
|
|
|
+ var Sub = function (instanceOptions) {
|
|
|
+ var mergedOptions = _.mergeOptions(Sub.options, instanceOptions)
|
|
|
+ Super.call(this, mergedOptions)
|
|
|
+ }
|
|
|
+ Sub.prototype = Object.create(Super.prototype)
|
|
|
+ _.define(Sub.prototype, 'constructor', Sub)
|
|
|
+ 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)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Expose some internal utilities
|
|
|
+ * Plugin system
|
|
|
+ *
|
|
|
+ * @param {String|Object} plugin
|
|
|
*/
|
|
|
|
|
|
-exports.require = function () {
|
|
|
-
|
|
|
+exports.use = function (plugin) {
|
|
|
+ if (typeof plugin === 'string') {
|
|
|
+ try {
|
|
|
+ plugin = require(plugin)
|
|
|
+ } catch (e) {
|
|
|
+ _.warn('Cannot load plugin: ' + plugin)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // additional parameters
|
|
|
+ var args = [].slice.call(arguments, 1)
|
|
|
+ args.unshift(this)
|
|
|
+ if (typeof plugin.install === 'function') {
|
|
|
+ plugin.install.apply(plugin, args)
|
|
|
+ } else {
|
|
|
+ plugin.apply(null, args)
|
|
|
+ }
|
|
|
+ return this
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Define asset registries and registration
|
|
|
- * methods on a constructor.
|
|
|
+ * Define asset registration methods on a constructor.
|
|
|
+ *
|
|
|
+ * @param {Function} Ctor
|
|
|
*/
|
|
|
|
|
|
-config.assetTypes.forEach(function (type) {
|
|
|
- var registry = '_' + type + 's'
|
|
|
- exports[registry] = {}
|
|
|
-
|
|
|
- /**
|
|
|
- * Asset registration method.
|
|
|
- *
|
|
|
- * @param {String} id
|
|
|
- * @param {*} definition
|
|
|
- */
|
|
|
-
|
|
|
- exports[type] = function (id, definition) {
|
|
|
- this[registry][id] = definition
|
|
|
- }
|
|
|
-})
|
|
|
+createAssetRegisters(exports)
|
|
|
+function createAssetRegisters (Ctor) {
|
|
|
+ config.assetTypes.forEach(function (type) {
|
|
|
|
|
|
-/**
|
|
|
- * This is pretty useful so we expose it as a global method.
|
|
|
- */
|
|
|
+ /**
|
|
|
+ * Asset registration method.
|
|
|
+ *
|
|
|
+ * @param {String} id
|
|
|
+ * @param {*} definition
|
|
|
+ */
|
|
|
|
|
|
-exports.nextTick = _.nextTick
|
|
|
+ Ctor[type] = function (id, definition) {
|
|
|
+ this.options[type + 's'][id] = definition
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|