How to use the @vue/shared.isFunction function in @vue/shared

To help you get started, we’ve selected a few @vue/shared examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vuejs / vue-next / packages / runtime-core / src / componentOptions.ts View on Github external
export function mergeComponentOptions(to: any, from: any): ComponentOptions {
  const res: any = Object.assign({}, to)
  if (from.mixins) {
    from.mixins.forEach((mixin: any) => {
      from = mergeComponentOptions(from, mixin)
    })
  }
  for (const key in from) {
    const value = from[key]
    const existing = res[key]
    if (isFunction(value) && isFunction(existing)) {
      if (key === 'data') {
        // for data we need to merge the returned value
        res[key] = mergeDataFn(existing, value)
      } else if (/^render|^errorCaptured/.test(key)) {
        // render, renderTracked, renderTriggered & errorCaptured
        // are never merged
        res[key] = value
      } else {
        // merge lifecycle hooks
        res[key] = mergeLifecycleHooks(existing, value)
      }
    } else if (isArray(value) && isArray(existing)) {
      res[key] = existing.concat(value)
    } else if (isObject(value) && isObject(existing)) {
      res[key] = Object.assign({}, existing, value)
    } else {
github vuejs / vue-next / packages / runtime-core / src / vnode.ts View on Github external
// mutated
      if (isReactive(style) && !isArray(style)) {
        style = extend({}, style)
      }
      props.style = normalizeStyle(style)
    }
  }

  // encode the vnode type information into a bitmap
  const shapeFlag = isString(type)
    ? ShapeFlags.ELEMENT
    : __FEATURE_SUSPENSE__ && (type as any).__isSuspense === true
      ? ShapeFlags.SUSPENSE
      : isObject(type)
        ? ShapeFlags.STATEFUL_COMPONENT
        : isFunction(type)
          ? ShapeFlags.FUNCTIONAL_COMPONENT
          : 0

  const vnode: VNode = {
    _isVNode: true,
    type,
    props,
    key: (props !== null && props.key) || null,
    ref: (props !== null && props.ref) || null,
    scopeId: currentScopeId,
    children: null,
    component: null,
    suspense: null,
    dirs: null,
    transition: null,
    el: null,
github vuejs / vue-next / packages / runtime-core / src / componentWatch.ts View on Github external
export function initializeWatch(
  instance: ComponentInstance,
  options: ComponentWatchOptions | undefined
) {
  if (options !== void 0) {
    for (const key in options) {
      const opt = options[key]
      if (isArray(opt)) {
        opt.forEach(o => setupWatcher(instance, key, o))
      } else if (isFunction(opt)) {
        setupWatcher(instance, key, opt)
      } else if (isString(opt)) {
        setupWatcher(instance, key, (instance as any)[opt])
      } else if (opt.handler) {
        setupWatcher(instance, key, opt.handler, opt)
      }
    }
  }
}
github vuejs / vue-next / packages / runtime-core / src / apiOptions.ts View on Github external
`Computed property "${key}" was assigned to but it has no setter.`
                    )
                  }
                : NOOP
          })
        } else if (__DEV__) {
          warn(`Computed property "${key}" has no getter.`)
        }
      }
    }
  }

  if (methods) {
    for (const key in methods) {
      const methodHandler = (methods as MethodOptions)[key]
      if (isFunction(methodHandler)) {
        __DEV__ && checkDuplicateProperties!(OptionTypes.METHODS, key)
        renderContext[key] = methodHandler.bind(ctx)
      } else if (__DEV__) {
        warn(
          `Method "${key}" has type "${typeof methodHandler}" in the component definition. ` +
            `Did you reference the function correctly?`
        )
      }
    }
  }
  if (watchOptions) {
    for (const key in watchOptions) {
      createWatcher(watchOptions[key], renderContext, ctx, key)
    }
  }
  if (provideOptions) {
github vuejs / vue-next / packages / runtime-core / src / componentComputed.ts View on Github external
export function initializeComputed(
  instance: ComponentInstance,
  computedOptions: ComponentComputedOptions | undefined
) {
  if (!computedOptions) {
    return
  }
  const handles: ComputedHandles = (instance._computedGetters = {})
  const proxy = instance.$proxy
  for (const key in computedOptions) {
    const option = computedOptions[key]
    const getter = isFunction(option) ? option : option.get || NOOP
    handles[key] = computed(getter, proxy)
  }
}
github vuejs / vue-next / packages / runtime-core / src / warning.ts View on Github external
function formatComponentName(vnode: ComponentVNode, file?: string): string {
  const Component = vnode.type as Component
  let name = isFunction(Component)
    ? Component.displayName || Component.name
    : Component.name
  if (!name && file) {
    const match = file.match(/([^/\\]+)\.vue$/)
    if (match) {
      name = match[1]
    }
  }
  return name ? classify(name) : 'Anonymous'
}
github vuejs / vue-next / packages / runtime-core / src / apiOptions.ts View on Github external
function createWatcher(
  raw: ComponentWatchOptionItem,
  renderContext: Data,
  ctx: ComponentPublicInstance,
  key: string
) {
  const getter = () => (ctx as Data)[key]
  if (isString(raw)) {
    const handler = renderContext[raw]
    if (isFunction(handler)) {
      watch(getter, handler as WatchCallback)
    } else if (__DEV__) {
      warn(`Invalid watch handler specified by key "${raw}"`, handler)
    }
  } else if (isFunction(raw)) {
    watch(getter, raw.bind(ctx))
  } else if (isObject(raw)) {
    if (isArray(raw)) {
      raw.forEach(r => createWatcher(r, renderContext, ctx, key))
    } else {
      watch(getter, raw.handler.bind(ctx), raw)
    }
  } else if (__DEV__) {
    warn(`Invalid watch option: "${key}"`)
  }
}
github vuejs / vue-next / packages / runtime-core / src / apiOptions.ts View on Github external
function createWatcher(
  raw: ComponentWatchOptionItem,
  renderContext: Data,
  ctx: ComponentPublicInstance,
  key: string
) {
  const getter = () => (ctx as Data)[key]
  if (isString(raw)) {
    const handler = renderContext[raw]
    if (isFunction(handler)) {
      watch(getter, handler as WatchCallback)
    } else if (__DEV__) {
      warn(`Invalid watch handler specified by key "${raw}"`, handler)
    }
  } else if (isFunction(raw)) {
    watch(getter, raw.bind(ctx))
  } else if (isObject(raw)) {
    if (isArray(raw)) {
      raw.forEach(r => createWatcher(r, renderContext, ctx, key))
    } else {
      watch(getter, raw.handler.bind(ctx), raw)
    }
  } else if (__DEV__) {
    warn(`Invalid watch option: "${key}"`)
  }
}
github vuejs / vue-next / packages / runtime-core / src / components / Suspense.ts View on Github external
function normalizeSuspenseChildren(
  vnode: VNode
): {
  content: VNode
  fallback: VNode
} {
  const { shapeFlag, children } = vnode
  if (shapeFlag & ShapeFlags.SLOTS_CHILDREN) {
    const { default: d, fallback } = children as Slots
    return {
      content: normalizeVNode(isFunction(d) ? d() : d),
      fallback: normalizeVNode(isFunction(fallback) ? fallback() : fallback)
    }
  } else {
    return {
      content: normalizeVNode(children as VNodeChild),
      fallback: normalizeVNode(null)
    }
  }
}