Skip to content

Commit

Permalink
fix confusing component definition naming
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeart committed Aug 26, 2021
1 parent 1776724 commit 5973149
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions tests/assets/reading-list/ember3.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
})

AddComponent({
name: 'app-header',
name: 'AppHeader',
template: `
<div>
<h1>Ember@3</h1>
Expand All @@ -62,7 +62,7 @@ <h3>Reading List: {{@booksCount}}</h3>
});

AddComponent({
name: 'reading-list',
name: 'ReadingList',
template: `
<ol>
{{#each @books as |book|}}
Expand All @@ -73,12 +73,12 @@ <h3>Reading List: {{@booksCount}}</h3>
});

AddComponent({
name: 'list-item',
name: 'ListItem',
template: `<li>{{@name}}</li>`
});

AddComponent({
name: 'color-button',
name: 'ColorButton',
template: `
<button
class={{@color}}
Expand All @@ -90,7 +90,7 @@ <h3>Reading List: {{@booksCount}}</h3>
});

AddComponent({
name: 'button-grid',
name: 'ButtonGrid',
template: `
{{#each this.buttons as |config|}}
<ColorButton
Expand All @@ -117,7 +117,7 @@ <h3>Reading List: {{@booksCount}}</h3>
})

AddComponent({
name: 'new-book',
name: 'NewBook',
template: `
<div>
<input type="text" {{on 'input' this.onInput}}>
Expand Down Expand Up @@ -151,7 +151,23 @@ <h3>Reading List: {{@booksCount}}</h3>
}
}

RegisterComponent(name, komponent, template.trim());
RegisterComponent(normalizeToClassicComponent(name), komponent, template.trim());
}

// https://github.com/rwjblue/ember-angle-bracket-invocation-polyfill/blob/master/lib/ast-transform.js#L33
function normalizeToClassicComponent(rawName) {
const name = rawName.split('$').pop() || '';
const ALPHA = /[A-Za-z]/;

return name
.replace(/[A-Z]/g, (char, index) => {
if (index === 0 || !ALPHA.test(name[index - 1])) {
return char.toLowerCase();
}

return `-${char.toLowerCase()}`;
})
.replace(/::/g, '/');
}


Expand Down

0 comments on commit 5973149

Please sign in to comment.