Skip to content

Commit

Permalink
Fixed issue with camel case event names.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Cable authored and pcable committed Jan 11, 2019
1 parent 3c2bc03 commit 9974801
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion example/vue-component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ angular
},
methods: {
updateFirstName () {
this.$emit('newFirstName', 'THE')
this.$emit('new-first-name', 'THE')
}
},
render (h) {
Expand Down
4 changes: 4 additions & 0 deletions lib/kebabCase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default function kebabCase (str) {
return str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
}

4 changes: 2 additions & 2 deletions src/__tests__/create-vue-component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ describe('create-vue-component', () => {
$compileProvider.directive('vbutton', createVueComponent => createVueComponent(ButtonComponent))

const scope = $rootScope.$new()
scope.handleHelloEvent = jest.fn()
scope.handleHelloWorldEvent = jest.fn()

const elem = compileHTML(`<vbutton v-on-hello="handleHelloEvent" />`, scope)
const elem = compileHTML(`<vbutton v-on-hello-world="handleHelloWorldEvent" />`, scope)
elem.find('button')[0].click()
scope.$digest()
expect(scope.handleHelloEvent).toHaveBeenCalledWith('Hello, World!')
Expand Down
7 changes: 6 additions & 1 deletion src/components/props/getExpressions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import angular from 'angular'
import extractExpressionName from './extractPropName'
import extractHtmlAttributes from './extractHtmlAttributes'
import kebabCase from '../../../lib/kebabCase';

/**
* Extract a subset of expressions from the element attributes, e.g. property/data, on, or htmlAttribute
Expand Down Expand Up @@ -41,7 +42,11 @@ export function extractExpressions (exprType, attributes) {
}
expressions.forEach(attrExprName => {
if (objectExprKey) {
const exprName = extractExpressionName(attrExprName, objectExprKey)
let exprName = extractExpressionName(attrExprName, objectExprKey)
if(objectExprKey == exprKeys.on) {
//vue events must be lower case and kebab case is the official recommendation
exprName = kebabCase(exprName)
}
exprsMap[exprName] = attributes[attrExprName]
} else {
// Non-prefixed attributes, i.e. a regular HTML attribute
Expand Down

0 comments on commit 9974801

Please sign in to comment.