Skip to content

Instantly share code, notes, and snippets.

@mehulkar
Last active August 31, 2020 16:38
Show Gist options
  • Save mehulkar/dc1005e563c48f438f0fa368717341ca to your computer and use it in GitHub Desktop.
Save mehulkar/dc1005e563c48f438f0fa368717341ca to your computer and use it in GitHub Desktop.
Glimmer Coversion
import Component from '@glimmer/component';
import { action, computed, set } from '@ember/object';
export default class extends Component {
prop1 = 0;
@computed('prop1')
get cp() {
return this.prop1 * 1000;
}
@action
update() {
const newVal = this.prop1 + 1;
console.log(newVal)
set(this, 'prop1', newVal)
}
}
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>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