Skip to content

Instantly share code, notes, and snippets.

@mehulkar
Created July 22, 2020 02:42
Show Gist options
  • Save mehulkar/c04372eadc4452ba7a48b26e863095ed to your computer and use it in GitHub Desktop.
Save mehulkar/c04372eadc4452ba7a48b26e863095ed to your computer and use it in GitHub Desktop.
notifyPropertyChange
import Controller from '@ember/controller';
import { computed } from '@ember/object';
let counter = 0;
export default Controller.extend({
appName: 'Ember Twiddle',
foo: 1,
bar: computed('foo', function() {
counter++;
return this.get('foo') + counter + 1;
}),
actions: {
notify() {
this.notifyPropertyChange('foo');
}
}
})
<h1>Welcome to {{this.appName}}</h1>
<p>Tests if notifyPropertyChange will retrigger a computed property successfully</p>
{{this.bar}}
<button {{action "notify"}}>recalc</button>
<br>
<br>
{{outlet}}
<br>
<br>
{
"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.8.3",
"ember-template-compiler": "3.8.3",
"ember-testing": "3.8.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment