Skip to content

Instantly share code, notes, and snippets.

@sukima
Created September 3, 2020 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sukima/6abadf622e2c3fddcdcb9da3979acf45 to your computer and use it in GitHub Desktop.
Save sukima/6abadf622e2c3fddcdcb9da3979acf45 to your computer and use it in GitHub Desktop.
New Twiddle
import Component from '@glimmer/component';
export default class extends Component {
}
import Component from '@glimmer/component';
export default class extends Component {
init() {
super.init(...arguments);
this.children = new Set();
this.args.parent.registerChild(this);
}
willDestroy() {
super.willDestroy(...arguments);
this.args.parent.unregisterChild(this);
}
registerChild(node) {
this.children.add(node);
}
unregisterChild(node) {
this.children.delete(node);
}
didInsertNode(element) {
console.log('Insert', element);
this.children.forEach(c => c.didInsertNode(element));
}
willDestroyNode(element) {
console.log('Destroy', element);
this.children.forEach(c => c.willDestroyNode(element));
}
}
import NodeComponent from './render-test/node';
export default class extends NodeComponent {}
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
<h1>Welcome to {{this.appName}}</h1>
<br>
<br>
<RenderTest as |node|>
</RenderTest>
<br>
<br>
{{yield (component "render-test/node" parent=this)}}
<div ...attributes
{{did-insert (action this.didInsertNode)}}
{{will-destroy (action this.willDestroyNode)}}
>
{{yield (component "render-test/node" parent=this)}}
</div>
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js",
"ember": "3.18.1",
"ember-template-compiler": "3.18.1",
"ember-testing": "3.18.1"
},
"addons": {
"@glimmer/component": "1.0.0",
"@ember/render-modifier": "1.0.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment