Skip to content

Instantly share code, notes, and snippets.

@lifeart
Last active March 14, 2025 12:33
Show Gist options
  • Save lifeart/bae9506b5431123ddc34b78095771f9c to your computer and use it in GitHub Desktop.
Save lifeart/bae9506b5431123ddc34b78095771f9c to your computer and use it in GitHub Desktop.
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { action, notifyPropertyChange, set, computed } from '@ember/object';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
@service state;
@action update() {
set(this.state, 'value', `${this.state.value}:${this.state.value}`);
//this.state.value = `${this.state.value}:${this.state.value}`;
//notifyPropertyChange(this.state, 'value');
notifyPropertyChange(this.state, 'name');
//notifyPropertyChange(this, 'valueGetter');
//notifyPropertyChange(this, 'nameGetter');
notifyPropertyChange(this, 'nameComputed');
}
@computed
get nameComputed() {
return this.state.name;
}
get valueGetter() {
return this.state.value;
}
get nameGetter() {
return this.state.name;
}
}
import Service from '@ember/service';
import { computed } from '@ember/object';
export default Service.extend({
value: '123',
name: computed(function(){
return this.value;
}),
});
<button type="button" {{on "click" this.update}}>
update
</button>
<br>
Direct value access:
{{this.state.value}}<br>
Direct computed access:
{{this.state.name}}<br>
Getter value access:
{{this.valueGetter}}<br>
Getter name access:
{{this.nameGetter}}<br>
Computed name access:
{{this.nameComputed}}<br>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment