/* @flow */

import { hasSymbol } from 'core/util/env'
import { warn } from '../util/index'
import { defineReactive } from '../observer/index'

export function initProvide (vm: Component) {
  const provide = vm.$options.provide
  if (provide) {
  // 计算proved结果 vm._provided
= typeof provide === 'function' ? provide.call(vm) : provide } } export function initInjections (vm: Component) { const inject: any = vm.$options.inject if (inject) { // inject is :any because flow is not smart enough to figure out cached // isArray here
  // 注入 可以任何类型 是因为fow不过智能, 计算出被缓存的数组
const isArray = Array.isArray(inject)
  //如果是对象, 取出属性值 const keys
= isArray ? inject : hasSymbol ? Reflect.ownKeys(inject) : Object.keys(inject) for (let i = 0; i < keys.length; i++) { const key = keys[i] const provideKey = isArray ? key : inject[key] let source = vm
while (source) { if (source._provided && provideKey in source._provided) { /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') {
       //添加这个vm的inject属性监控 defineReactive(vm, key, source._provided[provideKey], ()
=> { //避免直接监控一个属性, 因为当重新渲染的时候, 这个监控会被改变
        warn( `Avoid mutating an injected value directly since the changes will be `
+ `overwritten whenever the provided component re-renders. ` + `injection being mutated: "${key}"`, vm ) }) } else { defineReactive(vm, key, source._provided[provideKey]) } break } source = source.$parent } } } }

 这个方法应该是给vm的inject属性添加监控.