MCPcopy
hub / github.com/ygs-code/vue / loop

Function loop

vue.js:4908–4956  ·  view source on GitHub ↗
(key)

Source from the content-addressed store, hash-verified

4906 toggleObserving(false);
4907 }
4908 var loop = function (key) {
4909 keys.push(key);
4910 /*
4911 验证支柱 验证 prosp 是否是规范数据 并且为props 添加 value.__ob__ 属性,把prosp添加到观察者中
4912 * 校验 props 参数 就是组建 定义的props 类型数据,校验类型
4913 *
4914 * 判断prop.type的类型是不是Boolean或者String,如果不是他们两类型,调用getPropDefaultValue获取默认值并且把value添加到观察者模式中
4915 */
4916 var value = validateProp(
4917 key, //props 对象的key
4918 propsOptions,
4919 propsData,
4920 vm
4921 );
4922 /* istanbul ignore else 伊斯坦布尔忽略其他 */
4923 {
4924 //大写字母,加完减号又转成小写了 比如把驼峰 aBc 变成了 a-bc
4925 //匹配大写字母并且两面不是空白的 替换成 - 在转换成小写
4926 var hyphenatedKey = hyphenate(key);
4927 // 检查属性是否为保留属性。
4928 //var isReservedAttribute = makeMap('key,ref,slot,slot-scope,is');
4929 if (isReservedAttribute(hyphenatedKey) ||
4930 config.isReservedAttr(hyphenatedKey)) {
4931 //输出警告
4932 warn(
4933 ("\"" + hyphenatedKey + "\" is a reserved attribute and cannot be used as component prop."),
4934 vm
4935 );
4936 }
4937 //通过defineProperty的set方法去通知notify()订阅者subscribers有新的值修改
4938 defineReactive(props, key, value, function () {
4939 if (vm.$parent && !isUpdatingChildComponent) {
4940 warn(
4941 "Avoid mutating a prop directly since the value will be " +
4942 "overwritten whenever the parent component re-renders. " +
4943 "Instead, use a data or computed property based on the prop's " +
4944 "value. Prop being mutated: \"" + key + "\"",
4945 vm
4946 );
4947 }
4948 });
4949 }
4950 // static props are already proxied on the component's prototype
4951 // during Vue.extend(). We only need to proxy props defined at
4952 // instantiation here.
4953 if (!(key in vm)) { //如果vm中没有props属性,则把他添加到vm中,这样组件this.[propsKey] 就可以获取到值了
4954 proxy(vm, "_props", key);
4955 }
4956 };
4957 //循环校验 props 是否 是合格数据 并且添加观察者
4958 for (var key in propsOptions) loop(key);
4959 toggleObserving(true);

Callers 2

initPropsFunction · 0.85
bindObjectPropsFunction · 0.85

Calls 3

validatePropFunction · 0.85
defineReactiveFunction · 0.85
proxyFunction · 0.85

Tested by

no test coverage detected