Skip to content

Commit

Permalink
refactor: move wrapFunctional util to index
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 16, 2021
1 parent c39a593 commit 8203489
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ const componentsModule: Module<Options> = function () {
const templates = [
'components/index.js',
'components/plugin.js',
'components/utils.js',
'components/readme_md',
'vetur/tags.json'
]
Expand Down
33 changes: 31 additions & 2 deletions templates/components/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { wrapFunctional } from './utils'

<%= options.getComponents().map(c => {
const magicComments = [
`webpackChunkName: "${c.chunkName}"`,
Expand All @@ -15,3 +13,34 @@ import { wrapFunctional } from './utils'
return `export { ${exp} } from '../${relativeToBuild(c.filePath)}'`
}
}).join('\n') %>

// nuxt/nuxt.js#8607
function wrapFunctional(options) {
if (!options || !options.functional) {
return options
}

const propKeys = Array.isArray(options.props) ? options.props : Object.keys(options.props || {})

return {
render(h) {
const attrs = {}
const props = {}

for (const key in this.$attrs) {
if (propKeys.includes(key)) {
props[key] = this.$attrs[key]
} else {
attrs[key] = this.$attrs[key]
}
}

return h(options, {
on: this.$listeners,
attrs,
props,
scopedSlots: this.$scopedSlots,
}, this.$slots.default)
}
}
}
30 changes: 0 additions & 30 deletions templates/components/utils.js

This file was deleted.

0 comments on commit 8203489

Please sign in to comment.