Skip to content

Commit 6030d29

Browse files
committed
Merge branch 'pulls/33'
2 parents 9f32ad8 + d04bcc7 commit 6030d29

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

demo/components/DemoLazyLoading-docs.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
<p>Instead of component object we will use function with returned Promise. You can use Webpack's <code>require.ensure()</code> or any other async method to load component.</p>
2525

26-
<p>One note - Custom Elements v1 spec require defining observed props during registration. That's why if you omit them, attributes won't be reactive, and changing them from outside (HTML attributes or JavaScript) won't work.</p>
26+
<p>One note - Custom Elements v1 spec require defining observed props during registration. That's why if you omit them, attributes won't be reactive, and changing them from outside (HTML attributes or JavaScript) won't work. This also concerns props added by <code>mixins</code> and <code>extends</code></p>
2727
</el-collapse-item>
2828
<el-collapse-item title="Custom Element HTML" name="2">
2929
<pre><code class="language-html">

src/utils/props.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ export function convertAttributeValue(value) {
2121
return propsValue;
2222
}
2323

24+
function extractProps(collection, props) {
25+
if (collection && collection.length) {
26+
collection.forEach((prop) => {
27+
const camelCaseProp = camelize(prop);
28+
props.camelCase.indexOf(camelCaseProp) === -1 && props.camelCase.push(camelCaseProp);
29+
});
30+
} else if (collection && typeof collection === 'object') {
31+
for (const prop in collection) { // eslint-disable-line no-restricted-syntax, guard-for-in
32+
const camelCaseProp = camelize(prop);
33+
props.camelCase.indexOf(camelCaseProp) === -1 && props.camelCase.push(camelCaseProp);
34+
}
35+
}
36+
}
37+
2438
/**
2539
* Extract props from component definition, no matter if it's array or object
2640
* @param componentDefinition
@@ -32,16 +46,21 @@ export function getProps(componentDefinition = {}) {
3246
hyphenate: []
3347
};
3448

35-
if (componentDefinition.props && componentDefinition.props.length) {
36-
componentDefinition.props.forEach((prop) => {
37-
props.camelCase.push(camelize(prop));
49+
50+
if (componentDefinition.mixins) {
51+
componentDefinition.mixins.forEach((mixin) => {
52+
extractProps(mixin.props, props);
3853
});
39-
} else if (componentDefinition.props && typeof componentDefinition.props === 'object') {
40-
for (const prop in componentDefinition.props) { // eslint-disable-line no-restricted-syntax, guard-for-in
41-
props.camelCase.push(camelize(prop));
42-
}
4354
}
4455

56+
if (componentDefinition.extends && componentDefinition.extends.props) {
57+
const { props: parentProps } = componentDefinition.extends;
58+
59+
extractProps(parentProps, props);
60+
}
61+
62+
extractProps(componentDefinition.props, props);
63+
4564
props.camelCase.forEach((prop) => {
4665
props.hyphenate.push(hyphenate(prop));
4766
});

0 commit comments

Comments
 (0)