I am trying to create my first ember component, a wrapper for ChordsJS to display guitar chords.
My component template looks like this:
<chord {{bind-attr name=name positions=positions fingers=fingers size=size }}></chord>
And my component JS is here:
import Ember from 'ember';
export default Ember.Component.extend({
name: 'D',
positions: 'xx0232',
fingers: '---132',
size: '3',
didInsertElement: function() {
chords.replace();
}
});
This renders correctly, but since didInsertElement is in the component.js code, it fires once for each element on the page, so if my markup is
<chord></chord>
<chord></chord>
There will be 4 rendered elements instead of two. Is there another way to include the didInsertElement call so that it only fires once per template?
Edit: another approach would be for me to hack the ChordJS library and make chords.replace() work for a single element: chords.replace(element). To do this, I would need a way to access the dom element in the component.js ?