Skip to content

Instantly share code, notes, and snippets.

@jasonmit
Last active April 27, 2018 19:13
Show Gist options
  • Save jasonmit/9fc5d75efa52252fc95098a407c9aa7f to your computer and use it in GitHub Desktop.
Save jasonmit/9fc5d75efa52252fc95098a407c9aa7f to your computer and use it in GitHub Desktop.
custom element test
import Ember from 'ember';
import '../custom-element';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
count: 0,
actions: {
handleCounterClick() {
this.incrementProperty('count');
}
}
});
/* javascript things */
eval(`
class ClickCounter extends HTMLElement {
constructor() {
super();
let shadow = this.attachShadow({ mode: 'open' });
this.setup(shadow);
}
handleButtonClick() {
let event = new CustomEvent('customEventName', {
bubbles: true,
cancelable: false
});
this.dispatchEvent(event);
}
setup(shadow) {
let btn = document.createElement('button');
btn.addEventListener('click', this.handleButtonClick.bind(this), false, false);
btn.textContent = 'Submit';
shadow.appendChild(btn);
}
}
// Define the new element
customElements.define('click-counter', ClickCounter);
`);
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
{{count}}
<click-counter onclick={{action 'handleCounterClick'}}></click-counter>
<br>
<br>
{
"version": "0.13.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment