MCPcopy Index your code
hub / github.com/keepfool/vue-tutorials / makePropsLinkFn

Function makePropsLinkFn

01.GettingStarted/js/vue.js:6103–6155  ·  view source on GitHub ↗

* Build a function that applies props to a vm. * * @param {Array} props * @return {Function} propsLinkFn

(props)

Source from the content-addressed store, hash-verified

6101 */
6102
6103 function makePropsLinkFn(props) {
6104 return function propsLinkFn(vm, scope) {
6105 // store resolved props info
6106 vm._props = {};
6107 var inlineProps = vm.$options.propsData;
6108 var i = props.length;
6109 var prop, path, options, value, raw;
6110 while (i--) {
6111 prop = props[i];
6112 raw = prop.raw;
6113 path = prop.path;
6114 options = prop.options;
6115 vm._props[path] = prop;
6116 if (inlineProps && hasOwn(inlineProps, path)) {
6117 initProp(vm, prop, inlineProps[path]);
6118 }if (raw === null) {
6119 // initialize absent prop
6120 initProp(vm, prop, undefined);
6121 } else if (prop.dynamic) {
6122 // dynamic prop
6123 if (prop.mode === propBindingModes.ONE_TIME) {
6124 // one time binding
6125 value = (scope || vm._context || vm).$get(prop.parentPath);
6126 initProp(vm, prop, value);
6127 } else {
6128 if (vm._context) {
6129 // dynamic binding
6130 vm._bindDir({
6131 name: 'prop',
6132 def: propDef,
6133 prop: prop
6134 }, null, null, scope); // el, host, scope
6135 } else {
6136 // root instance
6137 initProp(vm, prop, vm.$get(prop.parentPath));
6138 }
6139 }
6140 } else if (prop.optimizedLiteral) {
6141 // optimized literal, cast it and just set once
6142 var stripped = stripQuotes(raw);
6143 value = stripped === raw ? toBoolean(toNumber(raw)) : stripped;
6144 initProp(vm, prop, value);
6145 } else {
6146 // string literal, but we need to cater for
6147 // Boolean props with no value, or with same
6148 // literal value (e.g. disabled="disabled")
6149 // see https://github.com/vuejs/vue-loader/issues/182
6150 value = options.type === Boolean && (raw === '' || raw === hyphenate(prop.name)) ? true : raw;
6151 initProp(vm, prop, value);
6152 }
6153 }
6154 };
6155 }
6156
6157 /**
6158 * Process a prop with a rawValue, applying necessary coersions,

Callers 1

compilePropsFunction · 0.70

Calls 6

hasOwnFunction · 0.70
initPropFunction · 0.70
stripQuotesFunction · 0.70
toBooleanFunction · 0.70
toNumberFunction · 0.70
hyphenateFunction · 0.70

Tested by

no test coverage detected