Skip to content

Instantly share code, notes, and snippets.

@cibernox
Forked from mehulkar/components.foo\.js
Last active August 31, 2020 16:41
Show Gist options
  • Save cibernox/145803bb2d3d81031b17f951fc0bec6b to your computer and use it in GitHub Desktop.
Save cibernox/145803bb2d3d81031b17f951fc0bec6b to your computer and use it in GitHub Desktop.
Glimmer Coversion 3
import Component from '@glimmer/component';
import { tracked} from '@glimmer/tracking';
import { action, set } from '@ember/object';
export default class extends Component {
@tracked prop1 = 0;
get step1() {
return this.prop1 * 10;
}
get step2() {
return this.step1 * 10;
}
get cp() {
return this.step2 * 10;
}
@action
update() {
this.prop1++;
}
}
import Controller from '@ember/controller';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
}
<h1>Welcome to {{this.appName}}</h1>
<p>prop1 is the underlying value, and clicking on the button calls <code>Ember.set</code> to update it. The <code>cp</code> is a computed property that relies on the dependent key <code>prop1</code>. If we remove the dependent key, <code>cp</code> will stop updating when <code>prop1</code> changes.</p>
<p>Currently, the code "works". To see it break, open <code>app/components/foo.js</code> and comment out the <code>@computed</code> decorator.</p>
<Foo />
<button {{on "click" this.update}}>update</button>
<table>
<tr><td>prop1</td><td>{{this.prop1}}</td></tr>
<tr><td>step1</td><td>{{this.step1}}</td></tr>
<tr><td>step2</td><td>{{this.step2}}</td></tr>
<tr><td>cp</td><td>{{this.cp}}</td></tr>
</table>
{
"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"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment