Skip to content

Instantly share code, notes, and snippets.

@al3xnag
Last active November 26, 2021 08:52
Show Gist options
  • Save al3xnag/92adf56b5a55c4bdc31ab81c8c9e235f to your computer and use it in GitHub Desktop.
Save al3xnag/92adf56b5a55c4bdc31ab81c8c9e235f to your computer and use it in GitHub Desktop.
autotracking, EmberObject
import Controller from '@ember/controller';
import EmberObject, { action, get, set } from '@ember/object';
import { cached } from '@glimmer/tracking';
export default class ApplicationController extends Controller {
obj = EmberObject.extend({ someFlag: false }).create();
// 1. call `setFlag()`
// -> rendered in template as `false` (not updated)
get someFlag() {
return this.obj.someFlag;
}
// 1. call `setFlag()`
// -> rendered in template as `true`
get someFlagEmberGet() {
return get(this.obj, 'someFlag');
}
// 1. call `setFlag()`
// -> rendered in template as `false` (not updated)
@cached
get cachedSomeFlagEmberGet() {
return get(this.obj, 'someFlag');
}
@action
setFlag() {
set(this.obj, 'someFlag', true);
}
}
<p>someFlag: {{this.someFlag}}</p>
<p>someFlagEmberGet: {{this.someFlagEmberGet}}</p>
<p>cachedSomeFlagEmberGet: {{this.cachedSomeFlagEmberGet}}</p>
<button {{on "click" this.setFlag}}>set flag</button>
{{outlet}}
{
"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-cached-decorator-polyfill": "^0.1.4"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment