Skip to content

Commit

Permalink
fix: register components with PascalCase
Browse files Browse the repository at this point in the history
so that we can use markups like `<CSelect />`, which would meet the needs of those PascalCase fans
  • Loading branch information
AngusFu committed Dec 7, 2018
1 parent 3399521 commit 58f3870
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/scripts/components.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { pascalCase } from './utils/index'
// NOTE
// `require.context` must be treated as a whole. by
// NO means you should split them up, as is required
Expand All @@ -10,17 +11,17 @@ export default {
const keys = reqs.keys()
for (let i = 0; i < keys.length; i++) {
const module = getModule(reqs(keys[i]))
module.name && Vue.component(module.name, module)

// turn components' names to Pascal Case
// so that we can use markups like `<CSelect />`
// which would meet the needs of those PascalCase fans
// TODO
// we will turn all `name` fields in SFC into pacal case in the future
module.name && Vue.component(pascalCase(module.name), module)
}
}
}

// function importAll (r) {
// return reqs.keys().map(key => {
// return getModule(reqs(key))
// })
// }

function getModule (module) {
return (module.__esModule && module.default) || module
}
9 changes: 9 additions & 0 deletions src/scripts/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import VueTypes from './vue-types'
import zIndexManager from './zIndexManager'
export { VueTypes }

/**
* pretty simple pascalCase function
*
* @param {String} str
*/
export function pascalCase (str) {
return str.replace(/(^|-)([a-z])/g, (_, __, g2) => g2.toUpperCase())
}

/**
* @desc get Vue Constructor inside Vue instances
* @param vm {VueComponent} Vue instance
Expand Down

0 comments on commit 58f3870

Please sign in to comment.