github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/public/libs/vue-1.0.24/src/instance/internal/misc.js (about)

     1  import {
     2    resolveAsset,
     3    isPlainObject,
     4    warn
     5  } from '../../util/index'
     6  
     7  export default function (Vue) {
     8    /**
     9     * Apply a list of filter (descriptors) to a value.
    10     * Using plain for loops here because this will be called in
    11     * the getter of any watcher with filters so it is very
    12     * performance sensitive.
    13     *
    14     * @param {*} value
    15     * @param {*} [oldValue]
    16     * @param {Array} filters
    17     * @param {Boolean} write
    18     * @return {*}
    19     */
    20  
    21    Vue.prototype._applyFilters = function (value, oldValue, filters, write) {
    22      var filter, fn, args, arg, offset, i, l, j, k
    23      for (i = 0, l = filters.length; i < l; i++) {
    24        filter = filters[write ? l - i - 1 : i]
    25        fn = resolveAsset(this.$options, 'filters', filter.name, true)
    26        if (!fn) continue
    27        fn = write ? fn.write : (fn.read || fn)
    28        if (typeof fn !== 'function') continue
    29        args = write ? [value, oldValue] : [value]
    30        offset = write ? 2 : 1
    31        if (filter.args) {
    32          for (j = 0, k = filter.args.length; j < k; j++) {
    33            arg = filter.args[j]
    34            args[j + offset] = arg.dynamic
    35              ? this.$get(arg.value)
    36              : arg.value
    37          }
    38        }
    39        value = fn.apply(this, args)
    40      }
    41      return value
    42    }
    43  
    44    /**
    45     * Resolve a component, depending on whether the component
    46     * is defined normally or using an async factory function.
    47     * Resolves synchronously if already resolved, otherwise
    48     * resolves asynchronously and caches the resolved
    49     * constructor on the factory.
    50     *
    51     * @param {String|Function} value
    52     * @param {Function} cb
    53     */
    54  
    55    Vue.prototype._resolveComponent = function (value, cb) {
    56      var factory
    57      if (typeof value === 'function') {
    58        factory = value
    59      } else {
    60        factory = resolveAsset(this.$options, 'components', value, true)
    61      }
    62      /* istanbul ignore if */
    63      if (!factory) {
    64        return
    65      }
    66      // async component factory
    67      if (!factory.options) {
    68        if (factory.resolved) {
    69          // cached
    70          cb(factory.resolved)
    71        } else if (factory.requested) {
    72          // pool callbacks
    73          factory.pendingCallbacks.push(cb)
    74        } else {
    75          factory.requested = true
    76          var cbs = factory.pendingCallbacks = [cb]
    77          factory.call(this, function resolve (res) {
    78            if (isPlainObject(res)) {
    79              res = Vue.extend(res)
    80            }
    81            // cache resolved
    82            factory.resolved = res
    83            // invoke callbacks
    84            for (var i = 0, l = cbs.length; i < l; i++) {
    85              cbs[i](res)
    86            }
    87          }, function reject (reason) {
    88            process.env.NODE_ENV !== 'production' && warn(
    89              'Failed to resolve async component' +
    90              (typeof value === 'string' ? ': ' + value : '') + '. ' +
    91              (reason ? '\nReason: ' + reason : '')
    92            )
    93          })
    94        }
    95      } else {
    96        // normal component
    97        cb(factory)
    98      }
    99    }
   100  }