Skip to content

scoped template and ability to pass available components #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 41 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export default {
type: Object,
default: () => ({}),
},
templateComponents: {
type: Object,
default: () => ({}),
},
scoped: Boolean,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add a default to this? I'm thinking a default of false, then it's backward compatible.

},
render() {
if (this.template) {
Expand Down Expand Up @@ -60,54 +65,60 @@ export default {
computed: {},
methods: {},
};

// build new objects by removing keys if already exists (e.g. created by mixins)
Object.keys(parentData).forEach((e) => {
if (typeof $data[e] === 'undefined') {
passthrough.$data[e] = parentData[e];
}
});
Object.keys(parentProps).forEach((e) => {
if (typeof $props[e] === 'undefined') {
passthrough.$props[e] = parentProps[e];
}
});
Object.keys(parentMethods).forEach((e) => {
if (typeof methods[e] === 'undefined') {
passthrough.methods[e] = parentMethods[e];
}
});
Object.keys(parentComputed).forEach((e) => {
if (typeof computed[e] === 'undefined') {
passthrough.computed[e] = parentComputed[e];
}
});
Object.keys(parentComponents).forEach((e) => {
if (typeof components[e] === 'undefined') {
passthrough.components[e] = parentComponents[e];
}
});

if (!this.scoped) {
// build new objects by removing keys if already exists (e.g. created by mixins)
Object.keys(parentData).forEach((e) => {
if (typeof $data[e] === 'undefined') {
passthrough.$data[e] = parentData[e];
}
});
Object.keys(parentProps).forEach((e) => {
if (typeof $props[e] === 'undefined') {
passthrough.$props[e] = parentProps[e];
}
});
Object.keys(parentMethods).forEach((e) => {
if (typeof methods[e] === 'undefined') {
passthrough.methods[e] = parentMethods[e];
}
});
Object.keys(parentComputed).forEach((e) => {
if (typeof computed[e] === 'undefined') {
passthrough.computed[e] = parentComputed[e];
}
});
Object.keys(parentComponents).forEach((e) => {
if (typeof components[e] === 'undefined') {
passthrough.components[e] = parentComponents[e];
}
});
}

const methodKeys = Object.keys(passthrough.methods || {});
const dataKeys = Object.keys(passthrough.$data || {});
const propKeys = Object.keys(passthrough.$props || {});
const templatePropKeys = Object.keys(this.templateProps);
const allKeys = dataKeys.concat(propKeys).concat(methodKeys).concat(templatePropKeys);
const allKeys = this.scoped ? templatePropKeys : dataKeys.concat(propKeys).concat(methodKeys).concat(templatePropKeys);
const methodsFromProps = buildFromProps(parent, methodKeys);
const finalProps = merge([
passthrough.$data,
passthrough.$props,
methodsFromProps,
this.templateProps,
]);
const components = this.scoped ? this.templateComponents : {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

components is already defined earlier, so my compiler to bugging out on this. Can you tweak this?

...this.templateComponents,
...(passthrough.components || {})
}

const provide = this.$parent.$.provides ? this.$parent.$.provides : {}; // Avoids Vue warning
const provide = (!this.scoped && this.$parent.$.provides) ? this.$parent.$.provides : {}; // Avoids Vue warning

const dynamic = {
template: this.template || '<div></div>',
props: allKeys,
computed: passthrough.computed,
components: passthrough.components,
components,
provide: provide,
};
// debugger;
Expand Down