|
1 | 1 | var _ = require('./index') |
2 | | -var config = require('../config') |
| 2 | + |
| 3 | +/** |
| 4 | + * Check if an element is a component, if yes return its |
| 5 | + * component id. |
| 6 | + * |
| 7 | + * @param {Element} el |
| 8 | + * @param {Object} options |
| 9 | + * @return {String|undefined} |
| 10 | + */ |
| 11 | + |
| 12 | +exports.commonTagRE = /^(div|p|span|img|a|br|ul|ol|li|h1|h2|h3|h4|h5|code|pre)$/ |
| 13 | +exports.checkComponent = function (el, options) { |
| 14 | + var tag = el.tagName.toLowerCase() |
| 15 | + if (tag === 'component') { |
| 16 | + // dynamic syntax |
| 17 | + var exp = el.getAttribute('is') |
| 18 | + el.removeAttribute('is') |
| 19 | + return exp |
| 20 | + } else if ( |
| 21 | + !exports.commonTagRE.test(tag) && |
| 22 | + _.resolveAsset(options, 'components', tag) |
| 23 | + ) { |
| 24 | + return tag |
| 25 | + /* eslint-disable no-cond-assign */ |
| 26 | + } else if (tag = _.attr(el, 'component')) { |
| 27 | + /* eslint-enable no-cond-assign */ |
| 28 | + return tag |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * Set a prop's initial value on a vm and its data object. |
| 34 | + * The vm may have inherit:true so we need to make sure |
| 35 | + * we don't accidentally overwrite parent value. |
| 36 | + * |
| 37 | + * @param {Vue} vm |
| 38 | + * @param {Object} prop |
| 39 | + * @param {*} value |
| 40 | + */ |
| 41 | + |
| 42 | +exports.initProp = function (vm, prop, value) { |
| 43 | + if (exports.assertProp(prop, value)) { |
| 44 | + var key = prop.path |
| 45 | + if (key in vm) { |
| 46 | + _.define(vm, key, value, true) |
| 47 | + } else { |
| 48 | + vm[key] = value |
| 49 | + } |
| 50 | + vm._data[key] = value |
| 51 | + } |
| 52 | +} |
3 | 53 |
|
4 | 54 | /** |
5 | 55 | * Assert whether a prop is valid. |
@@ -67,56 +117,3 @@ function formatType (val) { |
67 | 117 | function formatValue (val) { |
68 | 118 | return Object.prototype.toString.call(val).slice(8, -1) |
69 | 119 | } |
70 | | - |
71 | | -/** |
72 | | - * Check if an element is a component, if yes return its |
73 | | - * component id. |
74 | | - * |
75 | | - * @param {Element} el |
76 | | - * @param {Object} options |
77 | | - * @return {String|undefined} |
78 | | - */ |
79 | | - |
80 | | -exports.commonTagRE = /^(div|p|span|img|a|br|ul|ol|li|h1|h2|h3|h4|h5|code|pre)$/ |
81 | | -exports.checkComponent = function (el, options) { |
82 | | - var tag = el.tagName.toLowerCase() |
83 | | - if (tag === 'component') { |
84 | | - // dynamic syntax |
85 | | - var exp = el.getAttribute('is') |
86 | | - el.removeAttribute('is') |
87 | | - return exp |
88 | | - } else if ( |
89 | | - !exports.commonTagRE.test(tag) && |
90 | | - _.resolveAsset(options, 'components', tag) |
91 | | - ) { |
92 | | - return tag |
93 | | - /* eslint-disable no-cond-assign */ |
94 | | - } else if (tag = _.attr(el, 'component')) { |
95 | | - /* eslint-enable no-cond-assign */ |
96 | | - return tag |
97 | | - } |
98 | | -} |
99 | | - |
100 | | -/** |
101 | | - * Create an "anchor" for performing dom insertion/removals. |
102 | | - * This is used in a number of scenarios: |
103 | | - * - block instance |
104 | | - * - v-html |
105 | | - * - v-if |
106 | | - * - component |
107 | | - * - repeat |
108 | | - * |
109 | | - * @param {String} content |
110 | | - * @param {Boolean} persist - IE trashes empty textNodes on |
111 | | - * cloneNode(true), so in certain |
112 | | - * cases the anchor needs to be |
113 | | - * non-empty to be persisted in |
114 | | - * templates. |
115 | | - * @return {Comment|Text} |
116 | | - */ |
117 | | - |
118 | | -exports.createAnchor = function (content, persist) { |
119 | | - return config.debug |
120 | | - ? document.createComment(content) |
121 | | - : document.createTextNode(persist ? ' ' : '') |
122 | | -} |
0 commit comments