Skip to content

Commit 365b69b

Browse files
authored
Merge pull request #1 from EranGrin/feature-suggestion/add-attribute-before-root-vue-render
Feature suggestion/add attribute before root vue render
2 parents e2b8456 + d7b6a44 commit 365b69b

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ const CustomElement = wrap(Vue, () => import(`MyComponent.vue`))
4646

4747
window.customElements.define('my-element', CustomElement)
4848
```
49+
### Usage with addtional attributes
50+
```js
51+
const vueAttributeBeforeRender = {
52+
i18n:{ locale: 'de' },
53+
foo:{ bar: 'test' },
54+
};
55+
56+
const CustomElement = wrap(Vue, Component, vueAttributeBeforeRender)
57+
```
58+
This will add the attribute to the
59+
```js
60+
new Vue({ // attributes })
61+
```
4962
5063
## Interface Proxying Details
5164

src/index.js

+22-17
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
convertAttributeValue
1010
} from './utils.js'
1111

12-
export default function wrap (Vue, Component) {
12+
export default function wrap (Vue, Component, vueAttributeBeforeRender) {
1313
const isAsync = typeof Component === 'function' && !Component.cid
1414
let isInitialized = false
1515
let hyphenatedPropsList
@@ -83,23 +83,28 @@ export default function wrap (Vue, Component) {
8383
const self = super()
8484
self.attachShadow({ mode: 'open' })
8585

86-
const wrapper = self._wrapper = new Vue({
87-
name: 'shadow-root',
88-
customElement: self,
89-
shadowRoot: self.shadowRoot,
90-
data () {
91-
return {
92-
props: {},
93-
slotChildren: []
86+
const wrapper = self._wrapper = new Vue(
87+
Object.assign(
88+
vueAttributeBeforeRender, {
89+
name: 'shadow-root',
90+
customElement: self,
91+
shadowRoot: self.shadowRoot,
92+
93+
data () {
94+
return {
95+
props: {},
96+
slotChildren: []
97+
}
98+
},
99+
100+
render (h) {
101+
return h(Component, {
102+
ref: 'inner',
103+
props: this.props
104+
}, this.slotChildren)
105+
}
94106
}
95-
},
96-
render (h) {
97-
return h(Component, {
98-
ref: 'inner',
99-
props: this.props
100-
}, this.slotChildren)
101-
}
102-
})
107+
))
103108

104109
// Use MutationObserver to react to future attribute & slot content change
105110
const observer = new MutationObserver(mutations => {

0 commit comments

Comments
 (0)