diff --git a/index.js b/index.js index eefdcf8..53766df 100644 --- a/index.js +++ b/index.js @@ -33,6 +33,11 @@ export default { type: Object, default: () => ({}), }, + templateComponents: { + type: Object, + default: () => ({}), + }, + scoped: Boolean, }, render() { if (this.template) { @@ -60,39 +65,41 @@ 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, @@ -100,14 +107,18 @@ export default { methodsFromProps, this.templateProps, ]); + const components = this.scoped ? this.templateComponents : { + ...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 || '
', props: allKeys, computed: passthrough.computed, - components: passthrough.components, + components, provide: provide, }; // debugger;